|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-10-30 17:16:33
AMDG
Alexander Nasonov <alnsn <at> yandex.ru> writes:
>
> Steven Watanabe <steven <at> providere-consulting.com> writes:
> > Biggest implementation difference:
> > I am using an explicit table of function pointers and
> > a separate buffer rather than a virtual functions.
>
> Great. I planned this optimization but never started implementing it.
>
> Some further questions:
> Why do you use more than one placeholder? What's a difference between _1 and _?
> In dynamic_any, I use only anyT placeholder.
> I didn't get the idea of tuples. What are they for?
Everything that you do in dynamic_any can be handled using
only _. The other placeholders are for dealing with multiple
types.
Basically, I was trying to come up with a way to mimic
C++0x concepts as much as possible at runtime.
The tuples provide a way to capture functions involving
multiple types at the same time.
tuple<_1, _2, where_<addable<_1, _2> > > is two element tuple
whose elements can be added. If I created one
tuple<_1, _2, addable<_1, _2> > t(1, 2);
Then, I can write
type_erasure::any<> result = get<0>(t) + get<1>(t);
assert(type_erasure::any_cast<int>(result) == 3);
One of the things I was aiming for was
typedef tuple<_1, _1, _2,
where<
forward_iterator<_1>,
callable<_2, bool(deref<_1>::type)> > > algorithm_args;
class Base {
public:
// "virtual" template
template<class Iter, class F>
void do_stuff(Iter begin, Iter end, F f) {
algorithm_args args(begin, end, f);
return(do_stuff_impl(args));
}
virtual void do_stuff_impl(algorithm_args&) = 0;
};
class Derived : public Base {
virtual void do_stuff_impl(algorithm_args& args) {
std::remove_if(get<0>(args), get<1>(args), get<2>(args));
}
};
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk