On Saturday, 9 November 2019 at 12:30:46 UTC, René Heldmaier wrote:
The part i don't understand is "is(C R == Complex!R)".
What does that mean?

That's checking the if the template argument C is a case of Complex!R, while at the same time declaring a symbol R to hold the inner type.

So let's say we passed it a Complex!int. In that case, C is Complex!int, and then the new name, R, is declared to be `int`.

(though the name R in here is only valid inside that one expression because it is in the constraint... if you need to use it inside the function body, you will need to do it again:

void foo(C)(C c) if(is(C R == Complex!R)) {
static if(is(C R == Complex!R)) // gotta redeclare in this scope
          pragma(msg, R); // will print the type passed now

Can read more here:


I just like to think of it as a variable declaration pattern. A normal variable is declared

int a = 0;

where it goes `type name OPERATOR initializer`

so the

is(C R == Y)

is kinda similar: the existing type is C, the new name is R, then the == Y is the initializer.

still magic syntax but it helps remember the order at least.

And then the Y is like writing out the variable with placeholders.

Reply via email to