Flesh out the comments about Unit
authorYedidya Feldblum <yfeldblum@fb.com>
Wed, 18 May 2016 21:46:49 +0000 (14:46 -0700)
committerFacebook Github Bot 2 <facebook-github-bot-2-bot@fb.com>
Wed, 18 May 2016 21:53:25 +0000 (14:53 -0700)
Summary:
[Folly] Flesh out the comments about `Unit`.

* Remove mention of `Future`.
* Compare `unit` to `void`.

Reviewed By: djwatson

Differential Revision: D3316114

fbshipit-source-id: d30cf36cc029025734bb16c5bdbd640a289cad79

folly/Unit.h

index cb6a6566df41a57ead7ea60d940e338f639bc61c..df99eba27bebfb0bfc0ad8276d840e466bcd4481 100644 (file)
 namespace folly {
 
 /// In functional programming, the degenerate case is often called "unit". In
 namespace folly {
 
 /// In functional programming, the degenerate case is often called "unit". In
-/// C++, "void" is often the best analogue, however because of the syntactic
-/// special-casing required for void it is a liability for template
-/// metaprogramming. So, instead of e.g. Future<void>, we have Future<Unit>.
-/// You can ignore the actual value, and we port some of the syntactic
-/// niceties like setValue() instead of setValue(Unit{}).
+/// C++, "void" is often the best analogue. However, because of the syntactic
+/// special-casing required for void, it is frequently a liability for template
+/// metaprogramming. So, instead of writing specializations to handle cases like
+/// SomeContainer<void>, a library author may instead rule that out and simply
+/// have library users use SomeContainer<Unit>. Contained values may be ignored.
+/// Much easier.
+///
+/// "void" is the type that admits of no values at all. It is not possible to
+/// construct a value of this type.
+/// "unit" is the type that admits of precisely one unique value. It is
+/// possible to construct a value of this type, but it is always the same value
+/// every time, so it is uninteresting.
 struct Unit {
   template <typename T>
   using Lift = std::conditional<std::is_same<T, void>::value, Unit, T>;
 struct Unit {
   template <typename T>
   using Lift = std::conditional<std::is_same<T, void>::value, Unit, T>;