"Peter Dimov" <[EMAIL PROTECTED]> writes:

> From: "Derek Ross" <[EMAIL PROTECTED]>
>> 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...
>> 
>> As you can probably guess, this is a template function that should only
>> be called with types of int, bool, std::string or double.
>
> This would make a nice "MPL Hello World" example.

Except that it's an example of how to prevent something from
happening, I agree ;-)

    typedef mpl::vector<bool,int,double,string> legal_types;
    BOOST_STATIC_ASSERT((mpl::contains<legal_types,T>::value));

-Dave
-- 
                       David Abrahams
   [EMAIL PROTECTED] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to