Boost logo

Boost :

From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2003-01-09 13:26:15


Derek Ross wrote:
>
> Hello,
>
> I'd like to convert this run-time assertion to a compile time MPL check:
>
> template <class T>
> bool SetOption(COptionInfo& o, const char* key, const T& value)
> {
> assert( typeid(T)==typeid(bool)
> || typeid(T)==typeid(int)
> || typeid(T)==typeid(double)
> || typeid(T)==typeid(string));
> ...etc...

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...
}

Regards, Daniel

-- 
Daniel Frey
aixigo AG - financial training, research and technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de

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