diff --git a/octa/range.hh b/octa/range.hh index ab5bcd4..a6358bb 100644 --- a/octa/range.hh +++ b/octa/range.hh @@ -166,7 +166,7 @@ struct IsInfiniteRandomAccessRange: IntegralConstant struct OutputRangeTest { - template struct Test {}; + template struct Test {}; template static char test(Test *); template static int test(...); static constexpr bool value = (sizeof(test(0)) == sizeof(char)); @@ -559,11 +559,11 @@ public: return p_beg[idx]; } - void put(const RangeValue &v) { - p_beg.range().put(v); + bool put(const RangeValue &v) { + return p_beg.range().put(v); } - void put(RangeValue &&v) { - p_beg.range().put(octa::move(v)); + bool put(RangeValue &&v) { + return p_beg.range().put(octa::move(v)); } }; @@ -714,8 +714,8 @@ public: return MoveRange(p_range.slice(start, end)); } - void put(const Rval &v) { p_range.put(v); } - void put(Rval &&v) { p_range.put(octa::move(v)); } + bool put(const Rval &v) { return p_range.put(v); } + bool put(Rval &&v) { return p_range.put(octa::move(v)); } }; template @@ -847,11 +847,15 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> T &operator[](octa::Size i) const { return p_beg[i]; } /* satisfy OutputRange */ - void put(const T &v) { + bool put(const T &v) { + if (empty()) return false; *(p_beg++) = v; + return true; } - void put(T &&v) { + bool put(T &&v) { + if (empty()) return false; *(p_beg++) = octa::move(v); + return true; } private: diff --git a/octa/stream.hh b/octa/stream.hh index f60a082..5ff90c3 100644 --- a/octa/stream.hh +++ b/octa/stream.hh @@ -40,7 +40,13 @@ namespace detail { FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {} char *buf; octa::Size idx; - void put(char v) { if (idx < N) buf[idx++] = v; } + bool put(char v) { + if (idx < N) { + buf[idx++] = v; + return true; + } + return false; + } }; } @@ -198,8 +204,10 @@ struct StreamRange: InputRange< return p_stream->tell() == s.p_stream->tell(); } - void put(T val) { - p_size += p_stream->write_bytes(&val, sizeof(T)); + bool put(T val) { + octa::Size v = p_stream->write_bytes(&val, sizeof(T)); + p_size += v; + return (v == sizeof(T)); } private: diff --git a/octa/string.hh b/octa/string.hh index e8877dd..bd6f9f7 100644 --- a/octa/string.hh +++ b/octa/string.hh @@ -118,9 +118,10 @@ struct StringRangeBase: InputRange< T &operator[](octa::Size i) const { return p_beg[i]; } - void put(T v) { - if (empty()) return; + bool put(T v) { + if (empty()) return false; *(p_beg++) = v; + return true; } /* non-range methods */