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 11 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 12 // To silence a GCC warning-turned-error re. `BadAlloc::value_type`. 13 // ADDITIONAL_COMPILE_FLAGS: -Wno-unused-local-typedefs 14 15 // template<ranges::input_range R, 16 // class Allocator = allocator<ranges::range_value_t<R>>> 17 // basic_string(from_range_t, R&&, Allocator = Allocator()) 18 // -> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>, 19 // Allocator>; // C++23 20 // 21 // The deduction guide shall not participate in overload resolution if Allocator 22 // is a type that does not qualify as an allocator (in addition to the `input_range` concept being satisfied by `R`). 23 24 #include <array> 25 #include <string> 26 27 #include "deduction_guides_sfinae_checks.h" 28 #include "test_allocator.h" 29 30 int main(int, char**) { 31 using Char = char16_t; 32 33 { 34 std::basic_string c(std::from_range, std::array<Char, 0>()); 35 static_assert(std::is_same_v<decltype(c), std::basic_string<Char>>); 36 } 37 38 { 39 using Alloc = test_allocator<Char>; 40 std::basic_string c(std::from_range, std::array<Char, 0>(), Alloc()); 41 static_assert(std::is_same_v<decltype(c), std::basic_string<Char, std::char_traits<Char>, Alloc>>); 42 } 43 44 // Note: defining `value_type` is a workaround because one of the deduction guides will end up instantiating 45 // `basic_string`, and that would fail with a hard error if the given allocator doesn't define `value_type`. 46 struct BadAlloc { 47 using value_type = char; 48 }; 49 SequenceContainerDeductionGuidesSfinaeAway<std::basic_string, std::basic_string<char>, BadAlloc>(); 50 51 return 0; 52 } 53