// { 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 #include void test_deduction_guide(long* p) { __gnu_test::test_input_range r(p, p); std::stack s(std::from_range, r); static_assert(std::is_same_v>); using Alloc = __gnu_test::SimpleAllocator; Alloc alloc; std::stack s2(std::from_range, r, alloc); static_assert(std::is_same_v>>); } template constexpr void do_test() { // The stack's value_type. using V = typename Cont::value_type; // The range's value_type. using T = std::ranges::range_value_t; T a[]{1,2,3,4,5,6,7,8,9}; auto eq = [](std::stack& l, std::span r) { if (l.size() != r.size()) return false; for (auto const& v : r | std::views::reverse) { if (v != l.top()) return false; l.pop(); } return true; }; std::stack s0(std::from_range, Range(a, a+0)); VERIFY( s0.empty() ); std::stack s4(std::from_range, Range(a, a+4)); VERIFY( eq(s4, {a, 4}) ); typename Cont::allocator_type alloc; std::stack s9(std::from_range, Range(a, a+9), alloc); VERIFY( eq(s9, {a, 9}) ); } template> struct NoFromRangeCont : std::deque { NoFromRangeCont() = default; NoFromRangeCont(const Alloc& a) : std::deque(a) {} }; template void do_test_c() { do_test>(); do_test>>(); do_test>(); do_test>(); } bool test_ranges() { using namespace __gnu_test; do_test_c>(); do_test_c>(); do_test_c>(); return true; } int main() { test_ranges(); }