Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 29, 2014 A possible enhancement related to is() | ||||
---|---|---|---|---|
| ||||
In std.typecons there is this template, that tells if a given type is any tuple, this means if it's the instantiation of a Tuple with any argument type: template isTuple(T) { static if (is(Unqual!T Unused : Tuple!Specs, Specs...)) { enum isTuple = true; } else { enum isTuple = false; } } Do you think it's worth a D enhancement request to be able to write that code like this? enum isTuple(T) = is(Unqual!T Unused : Tuple!Specs, Specs...); Bye, bearophile |
January 29, 2014 Re: A possible enhancement related to is() | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wednesday, 29 January 2014 at 02:30:00 UTC, bearophile wrote:
> In std.typecons there is this template, that tells if a given type is any tuple, this means if it's the instantiation of a Tuple with any argument type:
>
>
> template isTuple(T)
> {
> static if (is(Unqual!T Unused : Tuple!Specs, Specs...))
> {
> enum isTuple = true;
> }
> else
> {
> enum isTuple = false;
> }
> }
>
>
> Do you think it's worth a D enhancement request to be able to write that code like this?
>
> enum isTuple(T) = is(Unqual!T Unused : Tuple!Specs, Specs...);
>
> Bye,
> bearophile
We can already do this, but you have to omit the `Unused` alias (a semi-recent enhancement allows for that):
---
import std.traits : Unqual;
struct Tuple(Args...) {}
enum isTuple(T) = is(Unqual!T : Tuple!Types, Types...);
void main()
{
Tuple!(int, string) t;
static assert(isTuple!(typeof(t)));
}
---
On a related note, I would like the body of a template to be able to access aliases introduced in IsExpression's in the template's constraints.
|
January 29, 2014 Re: A possible enhancement related to is() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On 1/29/14, Jakob Ovrum <jakobovrum@gmail.com> wrote:
> On a related note, I would like the body of a template to be able to access aliases introduced in IsExpression's in the template's constraints.
Me too, but I can't remember if this was filed in bugzilla.
|
January 29, 2014 Re: A possible enhancement related to is() | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | Jakob Ovrum:
> We can already do this, but you have to omit the `Unused` alias (a semi-recent enhancement allows for that):
>
> ---
> import std.traits : Unqual;
>
> struct Tuple(Args...) {}
>
> enum isTuple(T) = is(Unqual!T : Tuple!Types, Types...);
Thank you.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation