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)
     14 //    : __data (_s), __size(_Traits::length(_s)) {}
     15 
     16 
     17 #include <experimental/string_view>
     18 #include <string>
     19 #include <cassert>
     20 
     21 #include "constexpr_char_traits.hpp"
     22 
     23 template<typename CharT>
     24 size_t StrLen ( const CharT *s ) {
     25     size_t retVal = 0;
     26     while ( *s != 0 ) { ++retVal; ++s; }
     27     return retVal;
     28     }
     29 
     30 template<typename CharT>
     31 void test ( const CharT *s ) {
     32     std::experimental::basic_string_view<CharT> sv1 ( s );
     33     assert ( sv1.size() == StrLen( s ));
     34     assert ( sv1.data() == s );
     35     }
     36 
     37 
     38 int main () {
     39 
     40     test ( "QBCDE" );
     41     test ( "A" );
     42     test ( "" );
     43 
     44     test ( L"QBCDE" );
     45     test ( L"A" );
     46     test ( L"" );
     47 
     48 #if __cplusplus >= 201103L
     49     test ( u"QBCDE" );
     50     test ( u"A" );
     51     test ( u"" );
     52 
     53     test ( U"QBCDE" );
     54     test ( U"A" );
     55     test ( U"" );
     56 #endif
     57 
     58 #if _LIBCPP_STD_VER > 11
     59     {
     60     constexpr std::experimental::basic_string_view<char, constexpr_char_traits<char>> sv1 ( "ABCDE" );
     61     static_assert ( sv1.size() == 5, "");
     62     }
     63 #endif
     64 }
     65