Differential D47360 Diff 219818 test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/destroy.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/destroy.pass.cpp
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// | |||||
// The LLVM Compiler Infrastructure | |||||
// | |||||
// This file is dual licensed under the MIT and the University of Illinois Open | |||||
// Source Licenses. See LICENSE.TXT for details. | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
// UNSUPPORTED: c++98, c++03 | |||||
// <memory_resource> | |||||
// template <class T> class polymorphic_allocator | |||||
// template <class U> | |||||
// void polymorphic_allocator<T>::destroy(U * ptr); | |||||
#include <memory_resource> | |||||
#include <type_traits> | |||||
#include <new> | |||||
#include <cassert> | |||||
#include <cstdlib> | |||||
namespace ex = std::pmr; | |||||
int count = 0; | |||||
struct destroyable | |||||
{ | |||||
destroyable() { ++count; } | |||||
~destroyable() { --count; } | |||||
}; | |||||
int main(int, char**) | |||||
{ | |||||
typedef ex::polymorphic_allocator<double> A; | |||||
{ | |||||
A a; | |||||
static_assert( | |||||
std::is_same<decltype(a.destroy((destroyable*)nullptr)), void>::value, | |||||
""); | |||||
} | |||||
{ | |||||
destroyable * ptr = ::new (std::malloc(sizeof(destroyable))) destroyable(); | |||||
assert(count == 1); | |||||
A{}.destroy(ptr); | |||||
assert(count == 0); | |||||
std::free(ptr); | |||||
} | |||||
return 0; | |||||
} |