]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/default.allocator/allocator_types.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / default.allocator / allocator_types.pass.cpp
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 //     typedef true_type                             is_always_equal;
26 //
27 //     template <class U> struct rebind {typedef allocator<U> other;};
28 // ...
29 // };
30
31 #include <memory>
32 #include <type_traits>
33 #include <cstddef>
34
35 #include "test_macros.h"
36
37 int main()
38 {
39     static_assert((std::is_same<std::allocator<char>::size_type, std::size_t>::value), "");
40     static_assert((std::is_same<std::allocator<char>::difference_type, std::ptrdiff_t>::value), "");
41     static_assert((std::is_same<std::allocator<char>::pointer, char*>::value), "");
42     static_assert((std::is_same<std::allocator<char>::const_pointer, const char*>::value), "");
43     static_assert((std::is_same<std::allocator<char>::value_type, char>::value), "");
44     static_assert((std::is_same<std::allocator<char>::reference, char&>::value), "");
45     static_assert((std::is_same<std::allocator<char>::const_reference, const char&>::value), "");
46     static_assert((std::is_same<std::allocator<char>::rebind<int>::other,
47                                 std::allocator<int> >::value), "");
48
49     static_assert((std::is_same<std::allocator<      char>::is_always_equal, std::true_type>::value), "");
50     LIBCPP_STATIC_ASSERT((std::is_same<std::allocator<const char>::is_always_equal, std::true_type>::value), "");
51
52     std::allocator<char> a;
53     std::allocator<char> a2 = a;
54     a2 = a;
55     std::allocator<int> a3 = a2;
56     ((void)a3);
57 }