Constrained Templates

Simen kjaeraas simen.kjaras at gmail.com
Mon Jun 14 09:07:45 PDT 2010


Jason House <jadon.james.house at gmail.com> wrote:

> 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...

Well spotted. And a very good reason not to have this feature (or to
write unit tests, I guess :p )

-- 
Simen


More information about the Digitalmars-d mailing list