Constrained Templates

Jason House jadon.james.house at gmail.com
Mon Jun 14 08:09:15 PDT 2010


Simen kjaeraas Wrote:

> Leandro Lucarella <llucax at gmail.com> wrote:
> > it would be nice
> > to have some sort of way to tell the compiler to write the template
> > constraints for us (the obvious ones at least, there might be other
> > template constraints desired besides the ones the ones the compiler can
> > figure out). This way, the errors can be improved without user
> > intervention.
> 
> How's about @optional? Marks an entire function as optional, i.e. will
> not be included if it does not compile.
> 
> struct foo( T ) {
>    @optional
>    void bar( ) { // Will not exist if T cannot be flabbergasted.
>      T tmp;
>      t.flabbergast( );
>    }
> }
> 
> -- 
> Simen

Would it be a bug or a feature if bar was never included? As written, bar should never compile...


More information about the Digitalmars-d mailing list