2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <type_traits>
23 /// In functional programming, the degenerate case is often called "unit". In
24 /// C++, "void" is often the best analogue, however because of the syntactic
25 /// special-casing required for void it is a liability for template
26 /// metaprogramming. So, instead of e.g. Future<void>, we have Future<Unit>.
27 /// You can ignore the actual value, and we port some of the syntactic
28 /// niceties like setValue() instead of setValue(Unit{}).
31 using Lift = std::conditional<std::is_same<T, void>::value, Unit, T>;
33 using Drop = std::conditional<std::is_same<T, Unit>::value, void, T>;
35 bool operator==(const Unit& /*other*/) const { return true; }
36 bool operator!=(const Unit& /*other*/) const { return false; }
39 constexpr Unit unit {};