Пример #1
0
 /**
  * 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;
 }
Пример #2
0
/**
 * 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());
}
Пример #3
0
/**
 * Swap two data_view objects.
 *
 * @param lhs First object.
 * @param rhs Second object.
 */
inline void swap(data_view& lhs, data_view& rhs) noexcept {
    lhs.swap(rhs);
}
Пример #4
0
/**
 * Returns true if lhs.compare(rhs) >= 0.
 *
 * @param lhs First object.
 * @param rhs Second object.
 */
inline bool operator>=(const data_view lhs, const data_view rhs) noexcept {
    return lhs.compare(rhs) >= 0;
}
Пример #5
0
 /**
  * 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;
 }