Can not override template and nontemplate function

monarch_dodra monarchdodra at gmail.com
Sat Aug 31 09:39:20 PDT 2013


On Saturday, 31 August 2013 at 12:53:17 UTC, ilya-stromberg wrote:
> On Saturday, 31 August 2013 at 12:19:17 UTC, monarch_dodra 
> wrote:
>> While we are at it, this is also the way to "force" attribute 
>> inference on a function.
>
> Can you print any code example, please?

//This function is @system, not pure, and throws.
void foo()
{}

//This function is @safe, pure and nothrow.
void bar()()


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.

Although arguably, since foo is already in a parameterized 
context, *ideally* it should already be infered (but that is not 
the case today).


More information about the Digitalmars-d mailing list