Home | History | Annotate | Download | only in string.view.access
      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 const _CharT* data() const noexcept;
     14 
     15 #include <experimental/string_view>
     16 #include <cassert>
     17 
     18 template <typename CharT>
     19 void test ( const CharT *s, size_t len ) {
     20     std::experimental::basic_string_view<CharT> sv ( s, len );
     21     assert ( sv.length() == len );
     22     assert ( sv.data() == s );
     23     }
     24 
     25 int main () {
     26     test ( "ABCDE", 5 );
     27     test ( "a", 1 );
     28 
     29     test ( L"ABCDE", 5 );
     30     test ( L"a", 1 );
     31 
     32 #if __cplusplus >= 201103L
     33     test ( u"ABCDE", 5 );
     34     test ( u"a", 1 );
     35 
     36     test ( U"ABCDE", 5 );
     37     test ( U"a", 1 );
     38 #endif
     39 
     40 #if _LIBCPP_STD_VER > 11
     41     {
     42     constexpr const char *s = "ABC";
     43     constexpr std::experimental::basic_string_view<char> sv( s, 2 );
     44     static_assert( sv.length() ==  2,  "" );
     45     static_assert( sv.data() == s, "" );
     46     }
     47 #endif
     48 }
     49