1*053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
2*053d81ceSMarshall Clow //
3*053d81ceSMarshall Clow //                     The LLVM Compiler Infrastructure
4*053d81ceSMarshall Clow //
5*053d81ceSMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open
6*053d81ceSMarshall Clow // Source Licenses. See LICENSE.TXT for details.
7*053d81ceSMarshall Clow //
8*053d81ceSMarshall Clow //===----------------------------------------------------------------------===//
9*053d81ceSMarshall Clow 
10*053d81ceSMarshall Clow // <string>
11*053d81ceSMarshall Clow 
12*053d81ceSMarshall Clow // explicit basic_string(basic_string_view<CharT, traits> sv, const Allocator& a = Allocator());
13*053d81ceSMarshall Clow 
14*053d81ceSMarshall Clow #include <string>
15*053d81ceSMarshall Clow #include <string_view>
16*053d81ceSMarshall Clow #include <stdexcept>
17*053d81ceSMarshall Clow #include <algorithm>
18*053d81ceSMarshall Clow #include <cassert>
19*053d81ceSMarshall Clow 
20*053d81ceSMarshall Clow #include "test_macros.h"
21*053d81ceSMarshall Clow #include "test_allocator.h"
22*053d81ceSMarshall Clow #include "min_allocator.h"
23*053d81ceSMarshall Clow 
24*053d81ceSMarshall Clow template <class charT>
25*053d81ceSMarshall Clow void
26*053d81ceSMarshall Clow test(std::basic_string_view<charT> sv)
27*053d81ceSMarshall Clow {
28*053d81ceSMarshall Clow     typedef std::basic_string<charT, std::char_traits<charT>, test_allocator<charT> > S;
29*053d81ceSMarshall Clow     typedef typename S::traits_type T;
30*053d81ceSMarshall Clow     typedef typename S::allocator_type A;
31*053d81ceSMarshall Clow     S s2(sv);
32*053d81ceSMarshall Clow     LIBCPP_ASSERT(s2.__invariants());
33*053d81ceSMarshall Clow     assert(s2.size() == sv.size());
34*053d81ceSMarshall Clow     assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
35*053d81ceSMarshall Clow     assert(s2.get_allocator() == A());
36*053d81ceSMarshall Clow     assert(s2.capacity() >= s2.size());
37*053d81ceSMarshall Clow }
38*053d81ceSMarshall Clow 
39*053d81ceSMarshall Clow template <class charT, class A>
40*053d81ceSMarshall Clow void
41*053d81ceSMarshall Clow test(std::basic_string_view<charT> sv, const A& a)
42*053d81ceSMarshall Clow {
43*053d81ceSMarshall Clow     typedef std::basic_string<charT, std::char_traits<charT>, A> S;
44*053d81ceSMarshall Clow     typedef typename S::traits_type T;
45*053d81ceSMarshall Clow     S s2(sv, a);
46*053d81ceSMarshall Clow     LIBCPP_ASSERT(s2.__invariants());
47*053d81ceSMarshall Clow     assert(s2.size() == sv.size());
48*053d81ceSMarshall Clow     assert(T::compare(s2.data(), sv.data(), sv.size()) == 0);
49*053d81ceSMarshall Clow     assert(s2.get_allocator() == a);
50*053d81ceSMarshall Clow     assert(s2.capacity() >= s2.size());
51*053d81ceSMarshall Clow }
52*053d81ceSMarshall Clow 
53*053d81ceSMarshall Clow int main()
54*053d81ceSMarshall Clow {
55*053d81ceSMarshall Clow     {
56*053d81ceSMarshall Clow     typedef test_allocator<char> A;
57*053d81ceSMarshall Clow     typedef std::basic_string_view<char, std::char_traits<char> > SV;
58*053d81ceSMarshall Clow 
59*053d81ceSMarshall Clow     test(SV(""));
60*053d81ceSMarshall Clow     test(SV(""), A(2));
61*053d81ceSMarshall Clow 
62*053d81ceSMarshall Clow     test(SV("1"));
63*053d81ceSMarshall Clow     test(SV("1") ,A(2));
64*053d81ceSMarshall Clow 
65*053d81ceSMarshall Clow     test(SV("1234567980"));
66*053d81ceSMarshall Clow     test(SV("1234567980"), A(2));
67*053d81ceSMarshall Clow 
68*053d81ceSMarshall Clow     test(SV("123456798012345679801234567980123456798012345679801234567980"));
69*053d81ceSMarshall Clow     test(SV("123456798012345679801234567980123456798012345679801234567980"), A(2));
70*053d81ceSMarshall Clow     }
71*053d81ceSMarshall Clow #if TEST_STD_VER >= 11
72*053d81ceSMarshall Clow     {
73*053d81ceSMarshall Clow     typedef min_allocator<char> A;
74*053d81ceSMarshall Clow     typedef std::basic_string_view<char, std::char_traits<char> > SV;
75*053d81ceSMarshall Clow 
76*053d81ceSMarshall Clow     test(SV(""));
77*053d81ceSMarshall Clow     test(SV(""), A());
78*053d81ceSMarshall Clow 
79*053d81ceSMarshall Clow     test(SV("1"));
80*053d81ceSMarshall Clow     test(SV("1") ,A());
81*053d81ceSMarshall Clow 
82*053d81ceSMarshall Clow     test(SV("1234567980"));
83*053d81ceSMarshall Clow     test(SV("1234567980"), A());
84*053d81ceSMarshall Clow 
85*053d81ceSMarshall Clow     test(SV("123456798012345679801234567980123456798012345679801234567980"));
86*053d81ceSMarshall Clow     test(SV("123456798012345679801234567980123456798012345679801234567980"), A());
87*053d81ceSMarshall Clow     }
88*053d81ceSMarshall Clow #endif
89*053d81ceSMarshall Clow }
90