Home | History | Annotate | Download | only in memory.polymorphic.allocator.mem
      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 // memory_resource *
     18 // polymorphic_allocator<T>::resource() const
     19 
     20 #include <experimental/memory_resource>
     21 #include <type_traits>
     22 #include <cassert>
     23 
     24 namespace ex = std::experimental::pmr;
     25 
     26 int main()
     27 {
     28     typedef ex::polymorphic_allocator<void> A;
     29     {
     30         A const a;
     31         static_assert(
     32             std::is_same<decltype(a.resource()), ex::memory_resource*>::value
     33           , ""
     34           );
     35     }
     36     {
     37         ex::memory_resource * mptr = (ex::memory_resource*)42;
     38         A const a(mptr);
     39         assert(a.resource() == mptr);
     40     }
     41     {
     42         A const a(nullptr);
     43         assert(a.resource() == nullptr);
     44         assert(a.resource() == nullptr);
     45     }
     46     {
     47         A const a;
     48         assert(a.resource() == ex::get_default_resource());
     49     }
     50     {
     51         ex::memory_resource * mptr = (ex::memory_resource*)42;
     52         ex::set_default_resource(mptr);
     53         A const a;
     54         assert(a.resource() == mptr);
     55         assert(a.resource() == ex::get_default_resource());
     56     }
     57 }
     58