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>
test(const CharT * s,size_t len)20 bool test ( const CharT *s, size_t len ) {
21     typedef std::basic_string_view<CharT> SV;
22     SV sv ( s, len );
23     ASSERT_SAME_TYPE(decltype(sv.front()), typename SV::const_reference);
24     LIBCPP_ASSERT_NOEXCEPT(   sv.front());
25     assert ( sv.length() == len );
26     assert ( sv.front() == s[0] );
27     return &sv.front() == s;
28     }
29 
main(int,char **)30 int main(int, char**) {
31     assert ( test ( "ABCDE", 5 ));
32     assert ( test ( "a", 1 ));
33 
34     assert ( test ( L"ABCDE", 5 ));
35     assert ( test ( L"a", 1 ));
36 
37 #if TEST_STD_VER >= 11
38     assert ( test ( u"ABCDE", 5 ));
39     assert ( test ( u"a", 1 ));
40 
41     assert ( test ( U"ABCDE", 5 ));
42     assert ( test ( U"a", 1 ));
43 #endif
44 
45 #if TEST_STD_VER >= 11
46     {
47     constexpr std::basic_string_view<char> sv ( "ABC", 2 );
48     static_assert ( sv.length() ==  2,  "" );
49     static_assert ( sv.front()  == 'A', "" );
50     }
51 #endif
52 
53   return 0;
54 }
55