Option!T
monarch_dodra
monarchdodra at gmail.com
Tue Dec 10 12:02:57 PST 2013
On Tuesday, 10 December 2013 at 19:26:27 UTC, Andrei Alexandrescu
wrote:
> On 12/10/13 10:59 AM, monarch_dodra wrote:
>> On Tuesday, 10 December 2013 at 17:28:26 UTC, Andrei
>> Alexandrescu
>> wrote:
>>> We have only(x)
>>> (http://dlang.org/phobos/std_range.html#.only) to be a
>>> collection of exactly one value, but not a type for "a value
>>> of type T
>>> or nothing at all"
>>
>> Option is being upgraded to handle an arbitrary (but compile
>> time
>> known) amount of values:
>> https://github.com/D-Programming-Language/phobos/pull/1743
>
> Interesting! There is the problem one can't represent "no
> element of type T" and "one element of type T" with the same
> type.
Hum... True. Well... "T[]", I guess :)
> There's also the unrelated issue that the result of the
> proposed only() is passed around by value, even after it has
> been partially discarded.
Yes, but that also means than slicing doesn't escape a references
to temporaries about the go out of scope: It carries around its
payload.
But, I see no reason not to implement an "Option": The way I see
it, it "completes" our range package. Each tool has its pros and
cons.
I'm also working on a "staticArray", that can create static
arrays on the fly. That too can also be used just like "only",
but it does not carry arround its data by value. I'll finish the
ER, and the pull, and you'll get more details. It seems like very
useful stuff to me anyways.
More information about the Digitalmars-d
mailing list