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 // <stack>
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 #include <stack>
19 #include <cassert>
20 #include <vector>
21
22 #include "test_macros.h"
23
24 #include "../../../Emplaceable.h"
25
26 template <typename Stack>
test_return_type()27 void test_return_type() {
28 typedef typename Stack::container_type Container;
29 typedef typename Container::value_type value_type;
30 typedef decltype(std::declval<Stack>().emplace(std::declval<value_type &>())) stack_return_type;
31
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<stack_return_type, container_return_type>::value, "");
35 #else
36 static_assert(std::is_same<stack_return_type, void>::value, "");
37 #endif
38 }
39
main()40 int main()
41 {
42 test_return_type<std::stack<int> > ();
43 test_return_type<std::stack<int, std::vector<int> > > ();
44
45 std::stack<Emplaceable> q;
46 #if TEST_STD_VER > 14
47 typedef Emplaceable T;
48 T& r1 = q.emplace(1, 2.5);
49 assert(&r1 == &q.top());
50 T& r2 = q.emplace(2, 3.5);
51 assert(&r2 == &q.top());
52 T& r3 = q.emplace(3, 4.5);
53 assert(&r3 == &q.top());
54 #else
55 q.emplace(1, 2.5);
56 q.emplace(2, 3.5);
57 q.emplace(3, 4.5);
58 #endif
59 assert(q.size() == 3);
60 assert(q.top() == Emplaceable(3, 4.5));
61 }
62