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 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10
11 // <string_view>
12
13 // constexpr const _CharT& front();
14
15 #include <string_view>
16 #include <cassert>
17
18 #include "test_macros.h"
19
20 template <typename CharT>
test(const CharT * s,size_t len)21 bool test ( const CharT *s, size_t len ) {
22 typedef std::basic_string_view<CharT> SV;
23 SV sv ( s, len );
24 ASSERT_SAME_TYPE(decltype(sv.back()), typename SV::const_reference);
25 LIBCPP_ASSERT_NOEXCEPT( sv.back());
26 assert ( sv.length() == len );
27 assert ( sv.back() == s[len-1] );
28 return &sv.back() == s + len - 1;
29 }
30
main(int,char **)31 int main(int, char**) {
32 assert ( test ( "ABCDE", 5 ));
33 assert ( test ( "a", 1 ));
34
35 assert ( test ( L"ABCDE", 5 ));
36 assert ( test ( L"a", 1 ));
37
38 #if TEST_STD_VER >= 11
39 assert ( test ( u"ABCDE", 5 ));
40 assert ( test ( u"a", 1 ));
41
42 assert ( test ( U"ABCDE", 5 ));
43 assert ( test ( U"a", 1 ));
44 #endif
45
46 #if TEST_STD_VER >= 11
47 {
48 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
49 static_assert ( sv.length() == 2, "" );
50 static_assert ( sv.back() == 'B', "" );
51 }
52 #endif
53
54 return 0;
55 }
56