1 // Copyright (C) 2016 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++11" }
26 struct TaggingAllocator
30 TaggingAllocator() = default;
33 TaggingAllocator(const TaggingAllocator
<U
>&) { }
36 allocate(std::size_t n
) { return std::allocator
<T
>{}.allocate(n
); }
39 deallocate(T
* p
, std::size_t n
) { std::allocator
<T
>{}.deallocate(p
, n
); }
41 template<typename U
, typename
... Args
>
43 construct(U
* p
, Args
&&... args
)
44 { ::new((void*)p
) U(Tag
{}, std::forward
<Args
>(args
)...); }
46 template<typename U
, typename
... Args
>
52 template<typename T
, typename U
>
54 operator==(const TaggingAllocator
<T
>&, const TaggingAllocator
<U
>&)
57 template<typename T
, typename U
>
59 operator!=(const TaggingAllocator
<T
>&, const TaggingAllocator
<U
>&)
64 // All constructors must be passed the Tag type.
66 // DefaultInsertable into vector<X, TaggingAllocator<X>>,
68 // CopyInsertable into vector<X, TaggingAllocator<X>>,
70 // MoveInsertable into vector<X, TaggingAllocator<X>>, and
73 // EmplaceConstructible into vector<X, TaggingAllocator<X>> from args.
74 template<typename
... Args
>
77 // not DefaultConstructible, CopyConstructible or MoveConstructible.
83 X
& operator=(const X
&) { return *this; }
86 X
& operator=(X
&&) { return *this; }
92 // Erasable from vector<X, TaggingAllocator<X>>.
93 friend class TaggingAllocator
<X
>;
96 template class std::vector
<X
, TaggingAllocator
<X
>>;
100 std::vector
<X
, TaggingAllocator
<X
>> v
;
103 v
.emplace(v
.begin());
104 v
.emplace(v
.begin(), 1, 2, 3);