Repository navigation
MathUtils: let bringTo* deduce the type of the call they forward to - #15946
Conversation
The parameter is a reference, so T is deduced with the address space attached, and forcing that same T on a by-value parameter is a substitution failure on Metal. Letting the inner call deduce its own type gives the same T everywhere else, where the address space is not part of it.
|
But why is this needed? The existing code is even more explicit, so what is the problem? |
|
As I understand it, This is similar to: template <typename T>
T to02Pi(T phi) // by value, and it modifies a local of type T
{
T res = phi;
if (res < 0.f) {
res += 6.283185307f;
}
return res;
}
template <typename T>
T wrap(T& phi) // reference, so T picks up the qualifier
{
return to02Pi<T>(phi); // forwards the reference-deduced T
}
int main()
{
const float phi = -1.f;
return (int)wrap(phi); // T = const float
}which fails because the inner T is deduced as |
|
Builds. Merging. |
The parameter is a reference, so T is deduced with the address space attached,
and forcing that same T on a by-value parameter is a substitution failure on
Metal. Letting the inner call deduce its own type gives the same T everywhere
else, where the address space is not part of it.