Implement LWG2783: stack::emplace() and queue::emplace() should return decltype(auto)

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323385 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2018-01-24 22:42:25 +00:00
parent 8286acce44
commit cc7048888e
5 changed files with 64 additions and 26 deletions

View File

@@ -11,20 +11,39 @@
// <stack>
// template <class... Args> reference emplace(Args&&... args);
// return type is 'reference' in C++17; 'void' before
// template <class... Args> decltype(auto) emplace(Args&&... args);
// return type is 'decltype(auto)' in C++17; 'void' before
// whatever the return type of the underlying container's emplace_back() returns.
#include <stack>
#include <cassert>
#include <vector>
#include "test_macros.h"
#include "../../../Emplaceable.h"
template <typename Stack>
void test_return_type() {
typedef typename Stack::container_type Container;
typedef typename Container::value_type value_type;
typedef decltype(std::declval<Stack>().emplace(std::declval<value_type &>())) stack_return_type;
#if TEST_STD_VER > 14
typedef decltype(std::declval<Container>().emplace_back(std::declval<value_type>())) container_return_type;
static_assert(std::is_same<stack_return_type, container_return_type>::value, "");
#else
static_assert(std::is_same<stack_return_type, void>::value, "");
#endif
}
int main()
{
test_return_type<std::stack<int> > ();
test_return_type<std::stack<int, std::vector<int> > > ();
typedef Emplaceable T;
std::stack<Emplaceable> q;
std::stack<Emplaceable> q;
#if TEST_STD_VER > 14
T& r1 = q.emplace(1, 2.5);
assert(&r1 == &q.top());