blob: 76487b1615758fa2f0da2f6adb4d3fc5e626c982 [file] [log] [blame]
Marshall Clow053d81c2016-07-21 05:31:24 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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
Marshall Clow053d81c2016-07-21 05:31:24 +00006//
7//===----------------------------------------------------------------------===//
8
9
10// <string_view>
11
12// constexpr const _CharT& front();
13
14#include <string_view>
15#include <cassert>
16
17#include "test_macros.h"
18
19template <typename CharT>
20bool test ( const CharT *s, size_t len ) {
Marshall Clow9ea0e472019-03-19 03:30:07 +000021 typedef std::basic_string_view<CharT> SV;
22 SV sv ( s, len );
23 ASSERT_SAME_TYPE(decltype(sv.back()), typename SV::const_reference);
24 LIBCPP_ASSERT_NOEXCEPT( sv.back());
Marshall Clow053d81c2016-07-21 05:31:24 +000025 assert ( sv.length() == len );
26 assert ( sv.back() == s[len-1] );
27 return &sv.back() == s + len - 1;
28 }
29
JF Bastien2df59c52019-02-04 20:31:13 +000030int main(int, char**) {
Marshall Clow053d81c2016-07-21 05:31:24 +000031 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.back() == 'B', "" );
50 }
51#endif
JF Bastien2df59c52019-02-04 20:31:13 +000052
53 return 0;
Marshall Clow053d81c2016-07-21 05:31:24 +000054}