view: add equality operators
This commit is contained in:
parent
4764015f9b
commit
da464968e6
24
view.cpp
24
view.cpp
@ -90,6 +90,23 @@ util::view::operator[] (size_t idx) const
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
util::view::operator== (const char *restrict rhs) const
|
||||
{
|
||||
return strlen (rhs) == size () &&
|
||||
0 == strncmp (rhs, m_begin, size ());
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
util::view::operator== (view v) const
|
||||
{
|
||||
return std::equal (m_begin, m_end, v.begin ());
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::ostream&
|
||||
util::operator<< (std::ostream &os, util::view s)
|
||||
@ -98,3 +115,10 @@ util::operator<< (std::ostream &os, util::view s)
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
bool
|
||||
util::operator== (const char *str, view v)
|
||||
{
|
||||
return v == str;
|
||||
}
|
||||
|
4
view.hpp
4
view.hpp
@ -38,6 +38,9 @@ namespace util {
|
||||
size_t size (void) const;
|
||||
const char& operator[] (size_t) const;
|
||||
|
||||
bool operator== (const char *restrict str) const;
|
||||
bool operator== (view) const;
|
||||
|
||||
private:
|
||||
const char *m_begin;
|
||||
const char *m_end;
|
||||
@ -45,5 +48,6 @@ namespace util {
|
||||
|
||||
|
||||
std::ostream& operator<< (std::ostream&, view);
|
||||
bool operator== (const char*, view);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user