difference_type.pass.cpp revision 47761071be811e5815311294b71ad6ac9414963e
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// typedef Alloc::difference_type 16// | pointer_traits<pointer>::difference_type difference_type; 17// ... 18// }; 19 20#include <memory> 21#include <type_traits> 22 23template <class T> 24struct A 25{ 26 typedef T value_type; 27 typedef short difference_type; 28}; 29 30template <class T> 31struct B 32{ 33 typedef T value_type; 34}; 35 36template <class T> 37struct C 38{ 39 typedef T value_type; 40 struct pointer {}; 41 struct const_pointer {}; 42 struct void_pointer {}; 43 struct const_void_pointer {}; 44}; 45 46namespace std 47{ 48 49template <> 50struct pointer_traits<C<char>::pointer> 51{ 52 typedef signed char difference_type; 53}; 54 55} 56 57int main() 58{ 59 static_assert((std::is_same<std::allocator_traits<A<char> >::difference_type, short>::value), ""); 60 static_assert((std::is_same<std::allocator_traits<B<char> >::difference_type, std::ptrdiff_t>::value), ""); 61 static_assert((std::is_same<std::allocator_traits<C<char> >::difference_type, signed char>::value), ""); 62} 63