diff options
Diffstat (limited to 'include/cppbor/cppbor.h')
-rw-r--r-- | include/cppbor/cppbor.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/include/cppbor/cppbor.h b/include/cppbor/cppbor.h index f7a2af0..e0962db 100644 --- a/include/cppbor/cppbor.h +++ b/include/cppbor/cppbor.h @@ -16,12 +16,14 @@ #pragma once +#include <algorithm> #include <cassert> #include <cstdint> #include <functional> #include <iterator> #include <memory> #include <numeric> +#include <span> #include <string> #include <string_view> #include <vector> @@ -440,7 +442,7 @@ class Bstr : public Item { }; /** - * ViewBstr is a read-only version of Bstr backed by std::string_view + * ViewBstr is a read-only version of Bstr backed by std::span */ class ViewBstr : public Item { public: @@ -449,8 +451,8 @@ class ViewBstr : public Item { // Construct an empty ViewBstr explicit ViewBstr() {} - // Construct from a string_view of uint8_t values - explicit ViewBstr(std::basic_string_view<uint8_t> v) : mView(std::move(v)) {} + // Construct from a span of uint8_t values + explicit ViewBstr(std::span<const uint8_t> v) : mView(std::move(v)) {} // Construct from a string_view explicit ViewBstr(std::string_view v) @@ -466,7 +468,9 @@ class ViewBstr : public Item { ViewBstr(const uint8_t* begin, const uint8_t* end) : mView(begin, std::distance(begin, end)) {} - bool operator==(const ViewBstr& other) const& { return mView == other.mView; } + bool operator==(const ViewBstr& other) const& { + return std::equal(mView.begin(), mView.end(), other.mView.begin(), other.mView.end()); + } MajorType type() const override { return kMajorType; } using Item::asViewBstr; @@ -479,14 +483,14 @@ class ViewBstr : public Item { encodeValue(encodeCallback); } - const std::basic_string_view<uint8_t>& view() const { return mView; } + const std::span<const uint8_t>& view() const { return mView; } std::unique_ptr<Item> clone() const override { return std::make_unique<ViewBstr>(mView); } private: void encodeValue(EncodeCallback encodeCallback) const; - std::basic_string_view<uint8_t> mView; + std::span<const uint8_t> mView; }; /** |