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* data() const noexcept;
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 assert ( sv.data() == s );
23*0a6a1f1dSLionel Sambuc }
24*0a6a1f1dSLionel Sambuc
main()25*0a6a1f1dSLionel Sambuc int main () {
26*0a6a1f1dSLionel Sambuc test ( "ABCDE", 5 );
27*0a6a1f1dSLionel Sambuc test ( "a", 1 );
28*0a6a1f1dSLionel Sambuc
29*0a6a1f1dSLionel Sambuc test ( L"ABCDE", 5 );
30*0a6a1f1dSLionel Sambuc test ( L"a", 1 );
31*0a6a1f1dSLionel Sambuc
32*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
33*0a6a1f1dSLionel Sambuc test ( u"ABCDE", 5 );
34*0a6a1f1dSLionel Sambuc test ( u"a", 1 );
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel Sambuc test ( U"ABCDE", 5 );
37*0a6a1f1dSLionel Sambuc test ( U"a", 1 );
38*0a6a1f1dSLionel Sambuc #endif
39*0a6a1f1dSLionel Sambuc
40*0a6a1f1dSLionel Sambuc #if _LIBCPP_STD_VER > 11
41*0a6a1f1dSLionel Sambuc {
42*0a6a1f1dSLionel Sambuc constexpr const char *s = "ABC";
43*0a6a1f1dSLionel Sambuc constexpr std::experimental::basic_string_view<char> sv( s, 2 );
44*0a6a1f1dSLionel Sambuc static_assert( sv.length() == 2, "" );
45*0a6a1f1dSLionel Sambuc static_assert( sv.data() == s, "" );
46*0a6a1f1dSLionel Sambuc }
47*0a6a1f1dSLionel Sambuc #endif
48*0a6a1f1dSLionel Sambuc }
49