// { 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 #include struct Gt { template bool operator()(T const& l, U const & r) { return l > r; } }; void test_deduction_guide(long* p) { __gnu_test::test_input_range r(p, p); std::priority_queue pq(std::from_range, r); static_assert(std::is_same_v>); Gt cmp; std::priority_queue pq3(std::from_range, r, cmp); static_assert(std::is_same_v, Gt>>); using Alloc = __gnu_test::SimpleAllocator; Alloc alloc; std::priority_queue pq2(std::from_range, r, alloc); static_assert(std::is_same_v>>); std::priority_queue pq4(std::from_range, r, cmp, alloc); static_assert(std::is_same_v, Gt>>); } template> constexpr void do_test(Cmp cmp = Cmp()) { // The queue'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::priority_queue& l, std::span r) { if (l.size() != r.size()) return false; std::vector s(r.begin(), r.end()); std::ranges::sort(s, cmp); for (auto const& v : s | std::views::reverse) { if (v != l.top()) return false; l.pop(); } return true; }; std::priority_queue pq0(std::from_range, Range(a, a+0)); VERIFY( pq0.empty() ); std::priority_queue pq4(std::from_range, Range(a, a+4), cmp); VERIFY( eq(pq4, {a, 4}) ); typename Cont::allocator_type alloc; std::priority_queue pq7(std::from_range, Range(a, a+7), alloc); VERIFY( eq(pq7, {a, 7}) ); std::priority_queue pq9(std::from_range, Range(a, a+9), cmp, alloc); VERIFY( eq(pq9, {a, 9}) ); } template> struct NoFromRangeCont : std::vector { NoFromRangeCont() = default; NoFromRangeCont(const Alloc& a) : std::vector(a) {} }; template void do_test_c() { do_test>(); do_test>>(); do_test, Gt>(); do_test>, Gt>(); 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(); }