Boost logo

Boost :

From: David A. Greene (greened_at_[hidden])
Date: 2002-11-20 00:59:18


Hi,

I'm starting to explore mpl a bit and I ran into a roadblock.
If I have a template that takes an argument that can be
a sequence (e.g. mpl::vector) or a regular old type, is
there any way, short of specialization, to determine whether
the parameter is a sequence? I'd like to avoid specializing
the template based on mpl guts that may change. Alternatively,
is there any way to manipulate the parameter to guarantee that
it is converted to a sequence (of one element) if it is not a
sequence?

Here's a second question. Suppose I have a "chain" of types
such that each type contains as a member the next type in the
chain. For example:

struct third;
struct second;
struct first;

struct first {
   typedef second type;
};

struct second {
   typedef third type;
};

struct third {
   typedef boost::mpl::void_ type;
};

If I want to use this kind of intrusive sequence with mpl,
how would I go about defining begin<> and end<>? The headers
use something called begin_traits and end_traits but they
assume that the type passed is an mpl-style sequence that
has begin and end members defined.

I don't see how I can easily specialize begin<> and end<>
because I'd need a specialization for each of first, second
and third (in the real code there are many more of these).

I thought about designing some kind of wrapper that could
be used in specialization:

template<typename Node>
struct intrusive_list {
   typedef Node::type type;
};

Then I could partially specialize begin<>/end<> on
intrusive_list. Is this a reasonable approach? Does mpl
provide some more convenient method to use these kinds of
sequences?

Here's one final puzzle: I have two type vectors that
I'd like to merge into one. The trick is that I want
to eliminate all duplicates. Since types cannot be
ordered (how does one define a less-than operation?)
it seems that type vectors cannot be easily sorted.
Thus to do a concat/copy while eliminating duplicates
would seem to be a very expensive task (search for
each candidate in the built-up list before adding it).
Any ideas here? I know I'm missing something important.

Great work by all on mpl -- I'm enjoying the exploration!

                       -Dave

-- 
"Some little people have music in them, but Fats, he was all music,
  and you know how big he was."  --  James P. Johnson

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