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; }
};
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>
{};
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();