Skip to content

Latest commit

 

History

History
23 lines (14 loc) · 2.8 KB

CppSumSecond.md

File metadata and controls

23 lines (14 loc) · 2.8 KB

You may contact me if you have an STL solution...

Thanks to 'ofwolfandman':


#include <functional> #include <numeric> #include <utility> #include <vector> #include <boost/bind.hpp> int SumSecond(const std::vector<std::pair<int,int> >& v) {   return std::accumulate(     v.begin(),     v.end(),     static_cast<int>(0),     boost::bind(       std::plus<int>(),       _1,       boost::bind<int>(&std::pair<int,int>::second, _2)       )     ); }

Thanks to 'ofwolfandman':


#include <functional> #include <numeric> #include <utility> #include <vector> #include <boost/lambda/lambda.hpp> #include <boost/lambda/bind.hpp> int SumSecond(const std::vector<std::pair<int,int> >& v) {   return std::accumulate(     v.begin(),     v.end(),     static_cast<int>(0),     boost::lambda::_1     + boost::lambda::bind(       &std::pair<int, int>::second, boost::lambda::_2       )   ); }