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);
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
24int main(int, char**)
25{
26 {
27 typedef Emplaceable T;
28 typedef std::forward_list<T> C;
29 C c;
30#if TEST_STD_VER > 14
31 T& r1 = c.emplace_front();
32 assert(c.front() == Emplaceable());
33 assert(&r1 == &c.front());
34 assert(std::distance(c.begin(), c.end()) == 1);
35 T& r2 = c.emplace_front(1, 2.5);
36 assert(c.front() == Emplaceable(1, 2.5));
37 assert(&r2 == &c.front());
38#else
39 c.emplace_front();
40 assert(c.front() == Emplaceable());
41 assert(std::distance(c.begin(), c.end()) == 1);
42 c.emplace_front(args: 1, args: 2.5);
43 assert(c.front() == Emplaceable(1, 2.5));
44#endif
45 assert(*std::next(c.begin()) == Emplaceable());
46 assert(std::distance(c.begin(), c.end()) == 2);
47 }
48 {
49 typedef Emplaceable T;
50 typedef std::forward_list<T, min_allocator<T>> C;
51 C c;
52#if TEST_STD_VER > 14
53 T& r1 = c.emplace_front();
54 assert(c.front() == Emplaceable());
55 assert(&r1 == &c.front());
56 assert(std::distance(c.begin(), c.end()) == 1);
57 T& r2 = c.emplace_front(1, 2.5);
58 assert(c.front() == Emplaceable(1, 2.5));
59 assert(&r2 == &c.front());
60#else
61 c.emplace_front();
62 assert(c.front() == Emplaceable());
63 assert(std::distance(c.begin(), c.end()) == 1);
64 c.emplace_front(1, 2.5);
65 assert(c.front() == Emplaceable(1, 2.5));
66#endif
67 assert(*std::next(c.begin()) == Emplaceable());
68 assert(std::distance(c.begin(), c.end()) == 2);
69 }
70
71 return 0;
72}
73

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