1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 
10 // <string_view>
11 
12 // constexpr const _CharT& back();
13 
14 #include <string_view>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 template <typename CharT>
20 bool test ( const CharT *s, size_t len ) {
21     std::basic_string_view<CharT> sv ( s, len );
22     assert ( sv.length() == len );
23     assert ( sv.front() == s[0] );
24     return &sv.front() == s;
25     }
26 
27 int main(int, char**) {
28     assert ( test ( "ABCDE", 5 ));
29     assert ( test ( "a", 1 ));
30 
31     assert ( test ( L"ABCDE", 5 ));
32     assert ( test ( L"a", 1 ));
33 
34 #if TEST_STD_VER >= 11
35     assert ( test ( u"ABCDE", 5 ));
36     assert ( test ( u"a", 1 ));
37 
38     assert ( test ( U"ABCDE", 5 ));
39     assert ( test ( U"a", 1 ));
40 #endif
41 
42 #if TEST_STD_VER >= 11
43     {
44     constexpr std::basic_string_view<char> sv ( "ABC", 2 );
45     static_assert ( sv.length() ==  2,  "" );
46     static_assert ( sv.front()  == 'A', "" );
47     }
48 #endif
49 
50   return 0;
51 }
52