Commit 0b46bcd5 authored by Hans Fugal's avatar Hans Fugal Committed by Praveen Kumar Ramakrishnan

Unit::Lift<T>

Summary: Lift void into the unit monad and pass other types through unscathed.

Test Plan: new unit tests

Reviewed By: yfeldblum@fb.com

Subscribers: exa, folly-diffs@, jsedgwick, yfeldblum, chalfant

FB internal diff: D2029785

Signature: t1:2029785:1430333928:ef2fbb2e3d94518a732f6818a06c32481120bd4f
parent 5b531cbb
......@@ -16,7 +16,16 @@
#pragma once
namespace folly {
struct Unit {};
struct Unit {
template <class T> struct Lift : public std::false_type {
using type = T;
};
};
template <>
struct Unit::Lift<void> : public std::true_type {
using type = Unit;
};
template <class T>
struct is_void_or_unit : public std::conditional<
......
......@@ -33,3 +33,17 @@ TEST(Unit, PromiseSetValue) {
Promise<Unit> p;
p.setValue();
}
TEST(Unit, LiftInt) {
using Lifted = Unit::Lift<int>;
EXPECT_FALSE(Lifted::value);
auto v = std::is_same<int, Lifted::type>::value;
EXPECT_TRUE(v);
}
TEST(Unit, LiftVoid) {
using Lifted = Unit::Lift<void>;
EXPECT_TRUE(Lifted::value);
auto v = std::is_same<Unit, Lifted::type>::value;
EXPECT_TRUE(v);
}
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