Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2005-01-17 01:25:57


Aleksey Gurtovoy wrote:
> Can't it be something like
>
> mpl::find_if<
> overload_set<1,5,has_intersection>
> , is_same<first_arg<_>, Circle&>
> >
>
> ?

Well, I could use mpl find_if but it's not the best way (unless
mpl::find_if is specialized).

1. The overload_set is a mixture of positions and signatures. You can think
of it as of a vector of pointers to sequence elements or, even more closely
to problem domain, as a vector of indicies with elements stored in another
vector. It's perfectly valid to operate on position level and to
"dereference" it in predicate:

     mpl::find_if<
         range_c<int,1,5>
       , test1<has_intersection, first_arg_is_Circle_ref, _1>
                                      // this is position ^^
>

2. Without typeof you can't get signature from everywhere and pass it to
an algorithm. test1 can do this but the algorithm should operate on
position level then.

3. Performance. When number of functions is high everything is
important. For example, if all functions have same arity it decrease
compilation time significantly. I have to pass a strategy to algorithms.

Currently, this example looks like:

     overloads::find_if<
         overload_set<has_intersection, mpl::range_c<int,1,5> >
       , is_same<first_arg<_>, Circle&>
>

Close to your code but it's not mpl::find_if.

> > I used it till recently. But it's not quite an OverloadSet concept.
> >
> > 2. MPL-like sequence would be nice to have. Something similar to:
> >
> > mpl::vector< bool(Circle&, Circle& )
> > , bool(Circle&, Rectangle&)
> > , bool(Rectangle&, Circle& )
> > , bool(Rectangle&, Rectangle&)
> > >
> >
> > or
> >
> > mpl::set< bool(Circle&, Circle& )
> > , bool(Circle&, Rectangle&)
> > , bool(Rectangle&, Circle& )
> > , bool(Rectangle&, Rectangle&)
> > >
> >
> > Unfortunately, if typeof is not available, deref and some other
> > operations work only in deduced context (that is, inside special
> > function).
>
> I'm afraid I don't follow; the above seems perfectly viable to
> me. Could you provide an example?

It is viable. But function and metainformation (signature) are stored in
different places. It's ok only if you have few functions. What if you
have 400? Can mpl::vector or mpl::set contain 400 elements? I'm afraid
not. Some overloads library work even on higher numbers (up to 700 on my
laptop).
400 is not a random number. Imagine, you have 20 classes in Shape
hierarchy. Intersestion of all of them requires 20x20=400
has_intersection functions.

BTW, I remember Dave mentioned that you generate FSM using mpl::vectorN,
with N higher then default 50. How high is N?

> I think Fusion is already capable of building tuples based on the MPL
> sequences.

1. It's different. In mpl case you use a sequence to generate tuple *type*.
In overloads case, it's both types and values. overload_set is more like
mpl sequence of integral constants. You can pass it to for_each, for
example.

2. The problem is that overload_set is not an MPL sequence.

-- 
Alexander Nasonov

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