At 07:22 AM 1/20/2009, you wrote:
>Hi again,
>
>I have a problem. Not really big one but annoying.
>Often we need to write code like this:
>
>struct A{
> int a;
> std::string b;
>};
>
>int a_sum(int i, const A &v){ return v.a + i; };
>
>std::vector<A> v;
>//fill this vector somewhere
>
>std::accumulate( v.begin(), v.end(), 0, a_sum );
>
>or something like
>
>int m_sum(int i, const std::pair<int, std::string> p) { return p.first + i; };
>
>std::map <std::string, int> m;
>
>std::accumlate( m.begin(), m.end(), 0, m_sum);
>
>Or in common words we need to write some kind functor which just get
>member from element and apply it to another functor.
>
>Of course I can write something like:
>
>template<typename T_, typename V_, V_ T_::*Ptr_>
>struct get_mem{
> const V_ &operator()(const T_ &elem){
> return elem->*Ptr_;
> };
>};
>
>but may be there is library way to do this?