Thread overview
"static if" is awesome
Feb 24, 2006
Sean Kelly
Feb 27, 2006
Don Clugston
Feb 27, 2006
Sean Kelly
February 24, 2006
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
February 27, 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>
February 27, 2006
Don Clugston wrote:
>
> 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>

Yup :-)  About the only time I use it any more is when I want to change the entire class implementation rather than just a few functions.


Sean