blob: 6e73202d676323ce4528a8e032b9bf0cc9adcdb9 [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& back();
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 ) {
21 std::basic_string_view<CharT> sv ( s, len );
22 assert ( sv.length() == len );
23 assert ( sv.front() == s[0] );
24 return &sv.front() == s;
25 }
26
27int main () {
28 assert ( test ( "ABCDE", 5 ));
29 assert ( test ( "a", 1 ));
30
31 assert ( test ( L"ABCDE", 5 ));
32 assert ( test ( L"a", 1 ));
33
34#if TEST_STD_VER >= 11
35 assert ( test ( u"ABCDE", 5 ));
36 assert ( test ( u"a", 1 ));
37
38 assert ( test ( U"ABCDE", 5 ));
39 assert ( test ( U"a", 1 ));
40#endif
41
42#if TEST_STD_VER >= 11
43 {
44 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
45 static_assert ( sv.length() == 2, "" );
46 static_assert ( sv.front() == 'A', "" );
47 }
48#endif
49}