size_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::size_type | size_t    size_type;
16//     ...
17// };
18
19#include <memory>
20#include <type_traits>
21
22template <class T>
23struct A
24{
25    typedef T value_type;
26    typedef unsigned short size_type;
27};
28
29template <class T>
30struct B
31{
32    typedef T value_type;
33};
34
35template <class T>
36struct 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
45namespace std
46{
47
48template <>
49struct pointer_traits<C<char>::pointer>
50{
51    typedef signed char difference_type;
52};
53
54}
55
56int main()
57{
58    static_assert((std::is_same<std::allocator_traits<A<char> >::size_type, unsigned short>::value), "");
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), "");
63}
64