2 * Copyright 2015 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 /// In functional programming, the degenerate case is often called "unit". In
20 /// C++, "void" is often the best analogue, however because of the syntactic
21 /// special-casing required for void it is a liability for template
22 /// metaprogramming. So, instead of e.g. Future<void>, we have Future<Unit>.
23 /// You can ignore the actual value, and we port some of the syntactic
24 /// niceties like setValue() instead of setValue(Unit{}).
26 /// Lift type T into Unit. This is the definition for all non-void types.
27 template <class T> struct Lift : public std::false_type {
30 template <class T> struct Drop : public std::false_type {
33 bool operator==(const Unit& /*other*/) const { return true; }
34 bool operator!=(const Unit& /*other*/) const { return false; }
37 // Lift void into Unit.
39 struct Unit::Lift<void> : public std::true_type {
43 // Lift Unit into Unit (identity).
45 struct Unit::Lift<Unit> : public std::true_type {
49 // Drop Unit into void.
51 struct Unit::Drop<Unit> : public std::true_type {
55 // Drop void into void (identity).
57 struct Unit::Drop<void> : public std::true_type {
62 struct is_void_or_unit : public Unit::Lift<T>