From 213826d06cb69091b8c1605f7af321651b92c17f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 7 May 2018 14:44:31 -0700 Subject: [PATCH] ircd::buffer: Add convenience closure overload to window_buffer. --- include/ircd/buffer/window_buffer.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/ircd/buffer/window_buffer.h b/include/ircd/buffer/window_buffer.h index c7db384ec..02499dc64 100644 --- a/include/ircd/buffer/window_buffer.h +++ b/include/ircd/buffer/window_buffer.h @@ -25,6 +25,7 @@ struct ircd::buffer::window_buffer :mutable_buffer { using closure = std::function; + using closure_cbuf = std::function; mutable_buffer base; @@ -35,7 +36,8 @@ struct ircd::buffer::window_buffer explicit operator const_buffer() const; 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 shift(const size_t &n); @@ -84,6 +86,16 @@ ircd::buffer::window_buffer::rewind(const size_t &n) 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 ircd::buffer::window_buffer::operator()(const closure &closure) {