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