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 "../cpp17_input_iterator.h" 35 #include "min_allocator.h" 36 37 bool test() { 38 { 39 const char* s = "12345678901234"; 40 std::basic_string s1(s, s+10); // Can't use {} here 41 using S = decltype(s1); // what type did we get? 42 static_assert(std::is_same_v<S::value_type, char>, ""); 43 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 44 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 45 assert(s1.size() == 10); 46 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 47 } 48 { 49 const char* s = "12345678901234"; 50 std::basic_string s1{s, s+10, std::allocator<char>{}}; 51 using S = decltype(s1); // what type did we get? 52 static_assert(std::is_same_v<S::value_type, char>, ""); 53 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 54 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 55 assert(s1.size() == 10); 56 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 57 } 58 { 59 const wchar_t* s = L"12345678901234"; 60 std::basic_string s1{s, s+10, test_allocator<wchar_t>{}}; 61 using S = decltype(s1); // what type did we get? 62 static_assert(std::is_same_v<S::value_type, wchar_t>, ""); 63 static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); 64 static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); 65 assert(s1.size() == 10); 66 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 67 } 68 { 69 const char16_t* s = u"12345678901234"; 70 std::basic_string s1{s, s+10, min_allocator<char16_t>{}}; 71 using S = decltype(s1); // what type did we get? 72 static_assert(std::is_same_v<S::value_type, char16_t>, ""); 73 static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); 74 static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); 75 assert(s1.size() == 10); 76 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 77 } 78 { 79 const char32_t* s = U"12345678901234"; 80 std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}}; 81 using S = decltype(s1); // what type did we get? 82 static_assert(std::is_same_v<S::value_type, char32_t>, ""); 83 static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); 84 static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); 85 assert(s1.size() == 10); 86 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 87 } 88 89 return true; 90 } 91 92 int main(int, char**) 93 { 94 95 return 0; 96 } 97