Unable to instantiate template with same name as function
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 3 00:58:25 PST 2016
Hello people and thanks for your replies.
Jonathan M Davis via Digitalmars-d-learn wrote:
> You can't overload a function and an eponymous template like that. They
> need to have distinct names.
Why is it not possible for the overload to happen? After all, the compiler
should be able to identify which to use by seeing whether it is followed by
! or (), no?
> > Now, that being said, I don't understand why
> you'd need to do anything with a template for CTFE in this case. Just
> write the function and then call it in a context that requires a
> compile-time result, and it should work. e.g.
OK but say I have a function which returns an array. If I use enum to CTFE
its result, then it is repeatedly included explicitly in all places it is
used, thereby using more memory. So I want to do:
string s = ta!"s";
Obviously, I can still do the different name approach, so it brings us back
to the question as to why the name can't be re-used.
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list