Thread overview
I just discovered an alternative use of the `in`-operator
Aug 06, 2020
Per Nordlöw
Aug 06, 2020
Per Nordlöw
Aug 06, 2020
Paul Backus
Aug 07, 2020
Per Nordlöw
Aug 07, 2020
Per Nordlöw
Aug 07, 2020
aberba
Aug 07, 2020
H. S. Teoh
Aug 09, 2020
Per Nordlöw
August 06, 2020
I just discovered that the is-operator can be used as in

template ElementType(R)
{
    static if (is(typeof(R.init.front.init) T))
        alias ElementType = T;
    else
        alias ElementType = void;
}

. Very powerful. Is this documented?
August 06, 2020
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote:
> I just discovered that the is-operator can be used as in
> ...

Doh, title should of course be

I just discovered an alternative use of `is`-expressions.
August 06, 2020
On Thursday, 6 August 2020 at 21:50:06 UTC, Per Nordlöw wrote:
> I just discovered that the is-operator can be used as in
>
> template ElementType(R)
> {
>     static if (is(typeof(R.init.front.init) T))
>         alias ElementType = T;
>     else
>         alias ElementType = void;
> }
>
> . Very powerful. Is this documented?

Yes, in the following paragraph under "IsExpression" [1]:

> Identifier is declared to be an alias of the resulting type if the condition is satisfied. The Identifier forms can only be used if the IsExpression appears in a StaticIfCondition.

[1] https://dlang.org/spec/expression.html#is_expression
August 07, 2020
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:
> [1] https://dlang.org/spec/expression.html#is_expression

Thanks
August 07, 2020
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:
> [1] https://dlang.org/spec/expression.html#is_expression

I bet there a several places in Phobos where this feature isn't but could be used.
August 07, 2020
On Friday, 7 August 2020 at 21:02:03 UTC, Per Nordlöw wrote:
> On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:
>> [1] https://dlang.org/spec/expression.html#is_expression
>
> I bet there a several places in Phobos where this feature isn't but could be used.

I feel same. That there's a clever use of certain D features waiting to be discovered.
August 07, 2020
On Fri, Aug 07, 2020 at 09:02:03PM +0000, Per Nordlöw via Digitalmars-d-learn wrote:
> On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:
> > [1] https://dlang.org/spec/expression.html#is_expression
> 
> I bet there a several places in Phobos where this feature isn't but could be used.

Perhaps. But as I recall, it's widely used throughout Phobos, so it probably won't be easy to find a place where it could be used but isn't.


T

-- 
Written on the window of a clothing store: No shirt, no shoes, no service.
August 09, 2020
On Thursday, 6 August 2020 at 22:24:43 UTC, Paul Backus wrote:
> [1] https://dlang.org/spec/expression.html#is_expression

Thanks