Fortran: ICE in gfc_conv_expr_present w. defined assignment [PR118640]
[gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / modifiers / append_range.cc
blob5725cd2ad483478b0d708094955c8a8af1a58c0a
1 // { dg-do run { target c++23 } }
3 #include <vector>
4 #include <span>
5 #include <testsuite_hooks.h>
6 #include <testsuite_iterators.h>
7 #include <testsuite_allocator.h>
9 template<typename Range, typename Alloc>
10 constexpr void
11 do_test()
13 // The vector's value_type.
14 using V = typename std::allocator_traits<Alloc>::value_type;
16 // The range's value_type.
17 using T = std::ranges::range_value_t<Range>;
18 T a[]{1,2,3,4,5,6,7,8,9};
20 auto eq = [](const std::vector<V, Alloc>& l, std::span<T> r) {
21 if (l.size() != r.size())
22 return false;
23 for (auto i = 0u; i < l.size(); ++i)
24 if (l[i] != r[i])
25 return false;
26 return true;
29 Range r4(a, a+4);
30 Range r5(a+4, a+9);
32 std::vector<V, Alloc> v;
33 v.append_range(r4);
34 VERIFY( eq(v, {a, 4}) );
35 v.append_range(r5); // larger than v.capacity()
36 VERIFY( eq(v, a) );
37 v.append_range(Range(a, a));
38 VERIFY( eq(v, a) );
39 v.clear();
40 v.append_range(Range(a, a));
41 VERIFY( v.empty() );
44 template<typename Range>
45 void
46 do_test_a()
48 do_test<Range, std::allocator<int>>();
49 do_test<Range, __gnu_test::SimpleAllocator<int>>();
52 bool
53 test_ranges()
55 using namespace __gnu_test;
57 do_test_a<test_forward_range<int>>();
58 do_test_a<test_forward_sized_range<int>>();
59 do_test_a<test_sized_range_sized_sent<int, forward_iterator_wrapper>>();
61 do_test_a<test_input_range<int>>();
62 do_test_a<test_input_sized_range<int>>();
63 do_test_a<test_sized_range_sized_sent<int, input_iterator_wrapper>>();
65 do_test_a<test_range<int, input_iterator_wrapper_nocopy>>();
66 do_test_a<test_sized_range<int, input_iterator_wrapper_nocopy>>();
67 do_test_a<test_sized_range_sized_sent<int, input_iterator_wrapper_nocopy>>();
69 do_test_a<test_forward_range<short>>();
70 do_test_a<test_input_range<short>>();
72 // Not lvalue-convertible to int
73 struct C {
74 C(int v) : val(v) { }
75 operator int() && { return val; }
76 bool operator==(int b) const { return b == val; }
77 int val;
79 using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
80 do_test<rvalue_input_range, std::allocator<int>>();
82 return true;
85 constexpr bool
86 test_constexpr()
88 // XXX: this doesn't test the non-forward_range code paths are constexpr.
89 do_test<std::span<short>, std::allocator<int>>();
90 return true;
93 int main()
95 test_ranges();
96 static_assert( test_constexpr() );