|
Boost : |
From: Joel de Guzman (joel_at_[hidden])
Date: 2007-02-03 18:42:28
Steven Watanabe wrote:
>> 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.
Yeah, right. That's too hairy. I guess it's best to have that
(variant returns) as the responsibility of the function object:
struct f
{
typedef variant<char, float, std::string> result_type;
char operator()(mpl::int_<0>) const;
float operator()(mpl::int_<1>) const;
std::string operator()(mpl::int_<5>) const;
};
Regards,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk