Boost logo

Boost Users :

Subject: Re: [Boost-users] [function] generalization of std::plus and std::multiplies with more than one argument type
From: er (erwann.rogard_at_[hidden])
Date: 2009-10-21 17:54:58


alfC wrote:
> thank you er and Mathias for your answers,
>
>>> alfC wrote:
>>>> Does Boost have a generalization of std::plus and std::multiplies
>>>> (std_function.hpp)?
>>> How about the boost::lambda arithmetic operators, possibly in
>>> combination with ll_static_cast<Tp>, and -if necessary- put the
>>> result in the functor wrapper boost::function<Tp(const Tp&,const Tp&)
>>>> ?
>
> what is "ll_static_cast<Tp>"? after that part I got lost.

the cast was in mind to allow for an argument that is convertible to but
not necessarily equal to Tp.

>
>
> but I need this generalization of multiplies as one of the default
> parameter of a template, how would you pass a lambda expression as
> template parameter?

Since you insist on a template parameter,

template<typename Tp,template<typename> class G = default_factory>
struct my_class{

    typedef function<Tp(const Tp&,const Tp&)> F;

    my_class() : f(G<Tp>::create()){}

    F f;
};

template<typename Tp>
struct default_factory{

     typedef BOOST_TYPEOF(
        lambda::_1 * lambda::_2
     ) result_;

     static result_ create(){ return lambda::_1 * lambda::_2; }

};

I did not even try to compile it, just an idea.

>
> The reason I returned to my post is that today I found boost/mpl/
> plus.hpp and boost/mpl/multiplies.hpp which seem to answer the first
> part of my question (although not the syntactic sugar part).
>
> Thank you,
> Alfredo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net