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