view: add char-view less-than operator
This commit is contained in:
parent
62d5dfcf64
commit
17f1ca8f93
22
view.hpp
22
view.hpp
@ -345,6 +345,28 @@ namespace util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
/// a basic stringlike comparison operator that behaves as
|
||||||
|
/// std::string::compare would.
|
||||||
|
///
|
||||||
|
/// provided so that the common case of stringlike views can be used in a
|
||||||
|
/// std::map and similar without a great deal of work.
|
||||||
|
inline bool
|
||||||
|
operator< (util::view<const char*> a, util::view<const char*> b)
|
||||||
|
{
|
||||||
|
const auto la = std::size (a);
|
||||||
|
const auto lb = std::size (b);
|
||||||
|
|
||||||
|
const auto res = strncmp (
|
||||||
|
std::data (a),
|
||||||
|
std::data (b),
|
||||||
|
util::min (la, lb)
|
||||||
|
);
|
||||||
|
|
||||||
|
return res < 0 || la < lb;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// equality operations for string-like views against std::strings
|
// equality operations for string-like views against std::strings
|
||||||
bool equal (const std::string&, view<const char*>);
|
bool equal (const std::string&, view<const char*>);
|
||||||
|
Loading…
Reference in New Issue
Block a user