]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/scoped_allocator/1.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2017 Free Software Foundation, Inc.
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)
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.
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/>.
21 #include <scoped_allocator>
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 using __gnu_test::uneq_allocator
;
30 typedef uneq_allocator
<Element
> allocator_type
;
34 Element(const allocator_type
& a
= allocator_type()) : alloc(a
) { }
36 Element(std::allocator_arg_t
, const allocator_type
& a
, int = 0)
39 Element(std::allocator_arg_t
, const allocator_type
& a
, const Element
&)
42 const allocator_type
& get_allocator() const { return alloc
; }
47 typedef std::scoped_allocator_adaptor
<Element::allocator_type
> alloc1_type
;
49 typedef std::vector
<Element
, alloc1_type
> EltVec
;
54 VERIFY( ev1
.get_allocator().get_personality() == 1 );
55 VERIFY( ev1
[0].get_allocator().get_personality() == 1 );
60 typedef std::scoped_allocator_adaptor
<Element::allocator_type
> inner_alloc_type
;
62 typedef std::vector
<Element
, inner_alloc_type
> EltVec
;
64 typedef std::scoped_allocator_adaptor
<Element::allocator_type
,
65 Element::allocator_type
> alloc_type
;
67 typedef std::vector
<EltVec
, alloc_type
> EltVecVec
;
69 alloc_type
a(1, Element::allocator_type(2)); // outer=1, inner=2
72 EltVecVec
evv(1, ev
, a
);
74 VERIFY( evv
.get_allocator().get_personality() == 1 );
75 VERIFY( evv
[0].get_allocator().get_personality() == 2 );
76 VERIFY( evv
[0][0].get_allocator().get_personality() == 2 );
78 alloc_type
a2(3, Element::allocator_type(4)); // outer=3, inner=4
80 EltVecVec
evv2(evv
, a2
); // copy with a different allocator
82 VERIFY( evv2
.get_allocator().get_personality() == 3 );
83 VERIFY( evv2
[0].get_allocator().get_personality() == 4 );
84 VERIFY( evv2
[0][0].get_allocator().get_personality() == 4 );
86 EltVecVec
evv3(std::move(evv
), a2
); // move with a different allocator
88 VERIFY( evv3
.get_allocator().get_personality() == 3 );
89 VERIFY( evv3
[0].get_allocator().get_personality() == 4 );
90 VERIFY( evv3
[0][0].get_allocator().get_personality() == 4 );