Boost logo

Boost :

From: Hartmut Kaiser (hartmutkaiser_at_[hidden])
Date: 2004-12-08 11:22:16


 
Stefan Slapeta wrote:

> > is there a means of using the binary visitation pattern provided by
> > the Boost.Variant library and make the return type of the
> visitation
> > process dependent on the types currently stored inside the visited
> > variant object instances?
> >
>
> When I look at the current apply_visitor interface, I can't
> think of any:
>
> template<typename Visitor, typename Variant>
> typename Visitor::result_type
> apply_visitor(Visitor & visitor, Variant & operand);
>
>
> You would need something like the lazy function return type
> deduction in
> Phoenix:
>
> struct Visitor
> {
> template <typename Arg1, typename Arg2>
> struct result
> {
> typedef ... result_type;
> };
>
> ...
> };
>
> and
>
> template<typename Visitor, typename Variant>
> typename Visitor::result<???>::result_type
> apply_visitor(Visitor & visitor, Variant & operand);
>
> I really don't know if ??? (the real argument types) can be
> determined at compile time.

Sure. Actually I've expected to have something like that used in the binary
visiting code...

> > variant_type term1 = 1L;
> > variant_type term2 = 2UL;
> > variant_type term3 = -2L;
> >
> > variant_type unsigned_result =
> > boost::apply_visitor(add_visitor(), term1, term2);
> > variant_type signed_result =
> > boost::apply_visitor(add_visitor(), term1, term3);
> >
> > Is this possible with the current implementation?
> >
>
> That's something different: here you assign again to a
> variant! Why don't you simply use boost::variant as return
> type for the visitor?

Yes, you're right. I've simply choose a bad sample for what I was looking
for.
But it seems, you've got my point anyway.

Regards Hartmut


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