build the sockaddr_un without copy
[ghsmtp.git] / iobuffer.hpp
blob2500ac4b937ef99271e6b4563035c8476a80ce2e
1 #ifndef IOBUFFER_DOT_HPP
2 #define IOBUFFER_DOT_HPP
4 #include "default_init_allocator.hpp"
6 #include <cstddef>
7 #include <vector>
9 template <typename ByteT = std::byte>
10 class iobuffer {
11 public:
12 using buffer_t = std::vector<ByteT, default_init_allocator<ByteT>>;
13 using size_type = typename buffer_t::size_type;
15 iobuffer() = default;
16 explicit iobuffer(size_type sz)
17 : buf_(sz)
21 auto data() { return buf_.data(); }
22 auto data() const { return buf_.data(); }
23 auto size() const { return buf_.size(); }
24 auto resize(size_type sz) { return buf_.resize(sz); }
25 void shrink_to_fit() { buf_.shrink_to_fit(); }
27 auto begin() const { return buf_.begin(); }
28 auto end() const { return buf_.end(); }
30 bool operator==(iobuffer const& rhs) const
32 if (this->size() == rhs.size())
33 return memcmp(this->data(), rhs.data(), this->size()) == 0;
34 return false;
37 bool operator<(iobuffer const& rhs) const
39 if (this->size() == rhs.size())
40 return memcmp(this->data(), rhs.data(), this->size()) < 0;
41 return this->size() < rhs.size();
44 private:
45 buffer_t buf_;
48 #endif // IOBUFFER_DOT_HPP