| 1 | // Copyright Louis Dionne 2013-2022 |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | #include <boost/hana/traits.hpp> |
| 6 | |
| 7 | #include <boost/hana/assert.hpp> |
| 8 | #include <boost/hana/integral_constant.hpp> |
| 9 | #include <boost/hana/type.hpp> |
| 10 | namespace hana = boost::hana; |
| 11 | |
| 12 | |
| 13 | enum Enumeration { }; |
| 14 | struct Structure { }; |
| 15 | constexpr auto e = hana::type_c<Enumeration>; |
| 16 | constexpr auto s = hana::type_c<Structure>; |
| 17 | |
| 18 | int main() { |
| 19 | // We just make sure that they compile. If the forwarding to `std::` is |
| 20 | // well done, it is the job of `std::` to return the right thing. |
| 21 | |
| 22 | /////////////////////// |
| 23 | // Type properties |
| 24 | /////////////////////// |
| 25 | // Primary type categories |
| 26 | static_assert(!hana::traits::is_void(s), "the traits should be compile-time checkable" ); |
| 27 | hana::traits::is_null_pointer(s); |
| 28 | hana::traits::is_integral(s); |
| 29 | hana::traits::is_floating_point(s); |
| 30 | hana::traits::is_array(s); |
| 31 | hana::traits::is_enum(s); |
| 32 | hana::traits::is_union(s); |
| 33 | hana::traits::is_class(s); |
| 34 | hana::traits::is_function(s); |
| 35 | hana::traits::is_pointer(s); |
| 36 | hana::traits::is_lvalue_reference(s); |
| 37 | hana::traits::is_rvalue_reference(s); |
| 38 | hana::traits::is_member_object_pointer(s); |
| 39 | hana::traits::is_member_function_pointer(s); |
| 40 | |
| 41 | // Composite type categories |
| 42 | hana::traits::is_fundamental(s); |
| 43 | hana::traits::is_arithmetic(s); |
| 44 | hana::traits::is_scalar(s); |
| 45 | hana::traits::is_object(s); |
| 46 | hana::traits::is_compound(s); |
| 47 | hana::traits::is_reference(s); |
| 48 | hana::traits::is_member_pointer(s); |
| 49 | |
| 50 | // Type properties |
| 51 | hana::traits::is_const(s); |
| 52 | hana::traits::is_volatile(s); |
| 53 | hana::traits::is_trivial(s); |
| 54 | hana::traits::is_trivially_copyable(s); |
| 55 | hana::traits::is_standard_layout(s); |
| 56 | #if __cplusplus < 202002L |
| 57 | hana::traits::is_pod(s); |
| 58 | #endif |
| 59 | #if __cplusplus < 201703L |
| 60 | hana::traits::is_literal_type(s); |
| 61 | #endif |
| 62 | hana::traits::is_empty(s); |
| 63 | hana::traits::is_polymorphic(s); |
| 64 | hana::traits::is_abstract(s); |
| 65 | hana::traits::is_signed(s); |
| 66 | hana::traits::is_unsigned(s); |
| 67 | |
| 68 | // Supported operations |
| 69 | hana::traits::is_constructible(s, s); |
| 70 | hana::traits::is_trivially_constructible(s, s); |
| 71 | hana::traits::is_nothrow_constructible(s, s); |
| 72 | |
| 73 | hana::traits::is_default_constructible(s); |
| 74 | hana::traits::is_trivially_default_constructible(s); |
| 75 | hana::traits::is_nothrow_default_constructible(s); |
| 76 | |
| 77 | hana::traits::is_copy_constructible(s); |
| 78 | hana::traits::is_trivially_copy_constructible(s); |
| 79 | hana::traits::is_nothrow_copy_constructible(s); |
| 80 | |
| 81 | hana::traits::is_move_constructible(s); |
| 82 | hana::traits::is_trivially_move_constructible(s); |
| 83 | hana::traits::is_nothrow_move_constructible(s); |
| 84 | |
| 85 | hana::traits::is_assignable(s, s); |
| 86 | hana::traits::is_trivially_assignable(s, s); |
| 87 | hana::traits::is_nothrow_assignable(s, s); |
| 88 | |
| 89 | hana::traits::is_copy_assignable(s); |
| 90 | hana::traits::is_trivially_copy_assignable(s); |
| 91 | hana::traits::is_nothrow_copy_assignable(s); |
| 92 | |
| 93 | hana::traits::is_move_assignable(s); |
| 94 | hana::traits::is_trivially_move_assignable(s); |
| 95 | hana::traits::is_nothrow_move_assignable(s); |
| 96 | |
| 97 | hana::traits::is_destructible(s); |
| 98 | hana::traits::is_trivially_destructible(s); |
| 99 | hana::traits::is_nothrow_destructible(s); |
| 100 | |
| 101 | hana::traits::has_virtual_destructor(s); |
| 102 | |
| 103 | // Property queries |
| 104 | hana::traits::alignment_of(s); |
| 105 | hana::traits::rank(s); |
| 106 | hana::traits::extent(s); |
| 107 | hana::traits::extent(hana::type_c<int[2][3]>, hana::uint_c<1>); |
| 108 | |
| 109 | // Type relationships |
| 110 | hana::traits::is_same(s, s); |
| 111 | hana::traits::is_base_of(s, s); |
| 112 | hana::traits::is_convertible(s, s); |
| 113 | |
| 114 | /////////////////////// |
| 115 | // Type modifications |
| 116 | /////////////////////// |
| 117 | // Const-volatility specifiers |
| 118 | hana::traits::remove_cv(s); |
| 119 | hana::traits::remove_const(s); |
| 120 | hana::traits::remove_volatile(s); |
| 121 | |
| 122 | hana::traits::add_cv(s); |
| 123 | hana::traits::add_const(s); |
| 124 | hana::traits::add_volatile(s); |
| 125 | |
| 126 | // References |
| 127 | hana::traits::remove_reference(s); |
| 128 | hana::traits::add_lvalue_reference(s); |
| 129 | hana::traits::add_rvalue_reference(s); |
| 130 | |
| 131 | // Pointers |
| 132 | hana::traits::remove_pointer(s); |
| 133 | hana::traits::add_pointer(s); |
| 134 | |
| 135 | // Sign modifiers |
| 136 | hana::traits::make_signed(hana::type_c<unsigned>); |
| 137 | hana::traits::make_unsigned(hana::type_c<signed>); |
| 138 | |
| 139 | // Arrays |
| 140 | hana::traits::remove_extent(s); |
| 141 | hana::traits::remove_all_extents(s); |
| 142 | |
| 143 | // Miscellaneous transformations |
| 144 | hana::traits::aligned_storage(hana::size_c<1>); |
| 145 | hana::traits::aligned_storage(hana::size_c<1>, hana::size_c<1>); |
| 146 | hana::traits::aligned_union(hana::size_c<0>, s); |
| 147 | hana::traits::decay(s); |
| 148 | |
| 149 | hana::traits::common_type(s, s); |
| 150 | hana::traits::underlying_type(e); |
| 151 | |
| 152 | /////////////////////// |
| 153 | // Utilities |
| 154 | /////////////////////// |
| 155 | using Z = decltype(hana::traits::declval(hana::type_c<Structure>)); |
| 156 | } |
| 157 | |