digitalmars.D - "static if" is awesome
- Sean Kelly (17/17) Feb 23 2006 It's how D simplifies everyday programming tasks that really sells me on...
- Don Clugston (15/37) Feb 27 2006 Fabulous.
- Sean Kelly (4/17) Feb 27 2006 Yup :-) About the only time I use it any more is when I want to change
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
Feb 23 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>
Feb 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
Feb 27 2006








Sean Kelly <sean f4.ca>