Commit 2b2c6f01 authored by Davis King's avatar Davis King

Made the rectangle have an operator< rather than overloading std::less since

the former works with a wider range of tools in the STL.
parent 210bb301
......@@ -260,6 +260,19 @@ namespace dlib
return !(*this == rect);
}
inline bool operator< (const dlib::rectangle& b) const
{
if (left() < b.left()) return true;
else if (left() > b.left()) return false;
else if (top() < b.top()) return true;
else if (top() > b.top()) return false;
else if (right() < b.right()) return true;
else if (right() > b.right()) return false;
else if (bottom() < b.bottom()) return true;
else if (bottom() > b.bottom()) return false;
else return false;
}
private:
long l;
long t;
......@@ -753,29 +766,6 @@ namespace dlib
}
namespace std
{
/*!
Define std::less<rectangle> so that you can use rectangles in the associative containers.
!*/
template<>
struct less<dlib::rectangle> : public binary_function<dlib::rectangle ,dlib::rectangle,bool>
{
inline bool operator() (const dlib::rectangle& a, const dlib::rectangle& b) const
{
if (a.left() < b.left()) return true;
else if (a.left() > b.left()) return false;
else if (a.top() < b.top()) return true;
else if (a.top() > b.top()) return false;
else if (a.right() < b.right()) return true;
else if (a.right() > b.right()) return false;
else if (a.bottom() < b.bottom()) return true;
else if (a.bottom() > b.bottom()) return false;
else return false;
}
};
}
#endif // DLIB_RECTANGLe_
......@@ -363,6 +363,16 @@ namespace dlib
ensures
- returns !(*this == rect)
!*/
bool operator< (
const dlib::rectangle& a,
const dlib::rectangle& b
) const;
/*!
ensures
- Defines a total ordering over rectangles so they can be used in
associative containers.
!*/
};
// ----------------------------------------------------------------------------------------
......@@ -789,28 +799,5 @@ namespace dlib
}
namespace std
{
/*!
Define std::less<rectangle> so that you can use rectangles in the associative containers.
!*/
template<>
struct less<dlib::rectangle> : public binary_function<dlib::rectangle,dlib::rectangle,bool>
{
inline bool operator() (const dlib::rectangle& a, const dlib::rectangle& b) const
{
if (a.left() < b.left()) return true;
else if (a.left() > b.left()) return false;
else if (a.top() < b.top()) return true;
else if (a.top() > b.top()) return false;
else if (a.right() < b.right()) return true;
else if (a.right() > b.right()) return false;
else if (a.bottom() < b.bottom()) return true;
else if (a.bottom() > b.bottom()) return false;
else return false;
}
};
}
#endif // DLIB_RECTANGLe_ABSTRACT_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment