On Monday, 13 December 2021 at 20:43:51 UTC, Steven Schveighoffer
wrote:
On 12/11/21 10:02 PM, apz28 wrote:
On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov
wrote:
@apz28, I can't figure out the intent here. To convert result
of abs to an unsigned?
The function logic works only for unsigned type and the
parameter value can be altered in body hence Unqual. If not
Unqual, must declare a local var and make a copy. Just asking
if this can be done to avoid a cast by caller
To translate a bit here, what apz28 is looking for is, given
ANY value type that implicitly converts from the qualified
value to the unqualified value, generate *one* function that
only accepts the unqualified value.
You can wrap like:
```d
void foo2(T)(T v) if (!is(Unqual!T == T))
{
foo(Unqual!T(t));
}
```
This will inline as if you called it directly (which should
just whittle down to a direct call to the correct foo2).
But D isn't currently smart enough to see through aliases, so
IFTI will not work for what you are doing, even in a case like:
```d
template foo2(T) if (!isUnqual!T == T)
{
alias foo2 = .foo2!(Unqual!T);
}
```
It would be nice if IFTI gave some hooks between the parameter
and the deduction, but it currently doesn't.
-Steve
Is there anything wrong with the answer I posted?
Can you please tell me if there's anything dissatisfactory about
it? I feel like it does everything the OP wants.
Also, am I wrong in using `Unconst` over `Unqual`? Isn't `Unqual`
overkill if you just want to cast away `const`?