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 // template <class U>
     18 // void polymorphic_allocator<T>::destroy(U * ptr);
     19 
     20 #include <experimental/memory_resource>
     21 #include <type_traits>
     22 #include <new>
     23 #include <cassert>
     24 #include <cstdlib>
     25 
     26 namespace ex = std::experimental::pmr;
     27 
     28 int count = 0;
     29 
     30 struct destroyable
     31 {
     32     destroyable() { ++count; }
     33     ~destroyable() { --count; }
     34 };
     35 
     36 int main()
     37 {
     38     typedef ex::polymorphic_allocator<double> A;
     39     {
     40         A a;
     41         static_assert(
     42             std::is_same<decltype(a.destroy((destroyable*)nullptr)), void>::value,
     43             "");
     44     }
     45     {
     46         destroyable * ptr = ::new (std::malloc(sizeof(destroyable))) destroyable();
     47         assert(count == 1);
     48         A{}.destroy(ptr);
     49         assert(count == 0);
     50         std::free(ptr);
     51     }
     52 }
     53