|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-10-23 02:32:55
David B. Held writes:
> Is it possible to detect whether a template parameter is
> an MPL container or not?
Yep, please see below.
> I would like to be able to do
> something roughly like this:
>
> template <typename T>
> struct foo
> {
> typedef if_<is_mpl_container<T>::type,
> begin<T>::type,
> T
> >::type my_type;
> };
template <typename T>
struct foo
{
typedef if_< is_sequence<T>
begin<T>::type,
T
>::type my_type;
};
>
> Actually, what I would really like to do is create an array
> of objects based on the types in T if T is an MPL container,
> and an array of 1 if it's not. That way, I can say:
>
> foo<int> f;
>
> or:
>
> foo<mpl::list<int, double, char> > f;
You need this one, then:
template <typename T>
struct foo
{
typedef typename as_sequence<T>::type seq;
// ^^
};
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk