]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp
Vendor import of libc++ release_39 branch r276489:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / allocator.traits / allocator.traits.members / max_size.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 size_type max_size(const allocator_type& a) noexcept;
16 //     ...
17 // };
18
19 #include <memory>
20 #include <new>
21 #include <type_traits>
22 #include <cassert>
23
24 #include "test_macros.h"
25
26 template <class T>
27 struct A
28 {
29     typedef T value_type;
30
31 };
32
33 template <class T>
34 struct B
35 {
36     typedef T value_type;
37
38     size_t max_size() const
39     {
40         return 100;
41     }
42 };
43
44 int main()
45 {
46 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
47     {
48         A<int> a;
49         assert(std::allocator_traits<A<int> >::max_size(a) ==
50                std::numeric_limits<std::size_t>::max() / sizeof(int));
51     }
52     {
53         const A<int> a = {};
54         assert(std::allocator_traits<A<int> >::max_size(a) ==
55                std::numeric_limits<std::size_t>::max() / sizeof(int));
56     }
57 #endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
58     {
59         B<int> b;
60         assert(std::allocator_traits<B<int> >::max_size(b) == 100);
61     }
62     {
63         const B<int> b = {};
64         assert(std::allocator_traits<B<int> >::max_size(b) == 100);
65     }
66 #if TEST_STD_VER >= 11
67     {
68         std::allocator<int> a;
69         static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, "");
70     }
71 #endif
72 }