[Insight-users] TODO for AffineTransform::Rotate3D()

Benjamin King king.benjamin at mh-hannover.de
Tue, 27 Jan 2004 10:16:13 +0100


Hello,

I came across the AffineTransform::Rotate3D() documentation and the author 
needs some sort of compile-time assertion depending on the template 
parameter NDimensions.
I bought "Modern C++ Design" by Andrei Alexandrescu some time ago and 
never since dared to read more than the first few pages. Fortunately 
compile-time assertions are already done on page 25 of this amazing book 
=). See for yourself (credit of course goes to Andrei):

   template<bool> struct CompileTimeError;
   template<> struct CompileTimeError<true> { };
   #define STATIC_CHECK(expr, msg) {CompileTimeError<(expr) != 0> 
ERROR_##msg; (void)ERROR_##msg;}

Only the spezialization for 'true' of the bool templated 
CompileTimeError-class can be instatiated. This is exactly what the 
STATIC_CHECK macro tries to do. If you call it with an expression that 
evaluates to false at compile time, the compiler will tell that 
construction of the variable ERROR_##msg failed.
I have no idea what that '(void)ERROR_##msg;' is needed for. I think it's 
there to prevent a (useless) construction in cases where the assertion 
holds.

You will find pointers to this and other code from the book on 
http://www.moderncppdesign.com

HIH,
   Benjamin

-- 
Benjamin King
Institut für Medizinische Informatik
Medizinische Hochschule Hannover
Tel.: +49  511  532-2663