Commit c5adaa59 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Revise is_transparent_v and is_transparent

Summary: [Folly] Revise `is_transparent_v` as a variable and as eager, and atop `is_detected`, and `is_transparent` as a type and as deferred.

Reviewed By: Mizuchi

Differential Revision: D23367991

fbshipit-source-id: be30184b04e2a1977db3faccd57e947dd33282ce
parent 92a2a9b3
...@@ -599,19 +599,21 @@ struct StrictDisjunction ...@@ -599,19 +599,21 @@ struct StrictDisjunction
std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>> {}; std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>> {};
namespace detail { namespace detail {
template <typename, typename>
struct is_transparent_ : std::false_type {};
template <typename T> template <typename T>
struct is_transparent_<void_t<typename T::is_transparent>, T> : std::true_type { using is_transparent_ = typename T::is_transparent;
};
} // namespace detail } // namespace detail
// is_transparent_v
// is_transparent // is_transparent
// //
// To test whether a less, equal-to, or hash type follows the is-transparent // A trait variable and type to test whether a less, equal-to, or hash type
// protocol used by containers with optional heterogeneous access. // follows the is-transparent protocol used by containers with optional
// heterogeneous access.
template <typename T>
FOLLY_INLINE_VARIABLE constexpr bool is_transparent_v =
is_detected_v<detail::is_transparent_, T>;
template <typename T> template <typename T>
struct is_transparent : detail::is_transparent_<void, T> {}; struct is_transparent : bool_constant<is_transparent_v<T>> {};
} // namespace folly } // namespace folly
......
...@@ -34,22 +34,16 @@ using namespace folly; ...@@ -34,22 +34,16 @@ using namespace folly;
namespace { namespace {
template <typename T, typename Enable = void>
struct IsTransparent : std::false_type {};
template <typename T>
struct IsTransparent<T, void_t<typename T::is_transparent>> : std::true_type {};
template <typename T> template <typename T>
void checkTransparent() { void checkTransparent() {
static_assert(IsTransparent<HeterogeneousAccessEqualTo<T>>::value, ""); static_assert(is_transparent_v<HeterogeneousAccessEqualTo<T>>, "");
static_assert(IsTransparent<HeterogeneousAccessHash<T>>::value, ""); static_assert(is_transparent_v<HeterogeneousAccessHash<T>>, "");
} }
template <typename T> template <typename T>
void checkNotTransparent() { void checkNotTransparent() {
static_assert(!IsTransparent<HeterogeneousAccessEqualTo<T>>::value, ""); static_assert(!is_transparent_v<HeterogeneousAccessEqualTo<T>>, "");
static_assert(!IsTransparent<HeterogeneousAccessHash<T>>::value, ""); static_assert(!is_transparent_v<HeterogeneousAccessHash<T>>, "");
} }
struct StringVector { struct StringVector {
......
...@@ -30,8 +30,8 @@ struct StringKeyedUnorderedMap ...@@ -30,8 +30,8 @@ struct StringKeyedUnorderedMap
: public F14NodeMap<std::string, Mapped, Hash, Eq, Alloc> { : public F14NodeMap<std::string, Mapped, Hash, Eq, Alloc> {
using Super = F14NodeMap<std::string, Mapped, Hash, Eq, Alloc>; using Super = F14NodeMap<std::string, Mapped, Hash, Eq, Alloc>;
static_assert(is_transparent<Hash>::value, "not transparent"); static_assert(is_transparent_v<Hash>, "not transparent");
static_assert(is_transparent<Eq>::value, "not transparent"); static_assert(is_transparent_v<Eq>, "not transparent");
public: public:
using Super::Super; 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