]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/vector/cons/55977.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / cons / 55977.cc
1 // { dg-do compile { target c++11 } }
2
3 // Copyright (C) 2013-2019 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <memory>
21 #include <utility>
22 #include <vector>
23 #include <iterator>
24
25 template <class T>
26 struct MyAllocator
27 {
28 std::allocator<T> base;
29 typedef T value_type;
30 MyAllocator() = default;
31 template <class U>
32 MyAllocator(const MyAllocator<U>& other) : base(other.base) {}
33 T* allocate(std::size_t n) { return base.allocate(n); }
34 void deallocate(T* p, std::size_t n) { return base.deallocate(p, n); }
35 template <class U, class... Args>
36 void construct(U* p, Args&&... args)
37 {
38 ::new (static_cast<void*>(p)) U(std::forward<Args>(args)...);
39 }
40 };
41
42 struct A
43 {
44 private:
45 friend class MyAllocator<A>;
46 A(int value) : value(value) {}
47 int value;
48 public:
49 A() : value() {}
50 int get() const { return value; }
51 };
52
53 void foo()
54 {
55 std::vector<A, MyAllocator<A>> v1;
56 const int i = 1;
57 v1.emplace_back(i); // OK
58 std::vector<A, MyAllocator<A>> v2(std::istream_iterator<int>(), {}); // ERROR
59 }