// { dg-do run { target c++23 } } #include #if __cpp_lib_containers_ranges != 202202L # error "Feature-test macro __cpp_lib_containers_ranges has wrong value in " #endif #include #include #include #include #include template constexpr void do_test(Alloc alloc) { using T = std::ranges::range_value_t; T a[]{1,1,0,1,0,0,1,0,0}; auto eq = [](const std::vector& l, std::span r) { if (l.size() != r.size()) return false; for (auto i = 0u; i < l.size(); ++i) if (l[i] != r[i]) return false; return true; }; std::vector v0(std::from_range, Range(a, a+0)); VERIFY( v0.empty() ); VERIFY( v0.get_allocator() == Alloc() ); std::vector v4(std::from_range, Range(a, a+4)); VERIFY( eq(v4, {a, 4}) ); VERIFY( v4.get_allocator() == Alloc() ); std::vector v9(std::from_range, Range(a, a+9), alloc); VERIFY( eq(v9, {a, 9}) ); VERIFY( v9.get_allocator() == alloc ); } template void do_test_a() { do_test(std::allocator()); do_test(__gnu_test::uneq_allocator(42)); } bool test_ranges() { using namespace __gnu_test; do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); do_test_a>(); // Not lvalue-convertible to bool struct C { C(bool v) : val(v) { } operator bool() && { return val; } bool operator==(bool b) const { return b == val; } bool val; }; using rvalue_input_range = test_range; do_test(std::allocator()); return true; } constexpr bool test_constexpr() { // XXX: this doesn't test the non-forward_range code paths are constexpr. do_test>(std::allocator()); return true; } int main() { test_ranges(); static_assert( test_constexpr() ); }