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