blob: 90c4ac877c89b14761eeae6e0dd18f547fe02bad [file] [log] [blame]
Marshall Clow5aa8fa22014-06-11 16:44:55 +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& at(size_type _pos) const;
14
15#include <experimental/string_view>
16#include <cassert>
17
18template <typename CharT>
19void test ( const CharT *s, size_t len ) {
20 std::experimental::basic_string_view<CharT> sv ( s, len );
21 assert ( sv.length() == len );
22 for ( size_t i = 0; i < len; ++i ) {
23 assert ( sv.at(i) == s[i] );
24 assert ( &sv.at(i) == s + i );
25 }
26
27 try { sv.at(len); } catch ( const std::out_of_range & ) { return ; }
28 assert ( false );
29 }
30
31int main () {
32 test ( "ABCDE", 5 );
33 test ( "a", 1 );
34
35 test ( L"ABCDE", 5 );
36 test ( L"a", 1 );
37
38#if __cplusplus >= 201103L
39 test ( u"ABCDE", 5 );
40 test ( u"a", 1 );
41
42 test ( U"ABCDE", 5 );
43 test ( U"a", 1 );
44#endif
45
Marshall Clow926731b2014-07-08 22:38:11 +000046#if __cplusplus >= 201103L
Marshall Clow5aa8fa22014-06-11 16:44:55 +000047 {
48 constexpr std::experimental::basic_string_view<char> sv ( "ABC", 2 );
49 static_assert ( sv.length() == 2, "" );
50 static_assert ( sv.at(0) == 'A', "" );
51 static_assert ( sv.at(1) == 'B', "" );
52 }
53#endif
54}