1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <string> 10 // UNSUPPORTED: c++03, c++11, c++14 11 12 // template<class InputIterator> 13 // basic_string(InputIterator begin, InputIterator end, 14 // const Allocator& a = Allocator()); 15 16 // template<class InputIterator, 17 // class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 18 // basic_string(InputIterator, InputIterator, Allocator = Allocator()) 19 // -> basic_string<typename iterator_traits<InputIterator>::value_type, 20 // char_traits<typename iterator_traits<InputIterator>::value_type>, 21 // Allocator>; 22 // 23 // The deduction guide shall not participate in overload resolution if InputIterator 24 // is a type that does not qualify as an input iterator, or if Allocator is a type 25 // that does not qualify as an allocator. 26 27 #include <string> 28 #include <iterator> 29 #include <cassert> 30 #include <cstddef> 31 32 #include "test_macros.h" 33 #include "test_allocator.h" 34 #include "min_allocator.h" 35 36 bool test() { 37 { 38 const char* s = "12345678901234"; 39 std::basic_string s1(s, s+10); // Can't use {} here 40 using S = decltype(s1); // what type did we get? 41 static_assert(std::is_same_v<S::value_type, char>, ""); 42 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 43 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 44 assert(s1.size() == 10); 45 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 46 } 47 { 48 const char* s = "12345678901234"; 49 std::basic_string s1{s, s+10, std::allocator<char>{}}; 50 using S = decltype(s1); // what type did we get? 51 static_assert(std::is_same_v<S::value_type, char>, ""); 52 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 53 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 54 assert(s1.size() == 10); 55 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 56 } 57 { 58 const wchar_t* s = L"12345678901234"; 59 std::basic_string s1{s, s+10, test_allocator<wchar_t>{}}; 60 using S = decltype(s1); // what type did we get? 61 static_assert(std::is_same_v<S::value_type, wchar_t>, ""); 62 static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); 63 static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); 64 assert(s1.size() == 10); 65 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 66 } 67 { 68 const char16_t* s = u"12345678901234"; 69 std::basic_string s1{s, s+10, min_allocator<char16_t>{}}; 70 using S = decltype(s1); // what type did we get? 71 static_assert(std::is_same_v<S::value_type, char16_t>, ""); 72 static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); 73 static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); 74 assert(s1.size() == 10); 75 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 76 } 77 { 78 const char32_t* s = U"12345678901234"; 79 std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}}; 80 using S = decltype(s1); // what type did we get? 81 static_assert(std::is_same_v<S::value_type, char32_t>, ""); 82 static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); 83 static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); 84 assert(s1.size() == 10); 85 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 86 } 87 88 return true; 89 } 90 91 int main(int, char**) 92 { 93 94 return 0; 95 } 96