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// <forward_list>
12
13// template <class... Args> reference emplace_front(Args&&... args); // constexpr since C++26
14// return type is 'reference' in C++17; 'void' before
15
16#include <forward_list>
17#include <cassert>
18
19#include "test_macros.h"
20
21#include "../../../Emplaceable.h"
22#include "min_allocator.h"
23
24TEST_CONSTEXPR_CXX26 bool test() {
25 {
26 typedef Emplaceable T;
27 typedef std::forward_list<T> C;
28 C c;
29#if TEST_STD_VER > 14
30 T& r1 = c.emplace_front();
31 assert(c.front() == Emplaceable());
32 assert(&r1 == &c.front());
33 assert(std::distance(c.begin(), c.end()) == 1);
34 T& r2 = c.emplace_front(1, 2.5);
35 assert(c.front() == Emplaceable(1, 2.5));
36 assert(&r2 == &c.front());
37#else
38 c.emplace_front();
39 assert(c.front() == Emplaceable());
40 assert(std::distance(c.begin(), c.end()) == 1);
41 c.emplace_front(args: 1, args: 2.5);
42 assert(c.front() == Emplaceable(1, 2.5));
43#endif
44 assert(*std::next(c.begin()) == Emplaceable());
45 assert(std::distance(c.begin(), c.end()) == 2);
46 }
47 {
48 typedef Emplaceable T;
49 typedef std::forward_list<T, min_allocator<T>> C;
50 C c;
51#if TEST_STD_VER > 14
52 T& r1 = c.emplace_front();
53 assert(c.front() == Emplaceable());
54 assert(&r1 == &c.front());
55 assert(std::distance(c.begin(), c.end()) == 1);
56 T& r2 = c.emplace_front(1, 2.5);
57 assert(c.front() == Emplaceable(1, 2.5));
58 assert(&r2 == &c.front());
59#else
60 c.emplace_front();
61 assert(c.front() == Emplaceable());
62 assert(std::distance(c.begin(), c.end()) == 1);
63 c.emplace_front(1, 2.5);
64 assert(c.front() == Emplaceable(1, 2.5));
65#endif
66 assert(*std::next(c.begin()) == Emplaceable());
67 assert(std::distance(c.begin(), c.end()) == 2);
68 }
69
70 return true;
71}
72
73int main(int, char**) {
74 assert(test());
75#if TEST_STD_VER >= 26
76 static_assert(test());
77#endif
78
79 return 0;
80}
81

source code of libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp