When I try to use code like this:
namespace { typedef boost::shared_ptr< float > sharedFloat; } static bool operator<( const sharedFloat& inOne, float inTwo ) { return *inOne < inTwo; } static void foo() { std::vector< sharedFloat > theVec; std::vector< sharedFloat >::iterator i = std::lower_bound( theVec.begin(), theVec.end(), 3.4f ); } I get an error:
error: invalid operands to binary expression ('boost::shared_ptr<float>' and 'float') (with a pointer to the < comparison in the implementation of lower_bound.) So, why are they invalid, when I provided an operator< with those operands?
If I instead use a comparison functor,
namespace { typedef boost::shared_ptr< float > sharedFloat; struct Comp { bool operator()( const sharedFloat& inOne, float inTwo ) { return *inOne < inTwo; } }; } static void foo() { std::vector< sharedFloat > theVec; std::vector< sharedFloat >::iterator i = std::lower_bound( theVec.begin(), theVec.end(), 3.4f, Comp() ); } then it compiles. I could just do things that way, but I'd like to know why the first attempt failed.
Added after solution: Namespaces & Interface Principle by Herb Sutter helped clarify this stuff for me more.