Home | History | Annotate | Download | only in string.view.cons
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 
     11 // <string_view>
     12 
     13 //  constexpr basic_string_view(const _CharT* _s, size_type _len)
     14 //      : __data (_s), __size(_len) {}
     15 
     16 
     17 #include <experimental/string_view>
     18 #include <string>
     19 #include <cassert>
     20 
     21 template<typename CharT>
     22 void test ( const CharT *s, size_t sz ) {
     23     {
     24     std::experimental::basic_string_view<CharT> sv1 ( s, sz );
     25     assert ( sv1.size() == sz );
     26     assert ( sv1.data() == s );
     27     }
     28 }
     29 
     30 int main () {
     31 
     32     test ( "QBCDE", 5 );
     33     test ( "QBCDE", 2 );
     34     test ( "", 0 );
     35 #if _LIBCPP_STD_VER > 11
     36     {
     37     constexpr const char *s = "QBCDE";
     38     constexpr std::experimental::basic_string_view<char> sv1 ( s, 2 );
     39     static_assert ( sv1.size() == 2, "" );
     40     static_assert ( sv1.data() == s, "" );
     41     }
     42 #endif
     43 
     44     test ( L"QBCDE", 5 );
     45     test ( L"QBCDE", 2 );
     46     test ( L"", 0 );
     47 #if _LIBCPP_STD_VER > 11
     48     {
     49     constexpr const wchar_t *s = L"QBCDE";
     50     constexpr std::experimental::basic_string_view<wchar_t> sv1 ( s, 2 );
     51     static_assert ( sv1.size() == 2, "" );
     52     static_assert ( sv1.data() == s, "" );
     53     }
     54 #endif
     55 
     56 #if __cplusplus >= 201103L
     57     test ( u"QBCDE", 5 );
     58     test ( u"QBCDE", 2 );
     59     test ( u"", 0 );
     60 #if _LIBCPP_STD_VER > 11
     61     {
     62     constexpr const char16_t *s = u"QBCDE";
     63     constexpr std::experimental::basic_string_view<char16_t> sv1 ( s, 2 );
     64     static_assert ( sv1.size() == 2, "" );
     65     static_assert ( sv1.data() == s, "" );
     66     }
     67 #endif
     68 
     69     test ( U"QBCDE", 5 );
     70     test ( U"QBCDE", 2 );
     71     test ( U"", 0 );
     72 #if _LIBCPP_STD_VER > 11
     73     {
     74     constexpr const char32_t *s = U"QBCDE";
     75     constexpr std::experimental::basic_string_view<char32_t> sv1 ( s, 2 );
     76     static_assert ( sv1.size() == 2, "" );
     77     static_assert ( sv1.data() == s, "" );
     78     }
     79 #endif
     80 #endif
     81 }
     82