]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / allocator.traits / allocator.traits.members / allocate_hint.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 // template <class Alloc>
13 // struct allocator_traits
14 // {
15 //     static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
16 //     ...
17 // };
18
19 #include <memory>
20 #include <cstdint>
21 #include <cassert>
22
23 #include "test_macros.h"
24
25 template <class T>
26 struct A
27 {
28     typedef T value_type;
29
30     value_type* allocate(std::size_t n)
31     {
32         assert(n == 10);
33         return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xDEADBEEF));
34     }
35 };
36
37 template <class T>
38 struct B
39 {
40     typedef T value_type;
41
42     value_type* allocate(std::size_t n)
43     {
44         assert(n == 12);
45         return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xEEADBEEF));
46     }
47     value_type* allocate(std::size_t n, const void* p)
48     {
49         assert(n == 11);
50         assert(p == 0);
51         return reinterpret_cast<value_type*>(static_cast<std::uintptr_t>(0xFEADBEEF));
52     }
53 };
54
55 int main()
56 {
57 #if TEST_STD_VER >= 11
58     A<int> a;
59     assert(std::allocator_traits<A<int> >::allocate(a, 10, nullptr) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xDEADBEEF)));
60 #endif
61     B<int> b;
62     assert(std::allocator_traits<B<int> >::allocate(b, 11, nullptr) == reinterpret_cast<int*>(static_cast<std::uintptr_t>(0xFEADBEEF)));
63 }