1 #ifndef PROTOZERO_DATA_VIEW_HPP 2 #define PROTOZERO_DATA_VIEW_HPP 29 #ifdef PROTOZERO_USE_VIEW 30 using data_view = PROTOZERO_USE_VIEW;
41 const char* m_data =
nullptr;
42 std::size_t m_size = 0;
57 constexpr
data_view(
const char* ptr, std::size_t length) noexcept
79 m_size(std::strlen(ptr)) {
89 swap(m_data, other.m_data);
90 swap(m_size, other.m_size);
94 constexpr
const char*
data() const noexcept {
99 constexpr std::size_t
size() const noexcept {
104 constexpr
bool empty() const noexcept {
108 #ifndef PROTOZERO_STRICT_API 119 protozero_assert(m_data);
120 return {m_data, m_size};
129 explicit operator std::string()
const {
130 protozero_assert(m_data);
131 return {m_data, m_size};
145 protozero_assert(m_data && other.m_data);
146 const int cmp = std::memcmp(
data(), other.
data(),
152 return size() < other.
size() ? -1 : 1;
177 return lhs.size() == rhs.size() &&
178 std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data());
189 return !(lhs == rhs);
199 return lhs.compare(rhs) < 0;
209 return lhs.compare(rhs) <= 0;
219 return lhs.compare(rhs) > 0;
229 return lhs.compare(rhs) >= 0;
236 #endif // PROTOZERO_DATA_VIEW_HPP int compare(data_view other) const
Definition: data_view.hpp:144
constexpr bool operator==(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:176
constexpr bool empty() const noexcept
Returns true if size is 0.
Definition: data_view.hpp:104
data_view(const std::string &str) noexcept
Definition: data_view.hpp:67
std::string to_string() const
Definition: data_view.hpp:118
Contains macro checks for different configurations.
bool operator<=(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:208
bool operator>=(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:228
constexpr std::size_t size() const noexcept
Return length of data in bytes.
Definition: data_view.hpp:99
data_view(const char *ptr) noexcept
Definition: data_view.hpp:77
constexpr data_view() noexcept=default
bool operator<(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:198
bool operator>(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:218
void swap(data_view &other) noexcept
Definition: data_view.hpp:87
Definition: data_view.hpp:39
constexpr bool operator!=(const data_view lhs, const data_view rhs) noexcept
Definition: data_view.hpp:188
constexpr const char * data() const noexcept
Return pointer to data.
Definition: data_view.hpp:94
constexpr data_view(const char *ptr, std::size_t length) noexcept
Definition: data_view.hpp:57
All parts of the protozero header-only library are in this namespace.
Definition: byteswap.hpp:23
void swap(data_view &lhs, data_view &rhs) noexcept
Definition: data_view.hpp:165