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 int called = 0;
     24 
     25 template <class T>
     26 struct A
     27 {
     28     typedef T value_type;
     29 
     30     void deallocate(value_type* p, std::size_t n)
     31     {
     32         assert(p == reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xDEADBEEF)));
     33         assert(n == 10);
     34         ++called;
     35     }
     36 };
     37 
     38 int main()
     39 {
     40     A<int> a;
     41     std::allocator_traits<A<int> >::deallocate(a, reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF)), 10);
     42     assert(called == 1);
     43 }
     44