Fernando Cacciola wrote:
----- Original Message -----
From: "David A. Greene" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 05, 2002 5:10 PM
Subject: [boost] Compile-time print
Hi gang,
Has anyone come across a compile-time print metafunction?
Yep. Look at the attached file: static_print.hpp
Is this going into Boost somewhere eventually? I think it's
a critically useful thing for metaprogramming.
-Dave
------------------------------------------------------------------------
// (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<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 T> \
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<type>::value
#define STATIC_PRINT_INT(id,val) \
template<int N> \
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<val>::value
#define STATIC_PRINT_BOOL(id,val) \
template<bool B> \
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<val>::value
#define STATIC_PRINT_MSG(msg) \
template<int n> \
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
//
///////////////////////////////////////////////////////////////////////////////////////////////
------------------------------------------------------------------------
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
--
"Some little people have music in them, but Fats, he was all music,
and you know how big he was." -- James P. Johnson
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost