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// <iterator>
10
11// template <BackInsertionContainer Cont>
12// back_insert_iterator<Cont>
13// back_inserter(Cont& x); // constexpr in C++20
14
15// template <BackInsertionContainer Cont>
16// front_insert_iterator<Cont>
17// front_inserter(Cont& x); // constexpr in C++20
18
19#include <cassert>
20#include <iterator>
21#include <list>
22
23#include "test_macros.h"
24#include "nasty_containers.h"
25#include "test_constexpr_container.h"
26
27template <class C>
28TEST_CONSTEXPR_CXX20 bool
29test(C c)
30{
31 std::back_insert_iterator<C> i = std::back_inserter(c);
32 i = 3;
33 assert(c.size() == 1);
34 assert(c.back() == 3);
35 i = 4;
36 assert(c.size() == 2);
37 assert(c.back() == 4);
38 return true;
39}
40
41int main(int, char**)
42{
43 test(std::vector<int>());
44 test(nasty_vector<int>());
45#if TEST_STD_VER >= 20
46 test(ConstexprFixedCapacityDeque<int, 10>());
47 static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
48#endif
49 return 0;
50}
51

source code of libcxx/test/std/iterators/predef.iterators/insert.iterators/back.insert.iter.ops/back.inserter/test.pass.cpp