Commit b7a982a8 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Sara Golemon

folly::Unit::Drop.

Summary: [Folly] folly::Unit::Drop.

Antisymmetric to folly::Unit::Lift.

Reviewed By: @fugalh

Differential Revision: D2211725
parent b8147234
......@@ -27,6 +27,9 @@ struct Unit {
template <class T> struct Lift : public std::false_type {
using type = T;
};
template <class T> struct Drop : public std::false_type {
using type = T;
};
bool operator==(const Unit& other) const { return true; }
bool operator!=(const Unit& other) const { return false; }
};
......@@ -43,6 +46,18 @@ struct Unit::Lift<Unit> : public std::true_type {
using type = Unit;
};
// Drop Unit into void.
template <>
struct Unit::Drop<Unit> : public std::true_type {
using type = void;
};
// Drop void into void (identity).
template <>
struct Unit::Drop<void> : public std::true_type {
using type = void;
};
template <class T>
struct is_void_or_unit : public Unit::Lift<T>
{};
......
......@@ -59,6 +59,24 @@ TEST(Unit, liftVoid) {
EXPECT_TRUE(v);
}
TEST(Unit, dropInt) {
using dropped = typename Unit::Drop<int>;
EXPECT_FALSE(dropped::value);
EXPECT_TRUE((std::is_same<int, dropped::type>::value));
}
TEST(Unit, dropUnit) {
using dropped = typename Unit::Drop<Unit>;
EXPECT_TRUE(dropped::value);
EXPECT_TRUE((std::is_void<dropped::type>::value));
}
TEST(Unit, dropVoid) {
using dropped = typename Unit::Drop<void>;
EXPECT_TRUE(dropped::value);
EXPECT_TRUE((std::is_void<dropped::type>::value));
}
TEST(Unit, futureToUnit) {
Future<Unit> fu = makeFuture(42).unit();
fu.value();
......
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