1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
// Copyright (C) 2017-2024 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
// { dg-do compile { target c++17 } }
#include <string>
#include <testsuite_iterators.h>
template<typename C>
using input_iterator_seq
= __gnu_test::test_container<C, __gnu_test::input_iterator_wrapper>;
template<typename T, typename U> struct require_same;
template<typename T> struct require_same<T, T> { using type = void; };
template<typename T, typename U>
typename require_same<T, U>::type
check_type(U&) { }
void
test01()
{
std::string s0;
std::allocator<char> a;
std::basic_string s1 = s0;
check_type<std::string>(s1);
std::basic_string s2 = std::move(s0);
check_type<std::string>(s2);
const std::basic_string s3 = s0;
check_type<const std::string>(s3);
const std::basic_string s4 = s3;
check_type<const std::string>(s4);
#if _GLIBCXX_USE_CXX11_ABI
std::basic_string s5(s0, a);
check_type<std::string>(s5);
std::basic_string s6(std::move(s0), a);
check_type<std::string>(s6);
#endif
std::basic_string s7(s0, 0, 0);
check_type<std::string>(s7);
}
void
test02()
{
char a[1] = {};
input_iterator_seq<char> seq(a);
std::basic_string s1(seq.begin(), seq.end());
check_type<std::string>(s1);
std::basic_string s2(seq.begin(), seq.end(), std::allocator<char>());
check_type<std::string>(s2);
std::basic_string s3((char)1, 'a');
check_type<std::string>(s3);
std::basic_string s4((char)1, 'a', std::allocator<char>());
check_type<std::string>(s4);
}
void
test03()
{
char16_t a[1] = {};
input_iterator_seq<char16_t> seq(a);
std::basic_string s1(seq.begin(), seq.end());
check_type<std::u16string>(s1);
std::basic_string s2(seq.begin(), seq.end(), std::allocator<char16_t>());
check_type<std::u16string>(s2);
std::basic_string s3((char16_t)1, u'a');
check_type<std::u16string>(s3);
std::basic_string s4((char16_t)1, u'a', std::allocator<char16_t>());
check_type<std::u16string>(s4);
}
void
test04()
{
char32_t a[1] = {};
input_iterator_seq<char32_t> seq(a);
std::basic_string s1(seq.begin(), seq.end());
check_type<std::u32string>(s1);
std::basic_string s2(seq.begin(), seq.end(), std::allocator<char32_t>());
check_type<std::u32string>(s2);
std::basic_string s3((char32_t)1, U'a');
check_type<std::u32string>(s3);
std::basic_string s4((char32_t)1, U'a', std::allocator<char32_t>());
check_type<std::u32string>(s4);
}
void
test05()
{
#ifdef _GLIBCXX_USE_CHAR8_T
char8_t a[1] = {};
input_iterator_seq<char8_t> seq(a);
std::basic_string s1(seq.begin(), seq.end());
check_type<std::u8string>(s1);
std::basic_string s2(seq.begin(), seq.end(), std::allocator<char8_t>());
check_type<std::u8string>(s2);
std::basic_string s3((char8_t)1, u8'a');
check_type<std::u8string>(s3);
std::basic_string s4((char8_t)1, u8'a', std::allocator<char8_t>());
check_type<std::u8string>(s4);
#endif
}
void
test06()
{
// LWG 3075 basic_string needs deduction guides from basic_string_view
std::string_view sv{"A View to a Kill"};
const std::allocator<char> a;
std::basic_string s1(sv);
check_type<std::string>(s1);
std::basic_string s2(sv, a);
check_type<std::string>(s2);
std::basic_string s3(sv, 2u, 6u);
check_type<std::string>(s3);
std::basic_string s4(sv, 2u, 6u, a);
check_type<std::string>(s4);
}
void
test07()
{
// LWG 3076 basic_string CTAD ambiguity
using namespace std;
string s0;
basic_string s1(s0, 1, 1);
check_type<std::string>(s1);
basic_string s2("cat"sv, 1, 1);
check_type<std::string>(s2);
basic_string s3("cat", 1);
check_type<std::string>(s3);
}
|