62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <stack>12 13// template <class... Args> decltype(auto) emplace(Args&&... args);14// return type is 'decltype(auto)' in C++17; 'void' before15// 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 25template <typename Stack>26void 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 > 1432 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#else35 static_assert(std::is_same<stack_return_type, void>::value, "");36#endif37}38 39int main(int, char**) {40 test_return_type<std::stack<int> >();41 test_return_type<std::stack<int, std::vector<int> > >();42 43 std::stack<Emplaceable> q;44#if TEST_STD_VER > 1445 typedef Emplaceable T;46 T& r1 = q.emplace(1, 2.5);47 assert(&r1 == &q.top());48 T& r2 = q.emplace(2, 3.5);49 assert(&r2 == &q.top());50 T& r3 = q.emplace(3, 4.5);51 assert(&r3 == &q.top());52#else53 q.emplace(1, 2.5);54 q.emplace(2, 3.5);55 q.emplace(3, 4.5);56#endif57 assert(q.size() == 3);58 assert(q.top() == Emplaceable(3, 4.5));59 60 return 0;61}62