Getting resulting/return type from operation in templates

Rekel paultjeadriaanse at gmail.com
Tue Jul 6 15:21:20 UTC 2021


On Tuesday, 6 July 2021 at 15:00:24 UTC, Paul Backus wrote:
> On Tuesday, 6 July 2021 at 14:43:26 UTC, Rekel wrote:
>> Is there any reason the function call in the alias is 
>> acceptable? I would imagine the () part would actually require 
>> 2 parameters.
>
> You're right, it does; that was a mistake on my part. It should 
> work with `Lhs.init` and `Rhs.init` as arguments.

Hmm . . . doing that ironically brings me back to using:

```d
alias ResultType(Lhs, string op, Rhs) = typeof(mixin("Lhs.init" ~ 
op ~ "Rhs.init"));

auto opBinary(string op, R:
		T2[], T2)(R right) const if (is(ResultType!(T, op, T2))) {
	Vec!(ResultType!(T, op, T2), L) result;
	static foreach (i; 0 .. L) {
		mixin("result[i] = this[i] " ~ op ~ " right[i];");
	}
	return result;
}
```

Kind of ironic this is basically an alias of my old solution.
Strangely enough the nanF issue went away though, I guess I 
misinterpreted this.
Thanks for your help anyway 😅


More information about the Digitalmars-d-learn mailing list