1053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2053d81ceSMarshall Clow //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6053d81ceSMarshall Clow //
7053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
8053d81ceSMarshall Clow 
9*4fc50236SJoe Loser // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
10*4fc50236SJoe Loser 
11053d81ceSMarshall Clow // <string_view>
12053d81ceSMarshall Clow 
13053d81ceSMarshall Clow // constexpr const _CharT& front();
14053d81ceSMarshall Clow 
15053d81ceSMarshall Clow #include <string_view>
16053d81ceSMarshall Clow #include <cassert>
17053d81ceSMarshall Clow 
18053d81ceSMarshall Clow #include "test_macros.h"
19053d81ceSMarshall Clow 
20053d81ceSMarshall Clow template <typename CharT>
test(const CharT * s,size_t len)21053d81ceSMarshall Clow bool test ( const CharT *s, size_t len ) {
229ea0e473SMarshall Clow     typedef std::basic_string_view<CharT> SV;
239ea0e473SMarshall Clow     SV sv ( s, len );
249ea0e473SMarshall Clow     ASSERT_SAME_TYPE(decltype(sv.back()), typename SV::const_reference);
259ea0e473SMarshall Clow     LIBCPP_ASSERT_NOEXCEPT(   sv.back());
26053d81ceSMarshall Clow     assert ( sv.length() == len );
27053d81ceSMarshall Clow     assert ( sv.back() == s[len-1] );
28053d81ceSMarshall Clow     return &sv.back() == s + len - 1;
29053d81ceSMarshall Clow     }
30053d81ceSMarshall Clow 
main(int,char **)312df59c50SJF Bastien int main(int, char**) {
32053d81ceSMarshall Clow     assert ( test ( "ABCDE", 5 ));
33053d81ceSMarshall Clow     assert ( test ( "a", 1 ));
34053d81ceSMarshall Clow 
35053d81ceSMarshall Clow     assert ( test ( L"ABCDE", 5 ));
36053d81ceSMarshall Clow     assert ( test ( L"a", 1 ));
37053d81ceSMarshall Clow 
38053d81ceSMarshall Clow #if TEST_STD_VER >= 11
39053d81ceSMarshall Clow     assert ( test ( u"ABCDE", 5 ));
40053d81ceSMarshall Clow     assert ( test ( u"a", 1 ));
41053d81ceSMarshall Clow 
42053d81ceSMarshall Clow     assert ( test ( U"ABCDE", 5 ));
43053d81ceSMarshall Clow     assert ( test ( U"a", 1 ));
44053d81ceSMarshall Clow #endif
45053d81ceSMarshall Clow 
46053d81ceSMarshall Clow #if TEST_STD_VER >= 11
47053d81ceSMarshall Clow     {
48053d81ceSMarshall Clow     constexpr std::basic_string_view<char> sv ( "ABC", 2 );
49053d81ceSMarshall Clow     static_assert ( sv.length() ==  2,  "" );
50053d81ceSMarshall Clow     static_assert ( sv.back()  == 'B', "" );
51053d81ceSMarshall Clow     }
52053d81ceSMarshall Clow #endif
532df59c50SJF Bastien 
542df59c50SJF Bastien   return 0;
55053d81ceSMarshall Clow }
56