]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/experimental/string.view/string.view.access/index.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / experimental / string.view / string.view.access / index.pass.cpp
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 #include "test_macros.h"
19
20 template <typename CharT>
21 void test ( const CharT *s, size_t len ) {
22     std::experimental::basic_string_view<CharT> sv ( s, len );
23     assert ( sv.length() == len );
24     for ( size_t i = 0; i < len; ++i ) {
25         assert ( sv[i] == s[i] );
26         assert ( &sv[i] == s + i );
27         }
28     }
29
30 int main () {
31     test ( "ABCDE", 5 );
32     test ( "a", 1 );
33
34     test ( L"ABCDE", 5 );
35     test ( L"a", 1 );
36
37 #if TEST_STD_VER >= 11
38     test ( u"ABCDE", 5 );
39     test ( u"a", 1 );
40
41     test ( U"ABCDE", 5 );
42     test ( U"a", 1 );
43 #endif
44
45 #if TEST_STD_VER > 11
46     {
47     constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
48     static_assert ( sv.length() ==  2,  "" );
49     static_assert ( sv[0]  == 'A', "" );
50     static_assert ( sv[1]  == 'B', "" );
51     }
52 #endif
53 }