Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2006-08-03 15:13:45


AMDG

Alexander,

>For the latter I'm thinking of the following approach:
>
> struct plus : function<plus, anyT (anyT const&, anyT const&)>
> {
> int entry(id<1>, int, int) const;
> double entry(id<2>, double, int) const;
> // ...
> std::string entry(id<100>, std::string const&, char) const;
> // ...
> };
>
>
>
How do you detect the end of the entries?
I can't think of anything better in general but here are
some other possibilities that might be more convenient:

    struct plus : function<plus, anyT (anyT const&, anyT const&)>
    {
        typedef boost::mpl::vector<
            int (int, int),
            double (double, int),
            //...
            string (string const&, char),
            //...
> entry_functions;

        template<class T, class U>
        T entry(T t, U u) const;
    };

or this:

    struct plus : function<plus, anyT (anyT const&, anyT const&)>
    {
        typedef boost::mpl::vector<int, double, string const&>
first_any_argument_types;
        typedef boost::mpl::vector<int, char> second_any_argument_types;

        template<class T, class U>
        T entry(T t, U u) const;
    };

Of course this one only works when you want every
possible combination of the types.

In any case I agree that there should be a backup to use if
the types passed in don't match one of the signatures provided.
Maybe something like allowing any one of the arguments
to be unbounded.

    typedef boost::mpl::vector_c<int, 1, 2>
possibly_unbounded_any_arg_indexes;

Another way would be to require all the types to be the same
when at least one of them doesn't match.

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