[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / container.adaptors / queue / queue.defn / emplace.pass.cpp
blobbdfd9df7978c436c3e888bb589be5a199177fc4a
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <queue>
13 // template <class... Args> decltype(auto) emplace(Args&&... args);
14 // return type is 'decltype(auto)' in C++17; 'void' before
15 // whatever the return type of the underlying container's emplace_back() returns.
18 #include <queue>
19 #include <cassert>
20 #include <list>
22 #include "test_macros.h"
24 #include "../../../Emplaceable.h"
26 template <typename Queue>
27 void test_return_type() {
28 typedef typename Queue::container_type Container;
29 typedef typename Container::value_type value_type;
30 typedef decltype(std::declval<Queue>().emplace(std::declval<value_type &>())) queue_return_type;
32 #if TEST_STD_VER > 14
33 typedef decltype(std::declval<Container>().emplace_back(std::declval<value_type>())) container_return_type;
34 static_assert(std::is_same<queue_return_type, container_return_type>::value, "");
35 #else
36 static_assert(std::is_same<queue_return_type, void>::value, "");
37 #endif
40 int main(int, char**)
42 test_return_type<std::queue<int> > ();
43 test_return_type<std::queue<int, std::list<int> > > ();
45 std::queue<Emplaceable> q;
46 #if TEST_STD_VER > 14
47 typedef Emplaceable T;
48 T& r1 = q.emplace(1, 2.5);
49 assert(&r1 == &q.back());
50 T& r2 = q.emplace(2, 3.5);
51 assert(&r2 == &q.back());
52 T& r3 = q.emplace(3, 4.5);
53 assert(&r3 == &q.back());
54 assert(&r1 == &q.front());
55 #else
56 q.emplace(1, 2.5);
57 q.emplace(2, 3.5);
58 q.emplace(3, 4.5);
59 #endif
61 assert(q.size() == 3);
62 assert(q.front() == Emplaceable(1, 2.5));
63 assert(q.back() == Emplaceable(3, 4.5));
65 return 0;