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 // void clear() 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 typedef std::experimental::basic_string_view<CharT> SV;
21*0a6a1f1dSLionel Sambuc {
22*0a6a1f1dSLionel Sambuc SV sv1 ( s );
23*0a6a1f1dSLionel Sambuc assert ( sv1.size() == len );
24*0a6a1f1dSLionel Sambuc assert ( sv1.data() == s );
25*0a6a1f1dSLionel Sambuc
26*0a6a1f1dSLionel Sambuc sv1.clear ();
27*0a6a1f1dSLionel Sambuc assert ( sv1.data() == nullptr );
28*0a6a1f1dSLionel Sambuc assert ( sv1.size() == 0 );
29*0a6a1f1dSLionel Sambuc assert ( sv1 == SV());
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc }
32*0a6a1f1dSLionel Sambuc
33*0a6a1f1dSLionel Sambuc #if _LIBCPP_STD_VER > 11
test_ce(size_t n)34*0a6a1f1dSLionel Sambuc constexpr size_t test_ce ( size_t n ) {
35*0a6a1f1dSLionel Sambuc typedef std::experimental::basic_string_view<char> SV;
36*0a6a1f1dSLionel Sambuc SV sv1{ "ABCDEFGHIJKL", n };
37*0a6a1f1dSLionel Sambuc sv1.clear();
38*0a6a1f1dSLionel Sambuc return sv1.size();
39*0a6a1f1dSLionel Sambuc }
40*0a6a1f1dSLionel Sambuc #endif
41*0a6a1f1dSLionel Sambuc
main()42*0a6a1f1dSLionel Sambuc int main () {
43*0a6a1f1dSLionel Sambuc test ( "ABCDE", 5 );
44*0a6a1f1dSLionel Sambuc test ( "a", 1 );
45*0a6a1f1dSLionel Sambuc test ( "", 0 );
46*0a6a1f1dSLionel Sambuc
47*0a6a1f1dSLionel Sambuc test ( L"ABCDE", 5 );
48*0a6a1f1dSLionel Sambuc test ( L"a", 1 );
49*0a6a1f1dSLionel Sambuc test ( L"", 0 );
50*0a6a1f1dSLionel Sambuc
51*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
52*0a6a1f1dSLionel Sambuc test ( u"ABCDE", 5 );
53*0a6a1f1dSLionel Sambuc test ( u"a", 1 );
54*0a6a1f1dSLionel Sambuc test ( u"", 0 );
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc test ( U"ABCDE", 5 );
57*0a6a1f1dSLionel Sambuc test ( U"a", 1 );
58*0a6a1f1dSLionel Sambuc test ( U"", 0 );
59*0a6a1f1dSLionel Sambuc #endif
60*0a6a1f1dSLionel Sambuc
61*0a6a1f1dSLionel Sambuc #if _LIBCPP_STD_VER > 11
62*0a6a1f1dSLionel Sambuc static_assert ( test_ce (5) == 0, "" );
63*0a6a1f1dSLionel Sambuc #endif
64*0a6a1f1dSLionel Sambuc
65*0a6a1f1dSLionel Sambuc }
66