diff --git a/ostd/range.hh b/ostd/range.hh index b959e21..3ea889a 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -1731,9 +1731,20 @@ struct iterator_range: input_range> { /* satisfy output_range */ void put(value_type const &v) { + /* rely on iterators to do their own checks */ + if constexpr(std::is_pointer_v) { + if (p_beg == p_end) { + throw std::out_of_range{"put into an empty range"}; + } + } *(p_beg++) = v; } void put(value_type &&v) { + if constexpr(std::is_pointer_v) { + if (p_beg == p_end) { + throw std::out_of_range{"put into an empty range"}; + } + } *(p_beg++) = std::move(v); } diff --git a/ostd/string.hh b/ostd/string.hh index 648c945..10227eb 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -148,6 +148,9 @@ public: T &operator[](size_t i) const { return p_beg[i]; } void put(T v) { + if (p_beg == p_end) { + throw std::out_of_range{"put into an empty range"}; + } *(p_beg++) = v; }