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 // check nested types: 13 14 // template <class T> 15 // class allocator 16 // { 17 // public: 18 // typedef size_t size_type; 19 // typedef ptrdiff_t difference_type; 20 // typedef T* pointer; 21 // typedef const T* const_pointer; 22 // typedef typename add_lvalue_reference<T>::type reference; 23 // typedef typename add_lvalue_reference<const T>::type const_reference; 24 // typedef T value_type; 25 // 26 // template <class U> struct rebind {typedef allocator<U> other;}; 27 // ... 28 // }; 29 30 #include <memory> 31 #include <type_traits> 32 #include <cstddef> 33 34 int main() 35 { 36 static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), ""); 37 static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), ""); 38 static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), ""); 39 static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), ""); 40 static_assert((std::is_same<std::allocator<char>::value_type, char>::value), ""); 41 static_assert((std::is_same<std::allocator<char>::reference, char&>::value), ""); 42 static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), ""); 43 static_assert((std::is_same<std::allocator<char>::rebind<int>::other, 44 std::allocator<int> >::value), ""); 45 std::allocator<char> a; 46 std::allocator<char> a2 = a; 47 a2 = a; 48 std::allocator<int> a3 = a2; 49 } 50