1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// REQUIRES: c++experimental 11// UNSUPPORTED: c++98, c++03 12 13// <experimental/memory_resource> 14 15// template <class T> class polymorphic_allocator 16 17// polymorphic_allocator 18// polymorphic_allocator<T>::select_on_container_copy_construction() const 19 20#include <experimental/memory_resource> 21#include <type_traits> 22#include <cassert> 23 24namespace ex = std::experimental::pmr; 25 26int main() 27{ 28 typedef ex::polymorphic_allocator<void> A; 29 { 30 A const a; 31 static_assert( 32 std::is_same<decltype(a.select_on_container_copy_construction()), A>::value, 33 ""); 34 } 35 { 36 ex::memory_resource * mptr = (ex::memory_resource*)42; 37 A const a(mptr); 38 assert(a.resource() == mptr); 39 A const other = a.select_on_container_copy_construction(); 40 assert(other.resource() == ex::get_default_resource()); 41 assert(a.resource() == mptr); 42 } 43 { 44 ex::memory_resource * mptr = (ex::memory_resource*)42; 45 ex::set_default_resource(mptr); 46 A const a(nullptr); 47 assert(a.resource() == nullptr); 48 A const other = a.select_on_container_copy_construction(); 49 assert(other.resource() == ex::get_default_resource()); 50 assert(other.resource() == mptr); 51 assert(a.resource() == nullptr); 52 } 53} 54