// (C) 2001, Fernando Luis Cacciola Carballal. // // This material is provided "as is", with absolutely no warranty expressed // or implied. Any use is at your own risk. // // Permission to use or copy this software for any purpose is hereby granted // without fee, provided the above notices are retained on all copies. // Permission to modify the code and to distribute modified code is granted, // provided the above notices are retained, and a notice that the code was // modified is included with the above copyright notice. // // Revision History // // 27 Nov 2001 Initial version (Fernando Cacciola) // // #ifndef BOOST_STATIC_PRINT_27NOV2001_HPP #define BOOST_STATIC_PRINT_27NOV2001_HPP // // The following macros can be used in template metaprogramming to "print" typenames, // integer and boolean values. // Unlike STATIC_ASSERT(), the output is via a warning, so the code compiles without error. // // Example: // // template // struct Foo // { // STATIC_PRINT_TYPE( FOO_TEMPLATE_PARAMETER, T) // } ; // // template class Foo ; // // When the template is instatiated, a warning will be issued inside a function named: // // STATIC_PRINT_TYPE_NAMED_FOO_TEMPLATE_PARAMETER() // // if you locate the message, you can see which is the the template function parameter // (in this case 'string') // #define STATIC_PRINT_TYPE(id,type) \ template \ struct STATIC_PRINT_TYPE_NAMED_##id \ { \ static const bool value = ( (signed char*)(0) < (unsigned char*)(0) ) ; \ } ; \ static const bool static_printing_type_named_##id = STATIC_PRINT_TYPE_NAMED_##id::value #define STATIC_PRINT_INT(id,val) \ template \ struct STATIC_PRINT_INT_NAMED_##id \ { \ static const bool value = ( (signed char*)(0) < (unsigned char*)(0) ) ; \ } ; \ static const bool static_printing_int_named_##id = STATIC_PRINT_INT_NAMED_##id::value #define STATIC_PRINT_BOOL(id,val) \ template \ struct STATIC_PRINT_BOOL_NAMED_##id \ { \ static const bool value = ( (signed char*)(0) < (unsigned char*)(0) ) ; \ } ; \ static const bool static_printing_bool_named_##id = STATIC_PRINT_BOOL_NAMED_##id::value #define STATIC_PRINT_MSG(msg) \ template \ struct STATIC_PRINT_MSG_NAMED_##id \ { \ static const bool value = ( (signed char*)(0) < (unsigned char*)(0) ) ; \ } ; \ static const bool static_printing_msg_##id = STATIC_PRINT_MSG_NAMED_##id<0>::value #endif // ///////////////////////////////////////////////////////////////////////////////////////////////