Boost logo

Boost Users :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2002-11-13 03:18:48


Sam Gentile wrote:
> I went there and indeed it can't get any simpler - at least
> in theory-)
> Read the document
> C:\Boost\boost_1_29_0\libs\type_traits\c++_type_traits.htm
> and its quite
> simple:
>
> template <typename T>
> struct is_void
> { static const bool value = false; };
>
> template <>
> struct is_void<void>
> { static const bool value = true; };
>
> That's exactly what I want to show. So I go to the header files and
> instead:
>
> //* is a type T void - is_void<T>
>
> BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_void,T,false)
>
> BOOST_TT_AUX_BOOL_TRAIT_SPEC1(is_void,void,true)
>
>
>
> Huh? So I look in bool_trait_def.hpp:
>
> #define BOOST_TT_AUX_BOOL_TRAIT_DEF1(trait,T,C) \
>
> template< typename T > struct trait \
>
> : mpl::bool_c< C > \
>
> { \
>
> BOOST_TT_AUX_BOOL_TRAIT_VALUE_DECL(C) \
>
> BOOST_MPL_AUX_LAMBDA_SUPPORT(1,trait,(T)) \
>
> }; \

Well, the original code doesn't have all these excessive newlines ;), but
yes, basically that's how it's implemented.

> Argh! Why is it done like this? This makes it much more
> complicated and unreadable than it has to be. Why are macros
> being used everywhere?

Practical engineering matters. If you consider that the fact that there are
~60 trait templates in the library and every time when a new version of a
compiler comes out, or when somebody starts porting the library to a new
platform, there is a chance that you need to change half of those
definitions, from, for instance,

    template <typename T>
    struct is_void
        : mpl::bool_c<false>
    {
    };

to

    template <typename T>
    struct is_void
    {
        BOOST_STATIC_CONSTANT(bool, value = false);
        typedef mpl::bool_c<value> type;
    };

it might all make sense, after all :). Something along the lines of both of
the above scenarios has actually happened, a couple of times. It's not the
whole picture yet, but IMO it's enough of the motivation already, so I won't
go too deep into details :).

Hope this answers your question,
Aleksey


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net