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