0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 08:42:34 +01:00

ircd::buffer: Add operator+ to compute a new buffer at offset.

This commit is contained in:
Jason Volk 2018-02-19 14:01:00 -08:00
parent e9a84ff4d7
commit 622e0a56a6

View file

@ -61,6 +61,7 @@ namespace ircd::buffer
template<class it> size_t size(const buffer<it> &buffer);
template<class it> const it &data(const buffer<it> &buffer);
template<class it> size_t consume(buffer<it> &buffer, const size_t &bytes);
template<class it> buffer<it> operator+(const buffer<it> &buffer, const size_t &bytes);
template<class it> it copy(it &dest, const it &stop, const const_buffer &);
size_t copy(const mutable_buffer &dst, const const_buffer &src);
size_t reverse(const mutable_buffer &dst, const const_buffer &src);
@ -564,6 +565,22 @@ ircd::buffer::copy(it &dest,
return ret;
}
template<class it>
ircd::buffer::buffer<it>
ircd::buffer::operator+(const buffer<it> &buffer,
const size_t &bytes)
{
const size_t advance
{
std::min(bytes, size(buffer))
};
return
{
begin(buffer) + advance, size(buffer) - advance
};
}
template<class it>
size_t
ircd::buffer::consume(buffer<it> &buffer,