Difference between "can call" and "can compile"
Andrej Mitrovic
andrej.mitrovich at gmail.com
Tue Sep 8 13:40:19 UTC 2020
On Monday, 7 September 2020 at 14:57:24 UTC, Steven Schveighoffer
wrote:
> Thoughts?
>
> -Steve
I like your idea.
It's interesting that this would actually be implementable in the
library if we had an ability to retrieve a template's
compile-time parameters. Then you could have something like:
-----
void foo(T)(T v)
{
auto x = v.someProperty;
}
template isCallable (alias sym, Args...)
{
// create a syntactical "copy" of 'sym'
void Proto (CompileTimeParams!sym)(RunTimeParams!sym)
{
}
enum bool isCallable = is(typeof(Proto(Args)));
}
void bar(alias x)() if (isCallable!(x, 1))
{
auto val = x(1);
}
void main ()
{
bar!foo();
}
-----
However:
1. We don't have a way to extract the compile-time parameters
from a template / templated function
2. I'm not sure if there is an easy way to retrieve the run-time
parameters either. There is `ParameterStorageClassTuple` but it's
awkward to use.
And regardless, a library solution will likely be very slow
anyway. This belongs in the compiler.
More information about the Digitalmars-d
mailing list