Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2007-10-01 08:19:24


On 10/1/07, Marco Costalba <mcostalba_at_[hidden]> wrote:
> On 10/1/07, Joel de Guzman <joel_at_[hidden]> wrote:
> > Joel de Guzman wrote:
> >
> > Hence, I'd like to propose an extension (or a separate library)
> > for allowing overloads for boost.function. The example above can
> > be declared as:
> >
> > boost::overload<
> > std::string(std::string, std:string)
> > , std::string(std::string, char)
> > , std::string(std::string, char const*)
> > , std::string(char, std::string)
> > , std::string(char const*, std::string)
> > >
> > concat;
> >
>
> Or possibly (perhaps)
>
> typedef fusion::vector<
> std::string(std::string, std:string)
> , std::string(std::string, char)
> , std::string(std::string, char const*)
> , std::string(char, std::string)
> , std::string(char const*, std::string)
> > overloads_sequence;
>
>
> boost::overload<overloads_sequence> concat;
>

As example changing the inheritance compositing structure from

    namespace detail
    {
        template <typename Sig0, typename Sig1, typename Sig2, typename Sig3>
        struct compose_overload_base
        {
            typedef overload<Sig0, Sig1, Sig2, Sig3> derived;
            typedef overload_function<final_overload_function,
derived, Sig0> ov1;
            typedef overload_function<ov1, derived, Sig1> ov2;
            typedef overload_function<ov2, derived, Sig2> ov3;
            typedef overload_function<ov3, derived, Sig3> ov4;
            typedef ov4 type;
        };
    }

to

namespace detail
    {
        template <typename Seq, typename derived, int n>
        struct do_compose
        {
            typedef typename fusion::result_of::value_at_c<Seq, n -
1>::type sig;
            typedef typename fusion::result_of::pop_back<Seq>::type popped_seq;

            typedef do_compose<popped_seq, derived, n - 1> ov;
            typedef overload_function<ov, derived, sig> type;
        };

        template <typename Seq, typename derived>
        struct do_compose<Seq, derived, 1>
        {
            typedef typename fusion::result_of::value_at_c<Seq, 0>::type sig;

            typedef overload_function<final_overload_function, derived, sig> type;
        };

        template <typename Seq>
        struct compose_overload_base
        {
            enum { n = fusion::result_of::size<Seq>::type::value };

            typedef overload<Seq> derived;

            typedef typename do_compose<Seq, derived, n>::type type;
        };
    }

A little bit more complex but works for any number of arguments (sigantures).

Marco


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