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