cpp: type::raw_ref::str(), operator==, operator!=, operator< and operator> are now const

This commit is contained in:
frsyuki 2010-07-14 17:02:04 +09:00
parent 167e2475d8
commit 331bf0af21

View File

@ -33,25 +33,25 @@ struct raw_ref {
uint32_t size; uint32_t size;
const char* ptr; const char* ptr;
std::string str() { return std::string(ptr, size); } std::string str() const { return std::string(ptr, size); }
bool operator== (const raw_ref& x) bool operator== (const raw_ref& x) const
{ {
return size == x.size && memcmp(ptr, x.ptr, size) == 0; return size == x.size && memcmp(ptr, x.ptr, size) == 0;
} }
bool operator!= (const raw_ref& x) bool operator!= (const raw_ref& x) const
{ {
return !(*this != x); return !(*this != x);
} }
bool operator< (const raw_ref& x) bool operator< (const raw_ref& x) const
{ {
if(size == x.size) { return memcmp(ptr, x.ptr, size) < 0; } if(size == x.size) { return memcmp(ptr, x.ptr, size) < 0; }
else { return size < x.size; } else { return size < x.size; }
} }
bool operator> (const raw_ref& x) bool operator> (const raw_ref& x) const
{ {
if(size == x.size) { return memcmp(ptr, x.ptr, size) > 0; } if(size == x.size) { return memcmp(ptr, x.ptr, size) > 0; }
else { return size > x.size; } else { return size > x.size; }