Annoyance with function template unwrapping
kdevel
kdevel at vogtner.de
Sun Jan 17 18:36:13 UTC 2021
On Saturday, 16 January 2021 at 22:09:48 UTC, solidstate1991
wrote:
[...]
> However defining the function templates this way works:
>
> template func(ubyte b) {
> void func(int i) {
> writeln(__PRETTY_FUNCTION__);
> }
> void func(float i) {
> writeln(__PRETTY_FUNCTION__);
> }
> }
Fits.
> I might change my project CPUblit to fit to the latter, and
> then add unittests to ensure that it works, but I don't know
> whether it's a bug, some odd behavior, or something DIP-worthy.
It's odd behavior. It seems that in D template definitions are
things
in itself (like a struct definition) which obey a one declaration
(!) rule.
template S (T) {
void foo () {}
}
template S (T) {
void bar () {}
}
auto fp = &S!int.bar;
depicts the programmer's intent in a crystal clear manner.
Nonetheless dmd
yiels the error you encountered. I think that D-templates should
behave like
C++ namespaces not like structs.
More information about the Digitalmars-d
mailing list