Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <memory> |
| 11 | |
| 12 | // template <class Alloc> |
| 13 | // struct allocator_traits |
| 14 | // { |
| 15 | // typedef Alloc::size_type | size_t size_type; |
| 16 | // ... |
| 17 | // }; |
| 18 | |
| 19 | #include <memory> |
| 20 | #include <type_traits> |
| 21 | |
| 22 | template <class T> |
| 23 | struct A |
| 24 | { |
| 25 | typedef T value_type; |
| 26 | typedef unsigned short size_type; |
| 27 | }; |
| 28 | |
| 29 | template <class T> |
| 30 | struct B |
| 31 | { |
| 32 | typedef T value_type; |
| 33 | }; |
| 34 | |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 35 | template <class T> |
| 36 | struct C |
| 37 | { |
| 38 | typedef T value_type; |
| 39 | struct pointer {}; |
| 40 | struct const_pointer {}; |
| 41 | struct void_pointer {}; |
| 42 | struct const_void_pointer {}; |
| 43 | }; |
| 44 | |
| 45 | namespace std |
| 46 | { |
| 47 | |
| 48 | template <> |
| 49 | struct pointer_traits<C<char>::pointer> |
| 50 | { |
| 51 | typedef signed char difference_type; |
| 52 | }; |
| 53 | |
| 54 | } |
| 55 | |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 56 | int main() |
| 57 | { |
| 58 | static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), ""); |
Howard Hinnant | 4776107 | 2010-11-18 01:40:00 +0000 | [diff] [blame] | 59 | static_assert((std::is_same<std::allocator_traits<B<char> >::size_type, |
| 60 | std::make_unsigned<std::ptrdiff_t>::type>::value), ""); |
| 61 | static_assert((std::is_same<std::allocator_traits<C<char> >::size_type, |
| 62 | unsigned char>::value), ""); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 63 | } |