Commit 1804caee authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Style tweaks to max_align_v calculation

Summary:
[Folly] Style tweaks to `max_align_v` calculation.

* Change ns from `folly::detail` since that can be crowded and many other folly libraries may include this header.
* Extract a 2-param `max` alias.
* Fix an incorrectly hardcoded `size_t`.

Reviewed By: WillerZ

Differential Revision: D5468758

fbshipit-source-id: 14a3f67323020a3cfce2b3b46f5f64f3e6125027
parent efce8553
...@@ -33,21 +33,20 @@ constexpr bool kHasUnalignedAccess = true; ...@@ -33,21 +33,20 @@ constexpr bool kHasUnalignedAccess = true;
constexpr bool kHasUnalignedAccess = false; constexpr bool kHasUnalignedAccess = false;
#endif #endif
namespace detail { namespace portability_detail {
template <typename I, I A, I B>
using integral_max = std::integral_constant<I, (A < B) ? B : A>;
template <typename I, I A, I... Bs> template <typename I, I A, I... Bs>
struct integral_max struct integral_sequence_max
: std::integral_constant< : integral_max<I, A, integral_sequence_max<I, Bs...>::value> {};
I,
(A > integral_max<I, Bs...>::value) ? A
: integral_max<I, Bs...>::value> {
};
template <typename I, size_t A> template <typename I, I A>
struct integral_max<I, A> : std::integral_constant<I, A> {}; struct integral_sequence_max<I, A> : std::integral_constant<I, A> {};
template <typename... Ts> template <typename... Ts>
using max_alignment = integral_max<size_t, alignof(Ts)...>; using max_alignment = integral_sequence_max<size_t, alignof(Ts)...>;
using max_basic_alignment = max_alignment< using max_basic_alignment = max_alignment<
std::max_align_t, std::max_align_t,
...@@ -66,7 +65,7 @@ using max_basic_alignment = max_alignment< ...@@ -66,7 +65,7 @@ using max_basic_alignment = max_alignment<
std::nullptr_t>; std::nullptr_t>;
} // namespace detail } // namespace detail
constexpr size_t max_align_v = detail::max_basic_alignment::value; constexpr size_t max_align_v = portability_detail::max_basic_alignment::value;
// max_align_t is a type which is aligned at least as strictly as the // max_align_t is a type which is aligned at least as strictly as the
// most-aligned basic type (see the specification of std::max_align_t). This // most-aligned basic type (see the specification of std::max_align_t). This
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment