Boost logo

Boost :

From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2003-01-09 15:14:22


----- Original Message -----
From: "Daniel Frey" <d.frey_at_[hidden]>

> On Thu, 09 Jan 2003 20:18:08 +0100, Derek Ross wrote:
>
> > Daniel Frey wrote:
> >> Uhm... don't know about MPL, but isn't this a good example for
> >> type_traits? Something like:
> >>
> >> template <class T>
> >> bool SetOption(COptionInfo& o, const char* key, const T& value) {
> >> BOOST_STATIC_ASSERT( boost::is_same< T, bool >::value ||
> >> boost::is_same< T, int >::value ||
> >> boost::is_same< T, double >::value ||
> >> boost::is_same< T, std::string >::value );
> >> ...etc...
> >
> > It doesn't compile because the commas in the is_same template confuse
> > the macro preprocessor.
> >
> > The error message is:
> >
> > "macro "BOOST_STATIC_ASSERT" passed 5 arguments, but takes just 1"
> >
> > Thought you might be interested...
>
> Yes, sorry. I haven't tested this stuff, this is why I said "Something
> like" ;)
>
> Then how about:
>
> template <class T>
> bool SetOption(COptionInfo& o, const char* key, const T& value) {
> typedef boost::is_same< T, bool > is_bool_;
> typedef boost::is_same< T, int > is_int_;
> typedef boost::is_same< T, double > is_double_;
> typedef boost::is_same< T, std::string > is_string_;
> BOOST_STATIC_ASSERT( is_bool_::value ||
> is_int_::value ||
> is_double_::value ||
> is_string_::value );
> ...etc...
>
> (That's the "usual" work-around for the comma-in-macro problem :)
>
> Regards, Daniel

You can just do this as well:

BOOST_STATIC_ASSERT(
    ( boost::is_same<T, bool>::value ) ||
    ( boost::is_same<T, int>::value ) ||
    ( boost::is_same<T, double>::value ) ||
    ( boost::is_same<T, std::string>::value );
)

In other words, just parenthesize the expressions.

Paul Mensonides


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk