int main() { typedef ex::polymorphic_allocator<void> A; { A const a; static_assert( std::is_same<decltype(a.resource()), ex::memory_resource*>::value , "" ); } { ex::memory_resource * mptr = (ex::memory_resource*)42; A const a(mptr); assert(a.resource() == mptr); } { A const a(nullptr); assert(a.resource() == nullptr); assert(a.resource() == nullptr); } { A const a; assert(a.resource() == ex::get_default_resource()); } { ex::memory_resource * mptr = (ex::memory_resource*)42; ex::set_default_resource(mptr); A const a; assert(a.resource() == mptr); assert(a.resource() == ex::get_default_resource()); } }
int main() { { static_assert( std::is_nothrow_default_constructible<ex::polymorphic_allocator<void>>::value , "Must me nothrow default constructible" ); } { // test that the allocator gets its resource from get_default_resource TestResource R1(42); ex::set_default_resource(&R1); typedef ex::polymorphic_allocator<void> A; A const a; assert(a.resource() == &R1); ex::set_default_resource(nullptr); A const a2; assert(a.resource() == &R1); assert(a2.resource() == ex::new_delete_resource()); } }
int main() { { typedef ex::polymorphic_allocator<void> A; static_assert( std::is_convertible<decltype(nullptr), A>::value , "Must be convertible" ); static_assert( std::is_convertible<ex::memory_resource *, A>::value , "Must be convertible" ); } { typedef ex::polymorphic_allocator<void> A; TestResource R; A const a(&R); assert(a.resource() == &R); } }