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 | // { |
Marshall Clow | 08b4f3f | 2013-08-27 20:22:15 +0000 | [diff] [blame] | 15 | // static size_type max_size(const allocator_type& a) noexcept; |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 16 | // ... |
| 17 | // }; |
| 18 | |
| 19 | #include <memory> |
| 20 | #include <new> |
| 21 | #include <type_traits> |
| 22 | #include <cassert> |
| 23 | |
| 24 | template <class T> |
| 25 | struct A |
| 26 | { |
| 27 | typedef T value_type; |
| 28 | |
| 29 | }; |
| 30 | |
| 31 | template <class T> |
| 32 | struct B |
| 33 | { |
| 34 | typedef T value_type; |
| 35 | |
| 36 | size_t max_size() const |
| 37 | { |
| 38 | return 100; |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | int main() |
| 43 | { |
| 44 | #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 45 | { |
| 46 | A<int> a; |
| 47 | assert(std::allocator_traits<A<int> >::max_size(a) == |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 48 | std::numeric_limits<std::size_t>::max()); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 49 | } |
| 50 | { |
| 51 | const A<int> a = {}; |
| 52 | assert(std::allocator_traits<A<int> >::max_size(a) == |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 53 | std::numeric_limits<std::size_t>::max()); |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 54 | } |
| 55 | #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE |
| 56 | { |
| 57 | B<int> b; |
| 58 | assert(std::allocator_traits<B<int> >::max_size(b) == 100); |
| 59 | } |
| 60 | { |
| 61 | const B<int> b = {}; |
| 62 | assert(std::allocator_traits<B<int> >::max_size(b) == 100); |
| 63 | } |
Marshall Clow | 08b4f3f | 2013-08-27 20:22:15 +0000 | [diff] [blame] | 64 | #if __cplusplus >= 201103 |
| 65 | { |
| 66 | std::allocator<int> a; |
| 67 | static_assert(noexcept(std::allocator_traits<std::allocator<int>>::max_size(a)) == true, ""); |
| 68 | } |
| 69 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 70 | } |