blob: 65eb6b4f65e94a537e38add153e60f81b0ec97a2 [file] [log] [blame]
Marshall Clow053d81c2016-07-21 05:31:24 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10
11// <string_view>
12
13// constexpr const _CharT& operator[](size_type _pos) const;
14
15#include <string_view>
16#include <cassert>
17
18#include "test_macros.h"
19
20template <typename CharT>
21void test ( const CharT *s, size_t len ) {
22 std::basic_string_view<CharT> sv ( s, len );
23 assert ( sv.length() == len );
24 for ( size_t i = 0; i < len; ++i ) {
25 assert ( sv[i] == s[i] );
26 assert ( &sv[i] == s + i );
27 }
28 }
29
30int main () {
31 test ( "ABCDE", 5 );
32 test ( "a", 1 );
33
34 test ( L"ABCDE", 5 );
35 test ( L"a", 1 );
36
37#if TEST_STD_VER >= 11
38 test ( u"ABCDE", 5 );
39 test ( u"a", 1 );
40
41 test ( U"ABCDE", 5 );
42 test ( U"a", 1 );
43#endif
44
Stephan T. Lavavej0f901c72016-11-04 20:26:59 +000045#if TEST_STD_VER > 11
Marshall Clow053d81c2016-07-21 05:31:24 +000046 {
47 constexpr std::basic_string_view<char> sv ( "ABC", 2 );
48 static_assert ( sv.length() == 2, "" );
49 static_assert ( sv[0] == 'A', "" );
50 static_assert ( sv[1] == 'B', "" );
51 }
52#endif
53}