您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

64 行
1.6KB

  1. #pragma once
  2. #include <neo/base_buffer.hpp>
  3. #include <neo/mutable_buffer.hpp>
  4. #include <cassert>
  5. #include <cstddef>
  6. #include <string_view>
  7. namespace neo {
  8. /**
  9. * A type that represents a view to a readonly segment of contiguous memory.
  10. */
  11. class const_buffer {
  12. public:
  13. using pointer = const std::byte*;
  14. using size_type = std::size_t;
  15. private:
  16. pointer _data = nullptr;
  17. size_type _size = 0;
  18. public:
  19. constexpr const_buffer() noexcept = default;
  20. constexpr const_buffer(pointer ptr, size_type size) noexcept
  21. : _data(ptr)
  22. , _size(size) {}
  23. constexpr const_buffer(mutable_buffer buf)
  24. : _data(buf.data())
  25. , _size(buf.size()) {}
  26. explicit constexpr const_buffer(std::string_view sv)
  27. : _data(byte_pointer(sv.data()))
  28. , _size(sv.size()) {}
  29. constexpr pointer data() const noexcept { return _data; }
  30. constexpr pointer data_end() const noexcept { return _data + size(); }
  31. constexpr size_type size() const noexcept { return _size; }
  32. constexpr const_buffer& operator+=(size_type s) noexcept {
  33. assert(s <= size() && "Advanced neo::const_buffer past-the-end");
  34. _data += s;
  35. _size -= s;
  36. return *this;
  37. }
  38. };
  39. inline constexpr const_buffer operator+(const_buffer buf, const_buffer::size_type s) noexcept {
  40. auto copy = buf;
  41. copy += s;
  42. return copy;
  43. }
  44. inline constexpr auto _impl_buffer_sequence_begin(const_buffer buf) noexcept {
  45. return detail::single_buffer_iter(buf);
  46. }
  47. inline constexpr auto _impl_buffer_sequence_end(const_buffer) noexcept {
  48. return detail::single_buffer_iter_sentinel();
  49. }
  50. } // namespace neo