]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/memory_resource/resource_adaptor.cc
1 // { dg-do run { target c++14 } }
3 // Copyright (C) 2016-2018 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/>.
20 #include <experimental/memory_resource>
21 #include <testsuite_hooks.h>
22 #include <testsuite_allocator.h>
24 using std::experimental::pmr::memory_resource
;
25 using std::experimental::pmr::resource_adaptor
;
28 struct Allocator
: __gnu_test::SimpleAllocator
<T
>
30 Allocator(int) { } // not default constructible
33 Allocator(const Allocator
<U
>&) { }
39 return (reinterpret_cast<std::uintptr_t>(p
) % alignof(T
)) == 0;
46 using std::max_align_t
;
50 Allocator
<int> a1(1), a2(2); // minimal interface allocators
51 resource_adaptor
<decltype(a1
)> r1(a1
), r2(a2
);
55 VERIFY( aligned
<max_align_t
>(p
) );
57 p
= r1
.allocate(1, alignof(short));
58 VERIFY( aligned
<short>(p
) );
59 r1
.deallocate(p
, 1, alignof(short));
60 p
= r1
.allocate(1, alignof(long));
61 VERIFY( aligned
<long>(p
) );
62 r1
.deallocate(p
, 1, alignof(long));
64 __gnu_test::uneq_allocator
<double> a3(3), a4(4); // non-equal allocators
65 resource_adaptor
<decltype(a3
)> r3(a3
), r4(a4
);
70 VERIFY( aligned
<max_align_t
>(p
) );
72 p
= r3
.allocate(1, alignof(short));
73 VERIFY( aligned
<short>(p
) );
74 r3
.deallocate(p
, 1, alignof(short));
75 p
= r3
.allocate(1, alignof(long));
76 VERIFY( aligned
<long>(p
) );
77 r3
.deallocate(p
, 1, alignof(long));
79 // TODO test with an allocator that doesn't use new or malloc, so
80 // returns pointers that are not suitably aligned for any type.