diff --git a/folly/futures/Unit.h b/folly/futures/Unit.h index cb0b92c..a03d520 100644 --- a/folly/futures/Unit.h +++ b/folly/futures/Unit.h @@ -16,7 +16,16 @@ #pragma once namespace folly { -struct Unit {}; +struct Unit { + template struct Lift : public std::false_type { + using type = T; + }; +}; + +template <> +struct Unit::Lift : public std::true_type { + using type = Unit; +}; template struct is_void_or_unit : public std::conditional< diff --git a/folly/futures/test/UnitTest.cpp b/folly/futures/test/UnitTest.cpp index 0305739..930b123 100644 --- a/folly/futures/test/UnitTest.cpp +++ b/folly/futures/test/UnitTest.cpp @@ -33,3 +33,17 @@ TEST(Unit, PromiseSetValue) { Promise p; p.setValue(); } + +TEST(Unit, LiftInt) { + using Lifted = Unit::Lift; + EXPECT_FALSE(Lifted::value); + auto v = std::is_same::value; + EXPECT_TRUE(v); +} + +TEST(Unit, LiftVoid) { + using Lifted = Unit::Lift; + EXPECT_TRUE(Lifted::value); + auto v = std::is_same::value; + EXPECT_TRUE(v); +}