From: Yedidya Feldblum Date: Wed, 18 May 2016 21:46:49 +0000 (-0700) Subject: Flesh out the comments about Unit X-Git-Tag: 2016.07.26~222 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=004d6c170bf77139af25f7ff6024637cee5ce58b;p=folly.git Flesh out the comments about Unit 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 --- diff --git a/folly/Unit.h b/folly/Unit.h index cb6a6566..df99eba2 100644 --- a/folly/Unit.h +++ b/folly/Unit.h @@ -21,11 +21,18 @@ 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, we have Future. -/// 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, a library author may instead rule that out and simply +/// have library users use SomeContainer. 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 using Lift = std::conditional::value, Unit, T>;