On 10/29/17 10:35 AM, Ola Fosheim Grøstad wrote:
On Sunday, 29 October 2017 at 14:27:34 UTC, Ola Fosheim Grøstad wrote:
On Sunday, 29 October 2017 at 11:23:19 UTC, Steven Schveighoffer wrote:
So, what will the member function be called? «opElvis»? No…
opCast for bool.
That means you cannot create your own type-safe filtering mechanism,
but will be forced to provide opCast for bool.
That breaks down if you want do filter out invalid values where zero is
a valid value. For instance if you have an integer type that tracks
overflow:
calc(maybe_overflow_integer :? 0)
So casting to bool is a poor choice for the typical use context.
I would have expected Nullable!int to fit the bill, but unfortunately,
opCast(bool) doesn't work on a null Nullable.
But certainly you can construct a type that does work.
-Steve