Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2004-02-05 20:56:02


Brian McNamara wrote:

> On Thu, Feb 05, 2004 at 06:28:27PM -0600, Brock Peabody wrote:
>
>>Is there an easy way to write:
>>
>> template <typename T> struct is_variant {
>>
>> typedef ??? type;
>> };
>>
>>So far the best I can come up with is:
>>
>>1) T has a member type "types" and
>>2) T is convertible to make_variant_over<T::types>::type and
>>3) make_variant_over<T::types>::type is convertible to T
>>
>>Does anyone have a better idea?
>
>
> Perhaps I'm missing something, but why not just something like
>
> template <typename T> struct is_variant {
> typedef false_ type;
> };
> template <typename T1, typename T2, ... /*however many*/>
> struct is_variant<variant<T1,T2,...> > {
> typedef true_ type;
> };
>
> ?

Precisely,

   template <typename T> struct is_variant
     : mpl::false_ {};

   template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
   struct is_variant< variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
     : mpl::true_ {};

should do the trick. If this is deemed useful, I can include it in the
next release. For now, BOOST_VARIANT_ENUM_PARAMS should cover you.

Eric


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