blob: 87598dffe735cc381f196b06c7f0f63891515acb [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& operator[](size_type _pos) const;
13
14#include <string_view>
15#include <cassert>
16
17#include "test_macros.h"
18
19template <typename CharT>
20void test ( const CharT *s, size_t len ) {
21 std::basic_string_view<CharT> sv ( s, len );
22 assert ( sv.length() == len );
23 for ( size_t i = 0; i < len; ++i ) {
24 assert ( sv[i] == s[i] );
25 assert ( &sv[i] == s + i );
26 }
27 }
28
29int main () {
30 test ( "ABCDE", 5 );
31 test ( "a", 1 );
32
33 test ( L"ABCDE", 5 );
34 test ( L"a", 1 );
35
36#if TEST_STD_VER >= 11
37 test ( u"ABCDE", 5 );
38 test ( u"a", 1 );
39
40 test ( U"ABCDE", 5 );
41 test ( U"a", 1 );
42#endif
43
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000044#if TEST_STD_VER > 11
Marshall Clow053d81c2016-07-21 05:31:24 +000045 {
46 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
47 static_assert ( sv.length() == 2, "" );
48 static_assert ( sv[0] == 'A', "" );
49 static_assert ( sv[1] == 'B', "" );
50 }
51#endif
52}