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// back_insert_iterator
12
13// requires CopyConstructible<Cont::value_type>
14// back_insert_iterator<Cont>&
15// operator=(const Cont::value_type& value);
16
17#include <iterator>
18#include <vector>
19#include <cassert>
20
21#include "test_macros.h"
22#include "test_constexpr_container.h"
23
24template <class C>
25TEST_CONSTEXPR_CXX14 bool
26test(C c)
27{
28 const typename C::value_type v = typename C::value_type();
29 std::back_insert_iterator<C> i(c);
30 i = v;
31 assert(c.back() == v);
32 return true;
33}
34
35class Copyable
36{
37 int data_;
38public:
39 Copyable() : data_(0) {}
40 Copyable(const Copyable&) = default;
41 Copyable& operator=(const Copyable&) = default;
42 ~Copyable() {data_ = -1;}
43
44 friend bool operator==(const Copyable& x, const Copyable& y)
45 {return x.data_ == y.data_;}
46};
47
48int main(int, char**)
49{
50 test(std::vector<Copyable>());
51#if TEST_STD_VER >= 20
52 test(ConstexprFixedCapacityDeque<int, 10>());
53 static_assert(test(ConstexprFixedCapacityDeque<int, 10>()));
54#endif
55 return 0;
56}
57

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