----- Original Message -----
From: "David Abrahams" <[EMAIL PROTECTED]>
To: "Boost mailing list" <[EMAIL PROTECTED]>
Sent: Tuesday, December 10, 2002 3:40 PM
Subject: Re: [boost] Compile-time print


> "Fernando Cacciola" <[EMAIL PROTECTED]> writes:
>
> >> I don't really understand what's going on with it, but Comeau online
> >> is rejecting it:
> >>
> > Yes, I've just tested it and Comeau says the comparing chars of
different
> > types is an error, not a diagnostic.
>
> The code is not comparing chars, but pointers to chars.
>
I just get back to this...

The idea is basically to do anything that issues a warning but not an error.
The following generates a warning both on BCC and Comeau online:  ( (signed
int)(-1) < (unsigned int)(1) )
I've updated the macros to use this as the triggering diagnostic.New header
attached here.

If the trick is working on most of the boost target compilers, I can polish
it up and write a doc so it can be included in /utility or /detail.

Fernando Cacciola

// (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<class T>
//   struct Foo
//   {
//      STATIC_PRINT_TYPE( FOO_TEMPLATE_PARAMETER, T)
//   } ;
//
//   template class Foo<string> ;
//
// When the template is instatiated, a warning will be issued inside a function named:
//
//    STATIC_PRINT_TYPE_NAMED_FOO_TEMPLATE_PARAMETER<string>()
//
// 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<class> \
        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) <type>::value


#define STATIC_PRINT_INT(id,val) \
        template<int> \
        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) <val>::value

#define STATIC_PRINT_BOOL(id,val) \
        template<bool> \
        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) <val>::value

#define STATIC_PRINT_MSG(msg) \
        template<class> \
        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) <char>::value


#endif
//
///////////////////////////////////////////////////////////////////////////////////////////////
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to