| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <memory> |
| 10 | |
| 11 | // template <class T, class Alloc> struct uses_allocator; |
| 12 | |
| 13 | #include <memory> |
| 14 | #include <vector> |
| 15 | #include <type_traits> |
| 16 | |
| 17 | #include "test_macros.h" |
| 18 | |
| 19 | struct A |
| 20 | { |
| 21 | }; |
| 22 | |
| 23 | struct B |
| 24 | { |
| 25 | typedef int allocator_type; |
| 26 | }; |
| 27 | |
| 28 | struct C { |
| 29 | static int allocator_type; |
| 30 | }; |
| 31 | |
| 32 | struct D { |
| 33 | static int allocator_type() { return 0; } |
| 34 | }; |
| 35 | |
| 36 | struct E { |
| 37 | private: |
| 38 | typedef int allocator_type; |
| 39 | }; |
| 40 | |
| 41 | template <bool Expected, class T, class A> |
| 42 | void |
| 43 | test() |
| 44 | { |
| 45 | static_assert((std::uses_allocator<T, A>::value == Expected), "" ); |
| 46 | static_assert(std::is_base_of<std::integral_constant<bool, Expected>, std::uses_allocator<T, A> >::value, "" ); |
| 47 | #if TEST_STD_VER > 14 |
| 48 | ASSERT_SAME_TYPE(decltype(std::uses_allocator_v<T, A>), const bool); |
| 49 | static_assert((std::uses_allocator_v<T, A> == Expected), "" ); |
| 50 | #endif |
| 51 | } |
| 52 | |
| 53 | int main(int, char**) |
| 54 | { |
| 55 | test<false, int, std::allocator<int> >(); |
| 56 | test<true, std::vector<int>, std::allocator<int> >(); |
| 57 | test<false, A, std::allocator<int> >(); |
| 58 | test<false, B, std::allocator<int> >(); |
| 59 | test<true, B, double>(); |
| 60 | test<false, C, decltype(C::allocator_type)>(); |
| 61 | test<false, D, decltype(D::allocator_type)>(); |
| 62 | #if TEST_STD_VER >= 11 |
| 63 | test<false, E, int>(); |
| 64 | #endif |
| 65 | |
| 66 | |
| 67 | // static_assert((!std::uses_allocator<int, std::allocator<int> >::value), ""); |
| 68 | // static_assert(( std::uses_allocator<std::vector<int>, std::allocator<int> >::value), ""); |
| 69 | // static_assert((!std::uses_allocator<A, std::allocator<int> >::value), ""); |
| 70 | // static_assert((!std::uses_allocator<B, std::allocator<int> >::value), ""); |
| 71 | // static_assert(( std::uses_allocator<B, double>::value), ""); |
| 72 | // static_assert((!std::uses_allocator<C, decltype(C::allocator_type)>::value), ""); |
| 73 | // static_assert((!std::uses_allocator<D, decltype(D::allocator_type)>::value), ""); |
| 74 | // #if TEST_STD_VER >= 11 |
| 75 | // static_assert((!std::uses_allocator<E, int>::value), ""); |
| 76 | // #endif |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |