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 pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); 16 // ... 17 // }; 18 19 #include <memory> 20 #include <cassert> 21 22 template <class T> 23 struct A 24 { 25 typedef T value_type; 26 27 value_type* allocate(std::size_t n) 28 { 29 assert(n == 10); 30 return (value_type*)0xDEADBEEF; 31 } 32 }; 33 34 template <class T> 35 struct B 36 { 37 typedef T value_type; 38 39 value_type* allocate(std::size_t n) 40 { 41 assert(n == 12); 42 return (value_type*)0xEEADBEEF; 43 } 44 value_type* allocate(std::size_t n, const void* p) 45 { 46 assert(n == 11); 47 assert(p == 0); 48 return (value_type*)0xFEADBEEF; 49 } 50 }; 51 52 int main() 53 { 54 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE 55 A<int> a; 56 assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == (int*)0xDEADBEEF); 57 #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE 58 B<int> b; 59 assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == (int*)0xFEADBEEF); 60 } 61