trick to print a type at compile-time
Hello, Is there a way to print the type returned by a metafunction typedef some_metafunction<T>::type result_type; during compile-time (probably via triggering a compilation error). I almost recall some sort of static assertion (mpl ?) to do this. regards,
On Wed, Sep 8, 2010 at 12:08 AM, Hicham Mouline
Hello,
Is there a way to print the type returned by a metafunction
typedef some_metafunction<T>::type result_type;
during compile-time (probably via triggering a compilation error).
I almost recall some sort of static assertion (mpl ?) to do this.
If all you want is an error you could do typedef typename some_metafunction<T>::result_type error[0] or something like that. Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode
"Emil Dotchevski"
Hello,
Is there a way to print the type returned by a metafunction
typedef some_metafunction<T>::type result_type;
during compile-time (probably via triggering a compilation error).
I almost recall some sort of static assertion (mpl ?) to do this.
If all you want is an error you could do typedef typename some_metafunction<T>::result_type error[0] or something like that. Emil Dotchevski ---------------------- I'd like to print result_type, I don't know what it is. Shouldn't I make result_type a parameter to some template that just triggers an error printout when it is instantiated? would typedef typename some_metafunction<T>::result_type error[0] print what is result_type? thank you, regards,
On 9/8/2010 3:08 AM, Hicham Mouline wrote:
Hello,
Is there a way to print the type returned by a metafunction
typedef some_metafunction<T>::type result_type;
during compile-time (probably via triggering a compilation error). I almost recall some sort of static assertion (mpl ?) to do this.
boost::mpl::print in boost/mpl/print.hpp. Neither seem to be documented. -- Eric Niebler BoostPro Computing http://www.boostpro.com
On Wed, Sep 8, 2010 at 8:56 AM, Eric Niebler
boost::mpl::print in boost/mpl/print.hpp. Neither seem to be documented.
mpl::print is mostly good for those cases where you need to *not* cause a compilation error, perhaps because you are trying to follow recursive instantiations. Otherwise, I'd go with an explicit error; you'll get less noise. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Dave Abrahams Sent: 08 September 2010 14:58 To: boost-users@lists.boost.org Subject: Re: [Boost-users] trick to print a type at compile-time
On Wed, Sep 8, 2010 at 8:56 AM, Eric Niebler
wrote: boost::mpl::print in boost/mpl/print.hpp. Neither seem to be documented.
mpl::print is mostly good for those cases where you need to *not* cause a compilation error, perhaps because you are trying to follow recursive instantiations. Otherwise, I'd go with an explicit error; you'll get less noise.
I tried both ways:
boost::mpl::print
AMDG Hicham Mouline wrote:
I tried both ways:
boost::mpl::print
myvar; and
template <typename T> struct print_error { }; typedef typename print_error
::type my_print_error; my_print_error myvar; In both cases, the bit in the error in msvc2008 just shows:
1> with 1> [ 1> T=result_type 1> ]
it doesn't print what that type actually is.
MSVC does this for typedefs except when they are declared in a class template. Unfortunately, I don't know of any way to get MSVC to print the actual type in other cases. In Christ, Steven Watanabe
-----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users- bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: 09 September 2010 03:56 To: boost-users@lists.boost.org Subject: Re: [Boost-users] trick to print a type at compile-time
AMDG
Hicham Mouline wrote:
I tried both ways:
boost::mpl::print
myvar; and
template <typename T> struct print_error { }; typedef typename print_error
::type my_print_error; my_print_error myvar; In both cases, the bit in the error in msvc2008 just shows:
1> with 1> [ 1> T=result_type 1> ]
it doesn't print what that type actually is.
MSVC does this for typedefs except when they are declared in a class template. Unfortunately, I don't know of any way to get MSVC to print the actual type in other cases.
In Christ, Steven Watanabe
I've managed to change code a bit to allow for it to be printed at runtime instead: throw std::exception( typeid(result_type).name() ) the error I'm getting is related to a fusion::vector with 1 element only. I'll post another question about this now. Thanks,
participants (5)
-
Dave Abrahams
-
Emil Dotchevski
-
Eric Niebler
-
Hicham Mouline
-
Steven Watanabe