// { dg-do run { target c++14 } }
// Copyright (C) 2016-2017 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// .
#include
#include
#include
using std::experimental::pmr::memory_resource;
using std::experimental::pmr::resource_adaptor;
template
struct Allocator : __gnu_test::SimpleAllocator
{
Allocator(int) { } // not default constructible
template
Allocator(const Allocator&) { }
};
template
bool aligned(void* p)
{
return (reinterpret_cast(p) % alignof(T)) == 0;
}
// resource_adaptor
void
test05()
{
using std::max_align_t;
using std::uintptr_t;
void* p = nullptr;
Allocator a1(1), a2(2); // minimal interface allocators
resource_adaptor r1(a1), r2(a2);
VERIFY( r1 == r1 );
VERIFY( r1 == r2 );
p = r1.allocate(1);
VERIFY( aligned(p) );
r1.deallocate(p, 1);
p = r1.allocate(1, alignof(short));
VERIFY( aligned(p) );
r1.deallocate(p, 1, alignof(short));
p = r1.allocate(1, alignof(long));
VERIFY( aligned(p) );
r1.deallocate(p, 1, alignof(long));
__gnu_test::uneq_allocator a3(3), a4(4); // non-equal allocators
resource_adaptor r3(a3), r4(a4);
VERIFY( r3 == r3 );
VERIFY( r4 == r4 );
VERIFY( r3 != r4 );
p = r3.allocate(1);
VERIFY( aligned(p) );
r3.deallocate(p, 1);
p = r3.allocate(1, alignof(short));
VERIFY( aligned(p) );
r3.deallocate(p, 1, alignof(short));
p = r3.allocate(1, alignof(long));
VERIFY( aligned(p) );
r3.deallocate(p, 1, alignof(long));
// TODO test with an allocator that doesn't use new or malloc, so
// returns pointers that are not suitably aligned for any type.
}
int main()
{
test05();
}