/** * Compares the contents of this object with the given other object. * * @returns 0 if they are the same, <0 if this object is smaller than * the other or >0 if it is larger. If both objects have the * same size returns <0 if this object is lexicographically * before the other, >0 otherwise. * * @pre Must not be default constructed data_view. */ int compare(data_view other) const { protozero_assert(m_data && other.m_data); const int cmp = std::memcmp(data(), other.data(), std::min(size(), other.size())); if (cmp == 0) { if (size() == other.size()) { return 0; } return size() < other.size() ? -1 : 1; } return cmp; }
/** * Two data_view instances are equal if they have the same size and the * same content. * * @param lhs First object. * @param rhs Second object. */ inline bool operator==(const data_view& lhs, const data_view& rhs) noexcept { return lhs.size() == rhs.size() && std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data()); }
/** * Is this a valid property? Properties are valid if they were * constructed using the non-default constructor. */ constexpr bool valid() const noexcept { return m_key.data() != nullptr; }