1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // UNSUPPORTED: c++98, c++03
11 
12 // <queue>
13 
14 // template <class... Args> decltype(auto) emplace(Args&&... args);
15 // return type is 'decltype(auto)' in C++17; 'void' before
16 // whatever the return type of the underlying container's emplace_back() returns.
17 
18 
19 #include <queue>
20 #include <cassert>
21 #include <list>
22 
23 #include "test_macros.h"
24 
25 #include "../../../Emplaceable.h"
26 
27 template <typename Queue>
test_return_type()28 void test_return_type() {
29     typedef typename Queue::container_type Container;
30     typedef typename Container::value_type value_type;
31     typedef decltype(std::declval<Queue>().emplace(std::declval<value_type &>())) queue_return_type;
32 
33 #if TEST_STD_VER > 14
34     typedef decltype(std::declval<Container>().emplace_back(std::declval<value_type>())) container_return_type;
35     static_assert(std::is_same<queue_return_type, container_return_type>::value, "");
36 #else
37     static_assert(std::is_same<queue_return_type, void>::value, "");
38 #endif
39 }
40 
main()41 int main()
42 {
43     test_return_type<std::queue<int> > ();
44     test_return_type<std::queue<int, std::list<int> > > ();
45 
46     std::queue<Emplaceable> q;
47 #if TEST_STD_VER > 14
48     typedef Emplaceable T;
49     T& r1 = q.emplace(1, 2.5);
50     assert(&r1 == &q.back());
51     T& r2 = q.emplace(2, 3.5);
52     assert(&r2 == &q.back());
53     T& r3 = q.emplace(3, 4.5);
54     assert(&r3 == &q.back());
55     assert(&r1 == &q.front());
56 #else
57     q.emplace(1, 2.5);
58     q.emplace(2, 3.5);
59     q.emplace(3, 4.5);
60 #endif
61 
62     assert(q.size() == 3);
63     assert(q.front() == Emplaceable(1, 2.5));
64     assert(q.back() == Emplaceable(3, 4.5));
65 }
66