mirror of
https://github.com/clearlinux/folly.git
synced 2026-09-06 13:41:28 +00:00
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
This commit is contained in:
committed by
Praveen Kumar Ramakrishnan
parent
5b531cbb45
commit
0b46bcd5ec
+10
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user