November 19, 2018
On 11/19/18 6:39 PM, Nicholas Wilson wrote:
> On Monday, 19 November 2018 at 15:23:14 UTC, Steven Schveighoffer wrote:
>> We can reduce to linear growth using auto ref:
>>
>> void lval_only()(int x, auto ref int y, auto ref int z) @disable
>> void lval_only()(ref int, int, auto ref int) @disable
>> void lval_only(ref int, ref int, int) @disable
>>
>> Still not ideal though. I tried auto ref for all 3, but that means it will match both the template and the real function.
>>
>> I tried using a constraint, but not sure how to get the parameter ref-ness in a neat way inside the constraint. This does work:
>>
>> void lval_only()(auto ref int x, auto ref int y, auto ref int z) @disable if (!__traits(isRef, x) || !__traits(isRef, y) || !__traits(isRef, z))
>>
>> But it is a bit ugly.
>>
> 
> template isRefX(A...) if (A.length == 1)
> {
>      enum bool isRefX = __traits(isRef, A[0]);
> }
> template allIsRef(A...)
> {
>      enum allIsRef = allSatisfy!(isRefX, A);
> }
> 
> void lval_only()(auto ref int x, auto ref int y, auto ref int z) @disable if (!allIsRef!(x, y, z));

Yep, that is much better. I didn't think of that without making the parameters variadic, lol!

I don't think you need the if(A.length == 1) thing, because alias should work there. They are symbols and won't be keywords.

-Steve
1 2
Next ›   Last »