Clojure and Pull Request Controversy
jmh530
john.michael.hall at gmail.com
Fri Nov 30 23:59:21 UTC 2018
On Friday, 30 November 2018 at 16:54:43 UTC, Paul Backus wrote:
> [snip]
>
> UDAs attach to symbols, not values, so x will never have a
> @noAutodecode attribute, no matter what arguments you pass to
> foo.
Yeah you're right. Putting the attribute on the function
parameter gives the parameter that attribute (the function spec
says to look at the UDA spec and then that doesn't really say
anything about function parameters). It doesn't require that the
parameter has that attribute.
The only thing I could think of was doing it with an alias, but
it's a little too ugly to get the right behavior. Maybe there's a
more elegant way?
import std.traits : hasUDA;
import std.stdio : writeln;
struct noAutodecode {};
void foo(alias x, T)(T y)
if (hasUDA!(x, noAutodecode))
{
writeln("here");
}
void foo(alias x, T)(T y)
if (!hasUDA!(x, noAutodecode))
{
writeln("there");
}
void main() {
string a = "xyz";
@noAutodecode string b = "zyx";
foo!(a, string)(a);
foo!(b, string)(b);
}
More information about the Digitalmars-d
mailing list