"static if" is awesome

Don Clugston dac at nospam.com.au
Mon Feb 27 00:20:30 PST 2006


Sean Kelly wrote:
> It's how D simplifies everyday programming tasks that really sells me on 
> this language.  'Atomic' in Ares now supports increment and decrement 
> operations for numeric and pointer types only, and it does so without 
> any weird template machinations or duplicated code:
> 
> struct Atomic(T)
> {
>     T load();
>     void store( T newval );
>     bool storeIf( T newval, T equalTo );
> 
>     static if( isValidNumericType!(T) )
>     {
>         T increment();
>     T decrement();
>     }
> }
> 
> Try that in C++ :-P
> 
> 
> Sean

Fabulous.
"static if" makes the easy stuff easy, and the hard stuff moderately 
easy <g>

I'm tempted to report this line from
http://www.digitalmars.com/d/overview.html
as a documentation bug:
----------
Templates

D templates offer a clean way to support generic programming while 
offering the power of partial specialization.
-------

I think that since D has "static if", partial template specialisation is 
primarily for backwards compatibility with C++. It's a primitive, ugly 
technology. <g>



More information about the Digitalmars-d mailing list