Can not override template and nontemplate function

monarch_dodra monarchdodra at gmail.com
Sat Aug 31 09:43:40 PDT 2013


On Saturday, 31 August 2013 at 16:39:22 UTC, monarch_dodra wrote:
> It's a trick that is useful when doing non-template functions 
> inside a templated struct. EG:
>
> struct S(T)
> {
>     T t;
>     T foo()
>     {
>         return t;
>     }
> }
>
> Here, we don't know if foo is nothrow, as the postblit could 
> throw, for example. If we make it a template, then the compiler 
> deduces it for us.

Bad example, the "correct" example is one that uses voldermort 
typing:

auto foo(T)()
{
     struct S //S is not a template
     {
         void bar(){}
     }
     return S();
}

void main() pure nothrow @system
{
     auto s = foo!int();
     s.bar(); //Error here!
}

but, again, arguably, that should have "just worked" (tm)


More information about the Digitalmars-d mailing list