This question is inspired by Issue with std::reference_wrapper. Let' say, for example, operator<
for std::vector
. It's defined as a function template as
template< class T, class Alloc >
bool operator<( const vector<T,Alloc>& lhs,
const vector<T,Alloc>& rhs );
As a result, implicit conversion of function argument to the type of the corresponding function parameter is denied (basically because of its template nature). This greatly reduces the usefulness and convenience of std::reference_wrapper
. For example, you cannot use std::sort
on std::vector<std::reference_wrapper<std::vector<int>>>
.
On the other hand, all the problems are solved only if operator<
is defined as a non-template Koenig operator like
template <...>
class vector ... {
friend bool operator<(const vector& a, const vector& b) {...}
};
I'm wondering why the standard library has adopted the former approach instead of this?