Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 03, 2017 Strange expression found in std.variant | ||||
---|---|---|---|---|
| ||||
When looking at std.variant I found the following line: return q{ static if (allowed!%1$s && T.allowed!%1$s) if (convertsTo!%1$s && other.convertsTo!%1$s) return VariantN(get!%1$s %2$s other.get!%1$s); }.format(tp, op); I was wondering what exactly the % signs where doing/what they are for? |
June 03, 2017 Re: Strange expression found in std.variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to Francis Nixon | On Saturday, 3 June 2017 at 16:22:33 UTC, Francis Nixon wrote:
> When looking at std.variant I found the following line:
> return q{
> static if (allowed!%1$s && T.allowed!%1$s)
> if (convertsTo!%1$s && other.convertsTo!%1$s)
> return VariantN(get!%1$s %2$s other.get!%1$s);
> }.format(tp, op);
>
> I was wondering what exactly the % signs where doing/what they are for?
Those are positional arguments to format.
%1$s refers to the first argument (in this case tp)
while %2$s refers to the second (op)
|
June 03, 2017 Re: Strange expression found in std.variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to Francis Nixon | On Saturday, 3 June 2017 at 16:22:33 UTC, Francis Nixon wrote: > When looking at std.variant I found the following line: > return q{ > static if (allowed!%1$s && T.allowed!%1$s) > if (convertsTo!%1$s && other.convertsTo!%1$s) > return VariantN(get!%1$s %2$s other.get!%1$s); > }.format(tp, op); > > I was wondering what exactly the % signs where doing/what they are for? https://tour.dlang.org/tour/en/basics/alias-strings |
June 03, 2017 Re: Strange expression found in std.variant | ||||
---|---|---|---|---|
| ||||
Posted in reply to Francis Nixon | On Saturday, 3 June 2017 at 16:22:33 UTC, Francis Nixon wrote:
> When looking at std.variant I found the following line:
> return q{
> static if (allowed!%1$s && T.allowed!%1$s)
> if (convertsTo!%1$s && other.convertsTo!%1$s)
> return VariantN(get!%1$s %2$s other.get!%1$s);
> }.format(tp, op);
>
> I was wondering what exactly the % signs where doing/what they are for?
- q{} is a string that cmust contains D tokens. They allow highlightning in the editors, that's why you missed the point.
- % is a format specifier
- q{}.format() is format() called in the UFCS fashion
|
Copyright © 1999-2021 by the D Language Foundation