Home | History | Annotate | Download | only in allocator.traits.members
      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 // <memory>
     11 
     12 // template <class Alloc>
     13 // struct allocator_traits
     14 // {
     15 //     static void deallocate(allocator_type& a, pointer p, size_type n);
     16 //     ...
     17 // };
     18 
     19 #include <memory>
     20 #include <cstdint>
     21 #include <cassert>
     22 
     23 #include "incomplete_type_helper.h"
     24 
     25 int called = 0;
     26 
     27 template <class T>
     28 struct A
     29 {
     30     typedef T value_type;
     31 
     32     void deallocate(value_type* p, std::size_t n)
     33     {
     34         assert(p == reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xDEADBEEF)));
     35         assert(n == 10);
     36         ++called;
     37     }
     38 };
     39 
     40 int main()
     41 {
     42   {
     43     A<int> a;
     44     std::allocator_traits<A<int> >::deallocate(a, reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF)), 10);
     45     assert(called == 1);
     46   }
     47   called = 0;
     48   {
     49     typedef IncompleteHolder* VT;
     50     typedef A<VT> Alloc;
     51     Alloc a;
     52     std::allocator_traits<Alloc >::deallocate(a, reinterpret_cast<VT*>(static_cast<std::uintptr_t>(0xDEADBEEF)), 10);
     53     assert(called == 1);
     54   }
     55 }
     56