I have overloaded operator+
in my code,
template < class T1, class T2 >
inline std::pair < T1, T2 > operator+ ( const std::pair < T1, T2 > & a, const std::pair < T1, T2 > & b )
{
return std::make_pair < T1, T2 > ( a.first + b.first, a.second + b.second );
}
However, below fails
vector < pair < int, int > > v ( n );
accumulate ( v.begin( ), v.end( ), make_pair ( 0, 0 ) );
with the compiler complaining that
... stl_numeric.h:128:2: error: no match for 'operator+' in ...
and forces an explicit form as below:
accumulate ( v.begin( ), v.end( ), make_pair ( 0, 0 ), operator+< int, int> );
My question: Why I need to provide operator+
explicitly?
In particular why the line below works like a charm when accumulate
fails?
make_pair ( 2, 3 ) + make_pair ( 5, 7)