handful and interval
Philippe Sigaud
philippe.sigaud at gmail.com
Mon Sep 3 01:27:20 PDT 2012
Le 3 sept. 2012 08:42, "Simen Kjaeraas" <simen.kjaras at gmail.com> a écrit :
>
> On Mon, 03 Sep 2012 08:34:33 +0200, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:
>
>> we could add "in" to Tuple and get to write:
>>
>> if (x in tuple("struct", "class", "union")) { ... }
>
>
> if (x in tuple(1, new Foo(), "baa!") { ... }
>
> Just kidding.
I was about to say the same, except not kidding :)
I can see value in having this: finding if a value in a struct '.tupleof',
for example. Or finding a range among a tuple of ranges, all of subtly
different types and that cannot be put in an array.
I was imagining 'in' to return a boolean, but if you need it to return a
possible value, then it can return a pointer to CommonType!(Ts) if this
exists, or a pointer to Algebraic!(Types...).
Of course, that would also be a interesting place to use an Option!(T) type.
> tuple has the inconvenience that we don't know the values at compile-time.
> If we did, we could take advantage of some cleverer tricks for fast
> comparison. At the same time, it's a neat and logical solution.
We can try to get a fully-CT version, using template arguments, but I'm not
sure that would be interesting.
People here are talking about sets, but does Andrei really have sets in
mind? That has consequences if you want 'in' to return a pointer to a value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120903/c761da4a/attachment.html>
More information about the Digitalmars-d
mailing list