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 
23 template <class T>
24 struct A
25 {
26     typedef T value_type;
27     typedef short difference_type;
28 };
29 
30 template <class T>
31 struct B
32 {
33     typedef T value_type;
34 };
35 
36 template <class T>
37 struct 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 
46 namespace std
47 {
48 
49 template <>
50 struct pointer_traits<C<char>::pointer>
51 {
52     typedef signed char difference_type;
53 };
54 
55 }
56 
main()57 int 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