* doc/invoke.texi: Document -std=c++17 and -std=gnu++17 and document
[official-gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / cons / char / deduction.cc
blob52ab0601a24f3b4ed4695fb3e4b11c515d9f21f5
1 // Copyright (C) 2017 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++17" }
19 // { dg-do compile { target c++17 } }
21 #include <string>
22 #include <testsuite_iterators.h>
24 template<typename C>
25 using input_iterator_seq
26 = __gnu_test::test_container<C, __gnu_test::input_iterator_wrapper>;
28 template<typename T, typename U> struct require_same;
29 template<typename T> struct require_same<T, T> { using type = void; };
31 template<typename T, typename U>
32 typename require_same<T, U>::type
33 check_type(U&) { }
35 void
36 test01()
38 std::string s0;
39 std::allocator<char> a;
41 std::basic_string s1 = s0;
42 check_type<std::string>(s1);
44 std::basic_string s2 = std::move(s0);
45 check_type<std::string>(s2);
47 const std::basic_string s3 = s0;
48 check_type<const std::string>(s3);
50 const std::basic_string s4 = s3;
51 check_type<const std::string>(s4);
53 #if _GLIBCXX_USE_CXX11_ABI
54 std::basic_string s5(s0, a);
55 check_type<std::string>(s5);
57 std::basic_string s6(std::move(s0), a);
58 check_type<std::string>(s6);
59 #endif
61 std::basic_string s7(s0, 0, 0);
62 check_type<std::string>(s7);
65 void
66 test02()
68 char a[1] = {};
69 input_iterator_seq<char> seq(a);
71 std::basic_string s1(seq.begin(), seq.end());
72 check_type<std::string>(s1);
74 std::basic_string s2(seq.begin(), seq.end(), std::allocator<char>());
75 check_type<std::string>(s2);
77 std::basic_string s3((char)1, 'a');
78 check_type<std::string>(s3);
80 std::basic_string s4((char)1, 'a', std::allocator<char>());
81 check_type<std::string>(s4);
84 void
85 test03()
87 char16_t a[1] = {};
88 input_iterator_seq<char16_t> seq(a);
90 std::basic_string s1(seq.begin(), seq.end());
91 check_type<std::u16string>(s1);
93 std::basic_string s2(seq.begin(), seq.end(), std::allocator<char16_t>());
94 check_type<std::u16string>(s2);
96 std::basic_string s3((char16_t)1, u'a');
97 check_type<std::u16string>(s3);
99 std::basic_string s4((char16_t)1, u'a', std::allocator<char16_t>());
100 check_type<std::u16string>(s4);
103 void
104 test04()
106 char32_t a[1] = {};
107 input_iterator_seq<char32_t> seq(a);
109 std::basic_string s1(seq.begin(), seq.end());
110 check_type<std::u32string>(s1);
112 std::basic_string s2(seq.begin(), seq.end(), std::allocator<char32_t>());
113 check_type<std::u32string>(s2);
115 std::basic_string s3((char32_t)1, U'a');
116 check_type<std::u32string>(s3);
118 std::basic_string s4((char32_t)1, U'a', std::allocator<char32_t>());
119 check_type<std::u32string>(s4);