From ad916e61c9187067de3f0eaf255f2680d9fc8d9b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 19 Jun 2019 12:00:47 +1000 Subject: [PATCH] io: add iterative file reading helper --- io.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/io.hpp b/io.hpp index bf8aef17..347a67c5 100644 --- a/io.hpp +++ b/io.hpp @@ -131,6 +131,24 @@ namespace cruft { } + ///------------------------------------------------------------------------ + /// Read the number of bytes covered by the destination view from the + /// source descriptor. + template + decltype (auto) + read (SrcT &&src, cruft::view dst) + { + auto remain = dst; + + while (!remain.empty ()) { + auto const count = src.read (remain.begin (), remain.size () * sizeof (decltype(dst)::value_type)); + remain = remain.consume (count); + } + + return dst; + } + + /////////////////////////////////////////////////////////////////////////// class indenter : public std::streambuf { protected: