• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
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 // <string>
11 // UNSUPPORTED: c++98, c++03, c++11, c++14
12 // XFAIL: libcpp-no-deduction-guides
13 
14 // template<class InputIterator>
15 //   basic_string(InputIterator begin, InputIterator end,
16 //   const Allocator& a = Allocator());
17 
18 // template<class charT,
19 //          class traits,
20 //          class Allocator = allocator<charT>
21 //          >
22 // basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
23 //   -> basic_string<charT, traits, Allocator>;
24 //
25 //  The deduction guide shall not participate in overload resolution if Allocator
26 //  is a type that does not qualify as an allocator.
27 
28 
29 #include <string>
30 #include <string_view>
31 #include <iterator>
32 #include <memory>
33 #include <type_traits>
34 #include <cassert>
35 #include <cstddef>
36 
37 #include "test_macros.h"
38 #include "test_allocator.h"
39 #include "../input_iterator.h"
40 #include "min_allocator.h"
41 
main()42 int main()
43 {
44     {
45     std::string_view sv = "12345678901234";
46     std::basic_string s1(sv);
47     using S = decltype(s1); // what type did we get?
48     static_assert(std::is_same_v<S::value_type,                      char>,  "");
49     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char>>, "");
50     static_assert(std::is_same_v<S::allocator_type,   std::allocator<char>>, "");
51     assert(s1.size() == sv.size());
52     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
53     }
54 
55     {
56     std::string_view sv = "12345678901234";
57     std::basic_string s1{sv, std::allocator<char>{}};
58     using S = decltype(s1); // what type did we get?
59     static_assert(std::is_same_v<S::value_type,                      char>,  "");
60     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char>>, "");
61     static_assert(std::is_same_v<S::allocator_type,   std::allocator<char>>, "");
62     assert(s1.size() == sv.size());
63     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
64     }
65     {
66     std::wstring_view sv = L"12345678901234";
67     std::basic_string s1{sv, test_allocator<wchar_t>{}};
68     using S = decltype(s1); // what type did we get?
69     static_assert(std::is_same_v<S::value_type,                      wchar_t>,  "");
70     static_assert(std::is_same_v<S::traits_type,    std::char_traits<wchar_t>>, "");
71     static_assert(std::is_same_v<S::allocator_type,   test_allocator<wchar_t>>, "");
72     assert(s1.size() == sv.size());
73     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
74     }
75 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
76     {
77     std::u8string_view sv = u8"12345678901234";
78     std::basic_string s1{sv, min_allocator<char8_t>{}};
79     using S = decltype(s1); // what type did we get?
80     static_assert(std::is_same_v<S::value_type,                      char8_t>,  "");
81     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char8_t>>, "");
82     static_assert(std::is_same_v<S::allocator_type,    min_allocator<char8_t>>, "");
83     assert(s1.size() == sv.size());
84     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
85     }
86 #endif
87     {
88     std::u16string_view sv = u"12345678901234";
89     std::basic_string s1{sv, min_allocator<char16_t>{}};
90     using S = decltype(s1); // what type did we get?
91     static_assert(std::is_same_v<S::value_type,                      char16_t>,  "");
92     static_assert(std::is_same_v<S::traits_type,    std::char_traits<char16_t>>, "");
93     static_assert(std::is_same_v<S::allocator_type,    min_allocator<char16_t>>, "");
94     assert(s1.size() == sv.size());
95     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
96     }
97     {
98     std::u32string_view sv = U"12345678901234";
99     std::basic_string s1{sv, explicit_allocator<char32_t>{}};
100     using S = decltype(s1); // what type did we get?
101     static_assert(std::is_same_v<S::value_type,                        char32_t>,  "");
102     static_assert(std::is_same_v<S::traits_type,      std::char_traits<char32_t>>, "");
103     static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, "");
104     assert(s1.size() == sv.size());
105     assert(s1.compare(0, s1.size(), sv.data(), s1.size()) == 0);
106     }
107 }
108