|
Boost : |
From: Stefan Slapeta (stefan_nospam__at_[hidden])
Date: 2004-12-08 10:47:51
Hartmut Kaiser wrote:
> Hi all,
>
> 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.
>
> 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?
Stefan
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk