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

is_transparent

Summary: [Folly] `is_transparent`, for testing whether a hash or equal-to type marks itself as transparent.

Reviewed By: shixiao

Differential Revision: D14355772

fbshipit-source-id: 9bb0ce6f7fc177e2445d094796ae4e56d9a00e76
parent 83cda3c8
......@@ -505,6 +505,21 @@ struct StrictDisjunction
: Negation<
std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>> {};
namespace detail {
template <typename, typename>
struct is_transparent_ : std::false_type {};
template <typename T>
struct is_transparent_<void_t<typename T::is_transparent>, T> : std::true_type {
};
} // namespace detail
// is_transparent
//
// To test whether a less, equal-to, or hash type follows the is-transparent
// protocol used by containers with optional heterogeneous access.
template <typename T>
struct is_transparent : detail::is_transparent_<void, T> {};
} // namespace folly
/**
......
......@@ -228,30 +228,17 @@ template <typename Arg, typename Default>
using Defaulted =
typename std::conditional_t<std::is_same<Arg, void>::value, Default, Arg>;
template <
typename TableKey,
typename Hasher,
typename KeyEqual,
typename ArgKey,
typename Void = void>
struct EligibleForHeterogeneousFind : std::false_type {};
template <
typename TableKey,
typename Hasher,
typename KeyEqual,
typename ArgKey>
struct EligibleForHeterogeneousFind<
TableKey,
Hasher,
KeyEqual,
ArgKey,
void_t<
typename Hasher::is_transparent,
typename KeyEqual::is_transparent,
invoke_result_t<Hasher, ArgKey const&>,
invoke_result_t<KeyEqual, ArgKey const&, TableKey const&>>>
: std::true_type {};
struct EligibleForHeterogeneousFind
: Conjunction<
is_transparent<Hasher>,
is_transparent<KeyEqual>,
is_invocable<Hasher, ArgKey const&>,
is_invocable<KeyEqual, ArgKey const&, TableKey const&>> {};
template <
typename TableKey,
......
......@@ -30,8 +30,8 @@ struct StringKeyedUnorderedMap
: public F14NodeMap<std::string, Mapped, Hash, Eq, Alloc> {
using Super = F14NodeMap<std::string, Mapped, Hash, Eq, Alloc>;
using require_transparent_hash = typename Hash::is_transparent;
using require_transparent_eq = typename Eq::is_transparent;
static_assert(is_transparent<Hash>::value, "not transparent");
static_assert(is_transparent<Eq>::value, "not transparent");
public:
using Super::Super;
......
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