// (C) 2002, 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. // // #ifndef BOOST_STATIC_PRINT_27NOV2001_HPP #define BOOST_STATIC_PRINT_27NOV2001_HPP #include "boost/preprocessor/cat.hpp" #include "boost/preprocessor/stringize.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 BOOST_PP_CAT(STATIC_PRINT_TYPE_NAMED_,id) \ { \ static const bool value = (signed int)(-1) < (unsigned int)(1) ; \ } ; \ static const bool BOOST_PP_CAT(static_printing_type_named_,id) = BOOST_PP_CAT(STATIC_PRINT_TYPE_NAMED_,id) ::value #define STATIC_PRINT_INT(id,val) \ template \ struct BOOST_PP_CAT(STATIC_PRINT_INT_NAMED_,id) \ { \ static const bool value = (signed int)(-1) < (unsigned int)(1) ; \ } ; \ static const bool BOOST_PP_CAT(static_printing_int_named_,id) = BOOST_PP_CAT(STATIC_PRINT_INT_NAMED_,id) ::value #define STATIC_PRINT_BOOL(id,val) \ template \ struct BOOST_PP_CAT(STATIC_PRINT_BOOL_NAMED_,id) \ { \ static const bool value = (signed int)(-1) < (unsigned int)(1) ; \ } ; \ static const bool BOOST_PP_CAT(static_printing_bool_named_,id) = BOOST_PP_CAT(STATIC_PRINT_BOOL_NAMED_,id) ::value #define STATIC_PRINT_MSG(msg) \ template \ struct BOOST_PP_CAT(STATIC_PRINT_MSG_NAMED_,msg) \ { \ static const bool value = (signed int)(-1) < (unsigned int)(1) ; \ } ; \ static const bool BOOST_PP_CAT(static_printing_msg_,msg) = BOOST_PP_CAT(STATIC_PRINT_MSG_NAMED_,msg) ::value #endif // ///////////////////////////////////////////////////////////////////////////////////////////////