|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-02-03 12:30:16
AMDG
Joel de Guzman <joel <at> boost-consulting.com> writes:
>
>
> I'm interested. I'll need polymorphic return type handling though.
> Something like:
>
> struct f
> {
> template <typename Case> struct result;
>
> template <> struct result<mpl::int_<0> >
> : mpl::identity<char> {};
>
> template <> struct result<mpl::int_<2> >
> : mpl::identity<float> {};
>
> template <> struct result<mpl::int_<5> >
> : mpl::identity<std::string> {};
>
> char operator()(mpl::int_<0>) const;
> float operator()(mpl::int_<1>) const;
> std::string operator()(mpl::int_<5>) const;
> };
>
> Regards,
So what goes here?
template<class Cases, class Int, class F>
??? switch_(Int i, F f);
??? could be either any or variant.
If any, why then, typedef boost::any result_type
works just fine. Variant is a little more
difficult especially if operator() is a template.
template<class F>
struct get_result {
template<class Case>
struct apply {
typedef typename F::template result<Case>::type type;
};
};
template<class F, class Sequence>
struct variant_adapter : F {
typedef typename mpl::transform<Sequence,
mpl::protect<get_result<F> >,
mpl::inserter<mpl::set0<>, mpl::insert<_1, _2> >
>::type possible_results;
typedef typename make_variant_over<possible_results>::type result_type;
variant_adapter(const F& f) : F(f) {}
};
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