From 072dce88919af298800862c6fd9e4959bf1741d0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 19 Dec 2018 17:13:06 +1100 Subject: [PATCH] io: ensure write/pwrite views use pointer iterators --- io.hpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/io.hpp b/io.hpp index 37f78308..bf8aef17 100644 --- a/io.hpp +++ b/io.hpp @@ -9,6 +9,7 @@ #ifndef __UTIL_IO_HPP #define __UTIL_IO_HPP +#include "std.hpp" #include "platform.hpp" #include "posix/fd.hpp" @@ -67,25 +68,23 @@ namespace cruft { /// /// An exception may be throw in the event forward progress is impossible /// (depending on the supplied FunctionT). + /// + /// TODO: enforce constness of view iterators template < typename DstT, typename FunctionT, - typename IteratorA, - typename IteratorB, + typename ValueT, typename ...Args > [[nodiscard]] decltype(auto) drain ( DstT &&dst, FunctionT &&func, - cruft::view const &src, + cruft::view const &src, Args&& ...args ) { - static_assert (std::is_pointer_v); - static_assert (std::is_pointer_v); - - auto cursor = reinterpret_cast (src.data ()); - auto remain = src.size (); + auto cursor = reinterpret_cast (src.data ()); + auto remain = src.size () * sizeof (ValueT); while (remain) { auto count = std::invoke (func, dst, cursor, remain, args...); @@ -105,11 +104,10 @@ namespace cruft { /// to `src`. template < typename DstT, - typename IteratorA, - typename IteratorB + typename ValueT > decltype(auto) - write (DstT &&dst, const cruft::view &src) + write (DstT &&dst, cruft::view const &src) { constexpr auto func = &std::decay_t::write; return drain (std::forward (dst), func, src); @@ -124,11 +122,10 @@ namespace cruft { /// to `src`. template < typename DstT, - typename IteratorA, - typename IteratorB + typename ValueT > decltype(auto) - pwrite (DstT &&dst, const cruft::view &src, size_t offset) + pwrite (DstT &&dst, cruft::view const &src, size_t offset) { return drain (std::forward (dst), &std::decay_t::pwrite, src, offset); }