0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::buffer: Add convenience closure overload to window_buffer.

This commit is contained in:
Jason Volk 2018-05-07 14:44:31 -07:00
parent 1d3f92069f
commit 213826d06c

View file

@ -25,6 +25,7 @@ struct ircd::buffer::window_buffer
:mutable_buffer :mutable_buffer
{ {
using closure = std::function<size_t (const mutable_buffer &)>; using closure = std::function<size_t (const mutable_buffer &)>;
using closure_cbuf = std::function<const_buffer (const mutable_buffer &)>;
mutable_buffer base; mutable_buffer base;
@ -35,7 +36,8 @@ struct ircd::buffer::window_buffer
explicit operator const_buffer() const; explicit operator const_buffer() const;
mutable_buffer completed(); mutable_buffer completed();
const_buffer operator()(const closure &closure); const_buffer operator()(const closure &);
const_buffer operator()(const closure_cbuf &);
const_buffer rewind(const size_t &n = 1); const_buffer rewind(const size_t &n = 1);
const_buffer shift(const size_t &n); const_buffer shift(const size_t &n);
@ -84,6 +86,16 @@ ircd::buffer::window_buffer::rewind(const size_t &n)
return completed(); return completed();
} }
inline ircd::buffer::const_buffer
ircd::buffer::window_buffer::operator()(const closure_cbuf &closure)
{
return operator()([&closure]
(const mutable_buffer &buf)
{
return size(closure(buf));
});
}
inline ircd::buffer::const_buffer inline ircd::buffer::const_buffer
ircd::buffer::window_buffer::operator()(const closure &closure) ircd::buffer::window_buffer::operator()(const closure &closure)
{ {