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// <queue>
10
11// priority_queue(const Compare& comp, const Container& c);
12
13#include <queue>
14#include <cassert>
15#include <functional>
16
17#include "test_macros.h"
18#if TEST_STD_VER >= 11
19# include "test_convertible.h"
20#endif
21
22template <class C>
23TEST_CONSTEXPR_CXX26 C make(int n) {
24 C c;
25 for (int i = 0; i < n; ++i)
26 c.push_back(i);
27 return c;
28}
29
30TEST_CONSTEXPR_CXX26 bool test() {
31 typedef std::vector<int> Container;
32 typedef std::greater<int> Compare;
33 typedef std::priority_queue<int, Container, Compare> Q;
34 Container v = make<Container>(5);
35 Q q(Compare(), v);
36 assert(q.size() == 5);
37 assert(q.top() == 0);
38
39#if TEST_STD_VER >= 11
40 // It should be explicit, so not convertible before C++20.
41 static_assert(test_convertible<Q, const Compare&, const Container&>(), "");
42#endif
43
44 return true;
45}
46
47int main(int, char**) {
48 assert(test());
49#if TEST_STD_VER >= 26
50 static_assert(test());
51#endif
52
53 return 0;
54}
55

source code of libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp