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& operator[](size_type _pos) const; 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 for ( size_t i = 0; i < len; ++i ) { 23 assert ( sv[i] == s[i] ); 24 assert ( &sv[i] == s + i ); 25 } 26 } 27 28 int main () { 29 test ( "ABCDE", 5 ); 30 test ( "a", 1 ); 31 32 test ( L"ABCDE", 5 ); 33 test ( L"a", 1 ); 34 35 #if __cplusplus >= 201103L 36 test ( u"ABCDE", 5 ); 37 test ( u"a", 1 ); 38 39 test ( U"ABCDE", 5 ); 40 test ( U"a", 1 ); 41 #endif 42 43 #if _LIBCPP_STD_VER > 11 44 { 45 constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 ); 46 static_assert ( sv.length() == 2, "" ); 47 static_assert ( sv[0] == 'A', "" ); 48 static_assert ( sv[1] == 'B', "" ); 49 } 50 #endif 51 } 52