| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | #include <queue> |
| 12 | |
| 13 | #include "../../from_range_container_adaptors.h" |
| 14 | #include "../../../test_compare.h" |
| 15 | #include "test_macros.h" |
| 16 | |
| 17 | // template <container-compatible-range<T> R> |
| 18 | // priority_queue(from_range_t, R&& rg, const Compare& x = Compare()); // since C++23 |
| 19 | // template <container-compatible-range<T> R, class Alloc> |
| 20 | // priority_queue(from_range_t, R&& rg, const Compare&, const Alloc&); // since C++23 |
| 21 | // template <container-compatible-range<T> R, class Alloc> |
| 22 | // priority_queue(from_range_t, R&& rg, const Alloc&); // since C++23 |
| 23 | |
| 24 | template <class Range> |
| 25 | concept PriorityQueueHasFromRangeCtr = requires(Range&& range) { |
| 26 | std::priority_queue<int>(std::from_range, std::forward<Range>(range)); |
| 27 | std::priority_queue<int>(std::from_range, std::forward<Range>(range), std::less<int>()); |
| 28 | std::priority_queue<int>(std::from_range, std::forward<Range>(range), std::less<int>(), std::allocator<int>()); |
| 29 | std::priority_queue<int>(std::from_range, std::forward<Range>(range), std::allocator<int>()); |
| 30 | }; |
| 31 | |
| 32 | constexpr bool test_constraints_priority_queue() { |
| 33 | // Input range with the same value type. |
| 34 | static_assert(PriorityQueueHasFromRangeCtr<InputRange<int>>); |
| 35 | // Input range with a convertible value type. |
| 36 | static_assert(PriorityQueueHasFromRangeCtr<InputRange<double>>); |
| 37 | // Input range with a non-convertible value type. |
| 38 | static_assert(!PriorityQueueHasFromRangeCtr<InputRange<Empty>>); |
| 39 | // Not an input range. |
| 40 | static_assert(!PriorityQueueHasFromRangeCtr<InputRangeNotDerivedFrom>); |
| 41 | static_assert(!PriorityQueueHasFromRangeCtr<InputRangeNotIndirectlyReadable>); |
| 42 | static_assert(!PriorityQueueHasFromRangeCtr<InputRangeNotInputOrOutputIterator>); |
| 43 | |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | int main(int, char**) { |
| 48 | for_all_iterators_and_allocators<int>(f: []<class Iter, class Sent, class Alloc>() { |
| 49 | test_priority_queue<std::vector, int, Iter, Sent, test_less<int>, Alloc>(); |
| 50 | }); |
| 51 | test_container_adaptor_move_only<std::priority_queue>(); |
| 52 | |
| 53 | static_assert(test_constraints_priority_queue()); |
| 54 | |
| 55 | test_exception_safety_throwing_copy<std::priority_queue>(); |
| 56 | test_exception_safety_throwing_allocator<std::priority_queue, int>(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |