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 // XFAIL: libcpp-no-deduction-guides 12 13 // template<class InputIterator> 14 // basic_string(InputIterator begin, InputIterator end, 15 // const Allocator& a = Allocator()); 16 17 // template<class InputIterator, 18 // class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> 19 // basic_string(InputIterator, InputIterator, Allocator = Allocator()) 20 // -> basic_string<typename iterator_traits<InputIterator>::value_type, 21 // char_traits<typename iterator_traits<InputIterator>::value_type>, 22 // Allocator>; 23 // 24 // The deduction guide shall not participate in overload resolution if InputIterator 25 // is a type that does not qualify as an input iterator, or if Allocator is a type 26 // that does not qualify as an allocator. 27 28 29 #include <string> 30 #include <iterator> 31 #include <cassert> 32 #include <cstddef> 33 34 #include "test_macros.h" 35 #include "test_allocator.h" 36 #include "../input_iterator.h" 37 #include "min_allocator.h" 38 39 int main(int, char**) 40 { 41 { 42 const char* s = "12345678901234"; 43 std::basic_string s1(s, s+10); // Can't use {} here 44 using S = decltype(s1); // what type did we get? 45 static_assert(std::is_same_v<S::value_type, char>, ""); 46 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 47 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 48 assert(s1.size() == 10); 49 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 50 } 51 52 { 53 const char* s = "12345678901234"; 54 std::basic_string s1{s, s+10, std::allocator<char>{}}; 55 using S = decltype(s1); // what type did we get? 56 static_assert(std::is_same_v<S::value_type, char>, ""); 57 static_assert(std::is_same_v<S::traits_type, std::char_traits<char>>, ""); 58 static_assert(std::is_same_v<S::allocator_type, std::allocator<char>>, ""); 59 assert(s1.size() == 10); 60 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 61 } 62 { 63 const wchar_t* s = L"12345678901234"; 64 std::basic_string s1{s, s+10, test_allocator<wchar_t>{}}; 65 using S = decltype(s1); // what type did we get? 66 static_assert(std::is_same_v<S::value_type, wchar_t>, ""); 67 static_assert(std::is_same_v<S::traits_type, std::char_traits<wchar_t>>, ""); 68 static_assert(std::is_same_v<S::allocator_type, test_allocator<wchar_t>>, ""); 69 assert(s1.size() == 10); 70 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 71 } 72 { 73 const char16_t* s = u"12345678901234"; 74 std::basic_string s1{s, s+10, min_allocator<char16_t>{}}; 75 using S = decltype(s1); // what type did we get? 76 static_assert(std::is_same_v<S::value_type, char16_t>, ""); 77 static_assert(std::is_same_v<S::traits_type, std::char_traits<char16_t>>, ""); 78 static_assert(std::is_same_v<S::allocator_type, min_allocator<char16_t>>, ""); 79 assert(s1.size() == 10); 80 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 81 } 82 { 83 const char32_t* s = U"12345678901234"; 84 std::basic_string s1{s, s+10, explicit_allocator<char32_t>{}}; 85 using S = decltype(s1); // what type did we get? 86 static_assert(std::is_same_v<S::value_type, char32_t>, ""); 87 static_assert(std::is_same_v<S::traits_type, std::char_traits<char32_t>>, ""); 88 static_assert(std::is_same_v<S::allocator_type, explicit_allocator<char32_t>>, ""); 89 assert(s1.size() == 10); 90 assert(s1.compare(0, s1.size(), s, s1.size()) == 0); 91 } 92 93 return 0; 94 } 95