1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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.
22 #include "test_macros.h"
24 #include "../../../Emplaceable.h"
26 template <typename Queue
>
27 void test_return_type() {
28 typedef typename
Queue::container_type Container
;
29 typedef typename
Container::value_type value_type
;
30 typedef decltype(std::declval
<Queue
>().emplace(std::declval
<value_type
&>())) queue_return_type
;
33 typedef decltype(std::declval
<Container
>().emplace_back(std::declval
<value_type
>())) container_return_type
;
34 static_assert(std::is_same
<queue_return_type
, container_return_type
>::value
, "");
36 static_assert(std::is_same
<queue_return_type
, void>::value
, "");
42 test_return_type
<std::queue
<int> > ();
43 test_return_type
<std::queue
<int, std::list
<int> > > ();
45 std::queue
<Emplaceable
> q
;
47 typedef Emplaceable T
;
48 T
& r1
= q
.emplace(1, 2.5);
49 assert(&r1
== &q
.back());
50 T
& r2
= q
.emplace(2, 3.5);
51 assert(&r2
== &q
.back());
52 T
& r3
= q
.emplace(3, 4.5);
53 assert(&r3
== &q
.back());
54 assert(&r1
== &q
.front());
61 assert(q
.size() == 3);
62 assert(q
.front() == Emplaceable(1, 2.5));
63 assert(q
.back() == Emplaceable(3, 4.5));