mirror of
https://github.com/boostorg/stacktrace.git
synced 2026-02-22 03:32:27 +00:00
Added comparison operators and tests for them
This commit is contained in:
@@ -119,9 +119,27 @@ public:
|
||||
return !size();
|
||||
}
|
||||
|
||||
/// @brief Allows to check that capturing stack trace was successful.
|
||||
/// @returns `true` if `this->size() != 0`
|
||||
///
|
||||
/// @b Complexity: O(1)
|
||||
BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT()
|
||||
|
||||
/// @brief Compares stacktraces for less, order is platform dependant.
|
||||
///
|
||||
/// @b Complexity: Amortized O(1); worst case O(size())
|
||||
BOOST_STACKTRACE_FUNCTION bool operator< (const stacktrace& rhs) const BOOST_NOEXCEPT;
|
||||
|
||||
/// @brief Compares stacktraces for equality.
|
||||
///
|
||||
/// @b Complexity: Amortized O(1); worst case O(size())
|
||||
BOOST_STACKTRACE_FUNCTION bool operator==(const stacktrace& rhs) const BOOST_NOEXCEPT;
|
||||
};
|
||||
|
||||
inline bool operator> (const stacktrace& lhs, const stacktrace& rhs) BOOST_NOEXCEPT { return rhs < lhs; }
|
||||
inline bool operator<=(const stacktrace& lhs, const stacktrace& rhs) BOOST_NOEXCEPT { return !(lhs > rhs); }
|
||||
inline bool operator>=(const stacktrace& lhs, const stacktrace& rhs) BOOST_NOEXCEPT { return !(lhs < rhs); }
|
||||
inline bool operator!=(const stacktrace& lhs, const stacktrace& rhs) BOOST_NOEXCEPT { return !(lhs == rhs); }
|
||||
|
||||
/// Outputs stacktrace in a human readable format to output stream.
|
||||
template <class CharT, class TraitsT>
|
||||
|
||||
@@ -76,6 +76,32 @@ struct backtrace_holder {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline bool operator< (const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return frames_count < rhs.frames_count;
|
||||
} else if (frames.get() == rhs.frames.get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::lexicographical_compare(
|
||||
frames.get(), frames.get() + frames_count,
|
||||
rhs.frames.get(), rhs.frames.get() + rhs.frames_count
|
||||
);
|
||||
}
|
||||
|
||||
inline bool operator==(const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return false;
|
||||
} else if (frames.get() == rhs.frames.get()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return std::equal(
|
||||
frames.get(), frames.get() + frames_count,
|
||||
rhs.frames.get()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
@@ -50,6 +50,32 @@ struct backtrace_holder {
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
inline bool operator< (const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return frames_count < rhs.frames_count;
|
||||
} else if (this == &rhs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::lexicographical_compare(
|
||||
buffer, buffer + frames_count,
|
||||
rhs.buffer, rhs.buffer + rhs.frames_count
|
||||
);
|
||||
}
|
||||
|
||||
inline bool operator==(const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return false;
|
||||
} else if (this == &rhs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return std::equal(
|
||||
buffer, buffer + frames_count,
|
||||
rhs.buffer
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
@@ -23,6 +23,14 @@ struct backtrace_holder {
|
||||
inline std::string get_frame(std::size_t /*frame*/) const {
|
||||
return std::string();
|
||||
}
|
||||
|
||||
inline bool operator< (const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool operator==(const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
@@ -79,6 +79,32 @@ struct backtrace_holder {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
inline bool operator< (const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return frames_count < rhs.frames_count;
|
||||
} else if (this == &rhs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::lexicographical_compare(
|
||||
buffer, buffer + frames_count,
|
||||
rhs.buffer, rhs.buffer + rhs.frames_count
|
||||
);
|
||||
}
|
||||
|
||||
inline bool operator==(const backtrace_holder& rhs) const BOOST_NOEXCEPT {
|
||||
if (frames_count != rhs.frames_count) {
|
||||
return false;
|
||||
} else if (this == &rhs) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return std::equal(
|
||||
buffer, buffer + frames_count,
|
||||
rhs.buffer
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
}}} // namespace boost::stacktrace::detail
|
||||
|
||||
@@ -53,6 +53,13 @@ std::string stacktrace::operator[](std::size_t frame) const {
|
||||
return impl_.get_frame(frame);
|
||||
}
|
||||
|
||||
bool stacktrace::operator< (const stacktrace& rhs) const BOOST_NOEXCEPT {
|
||||
return impl_ < rhs.impl_;
|
||||
}
|
||||
|
||||
bool stacktrace::operator==(const stacktrace& rhs) const BOOST_NOEXCEPT {
|
||||
return impl_ == rhs.impl_;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user