Skip to content

Commit 3ea2110

Browse files
committed
keep improving
1 parent 8796487 commit 3ea2110

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: include/boost/pfr/detail/fields_count.hpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ubiq_rref_constructor {
5858

5959
///////////////////// Hand-made is_complete<T> trait
6060
template <typename T, typename = void>
61-
struct is_complete : std::integral_constant<bool, false>
61+
struct is_complete : std::false_type
6262
{};
6363

6464
template <typename T>
@@ -101,7 +101,7 @@ struct is_aggregate_initializable_n {
101101
};
102102

103103
template <class T, std::size_t N>
104-
struct is_aggregate_initializable_n<T, N, typename std::enable_if<std::is_class<T>::value && !std::is_empty<T>::value>::type> {
104+
struct is_aggregate_initializable_n<T, N, std::enable_if_t<std::is_class<T>::value && !std::is_empty<T>::value>> {
105105
template <std::size_t ...I>
106106
static constexpr bool is_not_constructible_n(std::index_sequence<I...>) noexcept {
107107
return (!std::is_constructible<T, decltype(ubiq_lref_constructor{I})...>::value && !std::is_constructible<T, decltype(ubiq_rref_constructor{I})...>::value)
@@ -148,16 +148,16 @@ struct ubiq_rref_base_asserting {
148148
}
149149
};
150150

151-
template <class T, std::size_t I0, std::size_t... I, class /*Enable*/ = typename std::enable_if<std::is_copy_constructible<T>::value>::type>
151+
template <class T, std::size_t I0, std::size_t... I, class /*Enable*/ = std::enable_if_t<std::is_copy_constructible<T>::value>>
152152
constexpr auto assert_first_not_base(std::index_sequence<I0, I...>) noexcept
153-
-> typename std::add_pointer<decltype(T{ ubiq_lref_base_asserting<T>{}, ubiq_lref_constructor{I}... })>::type
153+
-> std::add_pointer_t<decltype(T{ ubiq_lref_base_asserting<T>{}, ubiq_lref_constructor{I}... })>
154154
{
155155
return nullptr;
156156
}
157157

158-
template <class T, std::size_t I0, std::size_t... I, class /*Enable*/ = typename std::enable_if<!std::is_copy_constructible<T>::value>::type>
158+
template <class T, std::size_t I0, std::size_t... I, class /*Enable*/ = std::enable_if_t<!std::is_copy_constructible<T>::value>>
159159
constexpr auto assert_first_not_base(std::index_sequence<I0, I...>) noexcept
160-
-> typename std::add_pointer<decltype(T{ ubiq_rref_base_asserting<T>{}, ubiq_rref_constructor{I}... })>::type
160+
-> std::add_pointer_t<decltype(T{ ubiq_rref_base_asserting<T>{}, ubiq_rref_constructor{I}... })>
161161
{
162162
return nullptr;
163163
}
@@ -173,20 +173,20 @@ constexpr void assert_first_not_base(int) noexcept {}
173173

174174
template <class T, std::size_t N>
175175
constexpr auto assert_first_not_base(long) noexcept
176-
-> typename std::enable_if<std::is_class<T>::value>::type
176+
-> std::enable_if_t<std::is_class<T>::value>
177177
{
178178
detail::assert_first_not_base<T>(detail::make_index_sequence<N>{});
179179
}
180180

181181
///////////////////// Helpers for initializable detection
182182
// Note that these take O(N) compile time and memory!
183-
template <class T, std::size_t... I, class /*Enable*/ = typename std::enable_if<std::is_copy_constructible<T>::value>::type>
183+
template <class T, std::size_t... I, class /*Enable*/ = std::enable_if_t<std::is_copy_constructible<T>::value>>
184184
constexpr auto enable_if_initializable_helper(std::index_sequence<I...>) noexcept
185-
-> typename std::add_pointer<decltype(T{ubiq_lref_constructor{I}...})>::type;
185+
-> std::add_pointer_t<decltype(T{ubiq_lref_constructor{I}...})>;
186186

187-
template <class T, std::size_t... I, class /*Enable*/ = typename std::enable_if<!std::is_copy_constructible<T>::value>::type>
187+
template <class T, std::size_t... I, class /*Enable*/ = std::enable_if_t<!std::is_copy_constructible<T>::value>>
188188
constexpr auto enable_if_initializable_helper(std::index_sequence<I...>) noexcept
189-
-> typename std::add_pointer<decltype(T{ubiq_rref_constructor{I}...})>::type;
189+
-> std::add_pointer_t<decltype(T{ubiq_rref_constructor{I}...})>;
190190

191191
template <class T, std::size_t N, class U = std::size_t, class /*Enable*/ = decltype(detail::enable_if_initializable_helper<T>(detail::make_index_sequence<N>()))>
192192
using enable_if_initializable_helper_t = U;
@@ -311,8 +311,8 @@ constexpr std::size_t fields_count_lower_bound_unbounded(int, size_t_<Result>) n
311311
return Result;
312312
}
313313

314-
template <class T, std::size_t Begin, std::size_t Result>
315-
constexpr auto fields_count_lower_bound_unbounded(long, size_t_<Result>) noexcept
314+
template <class T, std::size_t Begin>
315+
constexpr auto fields_count_lower_bound_unbounded(long, size_t_<0>) noexcept
316316
-> std::enable_if_t<(Begin >= detail::fields_count_upper_bound_loose<T>()), std::size_t>
317317
{
318318
static_assert(
@@ -332,29 +332,29 @@ constexpr std::size_t fields_count_lower_bound_unbounded(int, size_t_<0>) noexce
332332

333333
///////////////////// Choosing between array size, unbounded binary search, and linear search followed by unbounded binary search.
334334
template <class T>
335-
constexpr auto fields_count_dispatch(long, long, std::integral_constant<bool, false> /*are_preconditions_met*/) noexcept {
335+
constexpr auto fields_count_dispatch(long, long, std::false_type /*are_preconditions_met*/) noexcept {
336336
return 0;
337337
}
338338

339339
template <class T>
340-
constexpr auto fields_count_dispatch(long, long, std::integral_constant<bool, true> /*are_preconditions_met*/) noexcept
341-
-> typename std::enable_if<std::is_array<T>::value, std::size_t>::type
340+
constexpr auto fields_count_dispatch(long, long, std::true_type /*are_preconditions_met*/) noexcept
341+
-> std::enable_if_t<std::is_array<T>::value, std::size_t>
342342
{
343-
return sizeof(T) / sizeof(typename std::remove_all_extents<T>::type);
343+
return sizeof(T) / sizeof(std::remove_all_extents_t<T>);
344344
}
345345

346346
template <class T>
347-
constexpr auto fields_count_dispatch(long, int, std::integral_constant<bool, true> /*are_preconditions_met*/) noexcept
347+
constexpr auto fields_count_dispatch(long, int, std::true_type /*are_preconditions_met*/) noexcept
348348
-> decltype(sizeof(T{}))
349349
{
350350
constexpr std::size_t typical_fields_count = 4;
351-
constexpr std::size_t last = detail::fields_count_upper_bound<T, typical_fields_count, typical_fields_count * 2>(1L, 1L);
351+
constexpr std::size_t last = detail::fields_count_upper_bound<T, typical_fields_count / 2, typical_fields_count>(1L, 1L);
352352
constexpr std::size_t middle = (last + 1) / 2;
353353
return detail::fields_count_binary_search<T, 0, middle>(detail::is_one_element_range<0, middle>{}, 1L);
354354
}
355355

356356
template <class T>
357-
constexpr std::size_t fields_count_dispatch(int, int, std::integral_constant<bool, true> /*are_preconditions_met*/) noexcept {
357+
constexpr std::size_t fields_count_dispatch(int, int, std::true_type /*are_preconditions_met*/) noexcept {
358358
// T is not default aggregate initializable. This means that at least one of the members is not default-constructible.
359359
// Use linear search to find the smallest valid initializer, after which we unbounded binary search for the largest.
360360
constexpr std::size_t begin = detail::fields_count_lower_bound_unbounded<T, 1>(1L, size_t_<0>{});

0 commit comments

Comments
 (0)