Skip to content

Commit

Permalink
make use of require_sizeof
Browse files Browse the repository at this point in the history
Reviewed By: DenisYaroshevskiy

Differential Revision: D52712101

fbshipit-source-id: bde1583b60cb6481ce80bed5d6470c0edaf79d76
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jan 16, 2024
1 parent 1ce47f5 commit 6222a1d
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
19 changes: 10 additions & 9 deletions folly/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ struct is_constexpr_default_constructible_ {
static std::true_type sfinae(T*);
static std::false_type sfinae(void*);
template <typename T>
static constexpr bool apply = sizeof(T) &&
decltype(sfinae(static_cast<T*>(nullptr)))::value;
static constexpr bool apply =
!require_sizeof<T> || decltype(sfinae(static_cast<T*>(nullptr)))::value;
};

} // namespace detail
Expand Down Expand Up @@ -405,7 +405,7 @@ struct detected_<void_t<T<A...>>, D, T, A...> {
//
// mimic: std::experimental::detected_or, Library Fundamentals TS v2
//
// Note: not resilient agaist incomplete types; may violate ODR.
// Note: not resilient against incomplete types; may violate ODR.
template <typename D, template <typename...> class T, typename... A>
using detected_or = detail::detected_<void, D, T, A...>;

Expand All @@ -418,7 +418,7 @@ using detected_or = detail::detected_<void, D, T, A...>;
//
// mimic: std::experimental::detected_or_t, Library Fundamentals TS v2
//
// Note: not resilient agaist incomplete types; may violate ODR.
// Note: not resilient against incomplete types; may violate ODR.
template <typename D, template <typename...> class T, typename... A>
using detected_or_t = typename detected_or<D, T, A...>::type;

Expand All @@ -431,7 +431,7 @@ using detected_or_t = typename detected_or<D, T, A...>::type;
//
// mimic: std::experimental::detected_t, Library Fundamentals TS v2
//
// Note: not resilient agaist incomplete types; may violate ODR.
// Note: not resilient against incomplete types; may violate ODR.
template <template <typename...> class T, typename... A>
using detected_t = detected_or_t<nonesuch, T, A...>;

Expand All @@ -449,7 +449,7 @@ using detected_t = detected_or_t<nonesuch, T, A...>;
// mimic: std::experimental::is_detected, std::experimental::is_detected_v,
// Library Fundamentals TS v2
//
// Note: not resilient agaist incomplete types; may violate ODR.
// Note: not resilient against incomplete types; may violate ODR.
//
// Note: the trait type is_detected differs here by being deferred.
template <template <typename...> class T, typename... A>
Expand Down Expand Up @@ -635,7 +635,8 @@ struct IsNothrowSwappable
template <class T>
struct IsRelocatable
: std::conditional<
sizeof(T) && is_detected_v<traits_detail::detect_IsRelocatable, T>,
!require_sizeof<T> ||
is_detected_v<traits_detail::detect_IsRelocatable, T>,
traits_detail::has_true_IsRelocatable<T>,
// TODO add this line (and some tests for it) when we
// upgrade to gcc 4.7
Expand All @@ -645,7 +646,7 @@ struct IsRelocatable
template <class T>
struct IsZeroInitializable
: std::conditional<
sizeof(T) &&
!require_sizeof<T> ||
is_detected_v<traits_detail::detect_IsZeroInitializable, T>,
traits_detail::has_true_IsZeroInitializable<T>,
bool_constant< //
Expand Down Expand Up @@ -734,7 +735,7 @@ struct is_transparent : bool_constant<is_transparent_v<T>> {};
namespace detail {

template <typename T, typename = void>
FOLLY_INLINE_VARIABLE constexpr bool is_allocator_ = !sizeof(T);
FOLLY_INLINE_VARIABLE constexpr bool is_allocator_ = !require_sizeof<T>;
template <typename T>
FOLLY_INLINE_VARIABLE constexpr bool is_allocator_<
T,
Expand Down
6 changes: 3 additions & 3 deletions folly/container/Foreach-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ template <typename T>
using EnableIfMemberGetFound =
void_t<decltype(std::declval<T>().template get<0>())>;
template <typename, typename T>
struct IsMemberGetFound : bool_constant<!sizeof(T)> {};
struct IsMemberGetFound : bool_constant<!require_sizeof<T>> {};
template <typename T>
struct IsMemberGetFound<EnableIfMemberGetFound<T>, T> : std::true_type {};

Expand Down Expand Up @@ -91,7 +91,7 @@ using EnableIfTuple = void_t<
decltype(get_impl<0>(std::declval<T>())),
decltype(std::tuple_size<T>::value)>;
template <typename, typename T>
struct IsTuple : bool_constant<!sizeof(T)> {};
struct IsTuple : bool_constant<!require_sizeof<T>> {};
template <typename T>
struct IsTuple<EnableIfTuple<T>, T> : std::true_type {};

Expand All @@ -103,7 +103,7 @@ using EnableIfRange = void_t<
decltype(access::begin(std::declval<T&>())),
decltype(access::end(std::declval<T&>()))>;
template <typename, typename T>
struct IsRange : bool_constant<!sizeof(T)> {};
struct IsRange : bool_constant<!require_sizeof<T>> {};
template <typename T>
struct IsRange<EnableIfRange<T>, T> : std::true_type {};

Expand Down
4 changes: 2 additions & 2 deletions folly/container/Iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace folly {
// the distance without advancing the iterators or copies of them.
template <typename Iter, typename SentinelIter>
FOLLY_INLINE_VARIABLE constexpr bool iterator_has_known_distance_v =
!sizeof(Iter) && !sizeof(SentinelIter);
!require_sizeof<Iter> || !require_sizeof<SentinelIter>;
template <typename Iter>
FOLLY_INLINE_VARIABLE constexpr bool iterator_has_known_distance_v<Iter, Iter> =
std::is_base_of<
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace detail {

template <typename Iter, typename Category, typename = void>
FOLLY_INLINE_VARIABLE constexpr bool iterator_category_matches_v_ =
!sizeof(Iter) && !sizeof(Category);
!require_sizeof<Iter> || !require_sizeof<Category>;
template <typename Iter, typename Category>
FOLLY_INLINE_VARIABLE constexpr bool iterator_category_matches_v_<
Iter,
Expand Down
2 changes: 1 addition & 1 deletion folly/container/detail/F14Policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct FOLLY_MSVC_DECLSPEC(empty_bases) BasePolicy
// Detection for folly_assume_32bit_hash

template <typename Hasher, typename Void = void>
struct ShouldAssume32BitHash : bool_constant<!sizeof(Hasher)> {};
struct ShouldAssume32BitHash : bool_constant<!require_sizeof<Hasher>> {};

template <typename Hasher>
struct ShouldAssume32BitHash<
Expand Down
2 changes: 1 addition & 1 deletion folly/container/detail/F14Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct StdNodeReplica {
#else

template <typename H>
struct StdIsFastHash : bool_constant<!!sizeof(H)> {};
struct StdIsFastHash : std::true_type {};
template <>
struct StdIsFastHash<std::hash<long double>> : std::false_type {};
template <typename... Args>
Expand Down
2 changes: 1 addition & 1 deletion folly/detail/PolyDetail.h
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ struct ModelsInterfaceFalse0_;
template <>
struct ModelsInterfaceFalse0_<false> {
template <typename... T>
using apply = bool_constant<(!sizeof(T) || ...)>;
using apply = bool_constant<(!require_sizeof<T> || ...)>;
};
template <>
struct ModelsInterfaceFalse0_<true> {
Expand Down
10 changes: 6 additions & 4 deletions folly/experimental/coro/Traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ inline constexpr bool is_coroutine_handle_v =
/// implementations have particular requirements on the promise (eg. the
/// stack-aware awaiters may require the .getAsyncFrame() method)
template <typename T, typename = void>
struct is_awaiter : bool_constant<!sizeof(T)> {};
struct is_awaiter : bool_constant<!require_sizeof<T>> {};

template <typename T>
struct is_awaiter<T, std::enable_if_t<std::is_void_v<T>>> : std::false_type {};
Expand All @@ -88,7 +88,8 @@ constexpr bool is_awaiter_v = is_awaiter<T>::value;
namespace detail {

template <typename Awaitable, typename = void>
struct _has_member_operator_co_await : bool_constant<!sizeof(Awaitable)> {};
struct _has_member_operator_co_await
: bool_constant<!require_sizeof<Awaitable>> {};

template <typename T>
struct _has_member_operator_co_await<T, std::enable_if_t<std::is_void_v<T>>>
Expand All @@ -101,7 +102,8 @@ struct _has_member_operator_co_await<
: is_awaiter<decltype(std::declval<Awaitable>().operator co_await())> {};

template <typename Awaitable, typename = void>
struct _has_free_operator_co_await : bool_constant<!sizeof(Awaitable)> {};
struct _has_free_operator_co_await : bool_constant<!require_sizeof<Awaitable>> {
};

template <typename T>
struct _has_free_operator_co_await<T, std::enable_if_t<std::is_void_v<T>>>
Expand Down Expand Up @@ -211,7 +213,7 @@ using await_result_t = typename await_result<Awaitable>::type;
namespace detail {

template <typename Promise, typename = void>
constexpr bool promiseHasAsyncFrame_v = !sizeof(Promise);
constexpr bool promiseHasAsyncFrame_v = !require_sizeof<Promise>;

template <typename Promise>
constexpr bool promiseHasAsyncFrame_v<
Expand Down
4 changes: 2 additions & 2 deletions folly/experimental/coro/ViaIfAsync.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class ViaIfAsyncAwaitable {
namespace detail {

template <typename SemiAwaitable, typename = void>
struct HasViaIfAsyncMethod : bool_constant<!sizeof(SemiAwaitable)> {};
struct HasViaIfAsyncMethod : bool_constant<!require_sizeof<SemiAwaitable>> {};

template <typename SemiAwaitable>
struct HasViaIfAsyncMethod<
Expand Down Expand Up @@ -501,7 +501,7 @@ struct ViaIfAsyncFunction {
FOLLY_DEFINE_CPO(detail::adl::ViaIfAsyncFunction, co_viaIfAsync)

template <typename T, typename = void>
struct is_semi_awaitable : bool_constant<!sizeof(T)> {};
struct is_semi_awaitable : bool_constant<!require_sizeof<T>> {};

template <typename T>
struct is_semi_awaitable<T, std::enable_if_t<std::is_void_v<T>>>
Expand Down
2 changes: 1 addition & 1 deletion folly/functional/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct match_empty_function_protocol_fn {

template <typename T>
static constexpr bool cx_matches_v =
sizeof(T) && is_detected_v<detect_from_eq_nullptr, T>;
require_sizeof<T>&& is_detected_v<detect_from_eq_nullptr, T>;

public:
template <typename T, std::enable_if_t<!cx_matches_v<T>, int> = 0>
Expand Down
3 changes: 2 additions & 1 deletion folly/hash/Hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ struct IsAvalanchingHasher;

namespace detail {
template <typename Hasher, typename Void = void>
struct IsAvalanchingHasherFromMemberType : bool_constant<!sizeof(Hasher)> {};
struct IsAvalanchingHasherFromMemberType
: bool_constant<!require_sizeof<Hasher>> {};

template <typename Hasher>
struct IsAvalanchingHasherFromMemberType<
Expand Down

0 comments on commit 6222a1d

Please sign in to comment.