1 // { dg-do run { target c++23 } }
5 #include <testsuite_hooks.h>
6 #include <testsuite_iterators.h>
7 #include <testsuite_allocator.h>
10 test_deduction_guide(long* p
)
12 __gnu_test::test_input_range
<long> r(p
, p
);
13 std::vector
v(std::from_range
, r
);
14 static_assert(std::is_same_v
<decltype(v
), std::vector
<long>>);
16 using Alloc
= __gnu_test::SimpleAllocator
<long>;
18 std::vector
v2(std::from_range
, r
, alloc
);
19 static_assert(std::is_same_v
<decltype(v2
), std::vector
<long, Alloc
>>);
22 template<typename Range
, typename Alloc
>
26 // The vector's value_type.
27 using V
= typename
std::allocator_traits
<Alloc
>::value_type
;
29 // The range's value_type.
30 using T
= std::ranges::range_value_t
<Range
>;
31 T a
[]{1,2,3,4,5,6,7,8,9};
33 auto eq
= [](const std::vector
<V
, Alloc
>& l
, std::span
<T
> r
) {
34 if (l
.size() != r
.size())
36 for (auto i
= 0u; i
< l
.size(); ++i
)
42 std::vector
<V
, Alloc
> v0(std::from_range
, Range(a
, a
+0));
44 VERIFY( v0
.get_allocator() == Alloc() );
46 std::vector
<V
, Alloc
> v4(std::from_range
, Range(a
, a
+4));
47 VERIFY( eq(v4
, {a
, 4}) );
48 VERIFY( v4
.get_allocator() == Alloc() );
50 std::vector
<V
, Alloc
> v9(std::from_range
, Range(a
, a
+9), alloc
);
51 VERIFY( eq(v9
, {a
, 9}) );
52 VERIFY( v9
.get_allocator() == alloc
);
55 template<typename Range
>
59 do_test
<Range
>(std::allocator
<int>());
60 do_test
<Range
>(__gnu_test::uneq_allocator
<int>(42));
66 using namespace __gnu_test
;
68 do_test_a
<test_forward_range
<int>>();
69 do_test_a
<test_forward_sized_range
<int>>();
70 do_test_a
<test_sized_range_sized_sent
<int, forward_iterator_wrapper
>>();
72 do_test_a
<test_input_range
<int>>();
73 do_test_a
<test_input_sized_range
<int>>();
74 do_test_a
<test_sized_range_sized_sent
<int, input_iterator_wrapper
>>();
76 do_test_a
<test_range
<int, input_iterator_wrapper_nocopy
>>();
77 do_test_a
<test_sized_range
<int, input_iterator_wrapper_nocopy
>>();
78 do_test_a
<test_sized_range_sized_sent
<int, input_iterator_wrapper_nocopy
>>();
80 do_test_a
<test_forward_range
<short>>();
81 do_test_a
<test_input_range
<short>>();
83 // Not lvalue-convertible to int
86 operator int() && { return val
; }
87 bool operator==(int b
) const { return b
== val
; }
90 using rvalue_input_range
= test_range
<C
, input_iterator_wrapper_rval
>;
91 do_test
<rvalue_input_range
>(std::allocator
<int>());
99 // XXX: this doesn't test the non-forward_range code paths are constexpr.
100 do_test
<std::span
<short>>(std::allocator
<int>());
107 static_assert( test_constexpr() );