forked from OctaForge/libostd
make put() on OutputRanges return bool
This commit is contained in:
parent
f36c35afae
commit
a23525bacf
|
@ -166,7 +166,7 @@ struct IsInfiniteRandomAccessRange: IntegralConstant<bool,
|
||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T, typename P>
|
template<typename T, typename P>
|
||||||
struct OutputRangeTest {
|
struct OutputRangeTest {
|
||||||
template<typename U, void (U::*)(P)> struct Test {};
|
template<typename U, bool (U::*)(P)> struct Test {};
|
||||||
template<typename U> static char test(Test<U, &U::put> *);
|
template<typename U> static char test(Test<U, &U::put> *);
|
||||||
template<typename U> static int test(...);
|
template<typename U> static int test(...);
|
||||||
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
||||||
|
@ -559,11 +559,11 @@ public:
|
||||||
return p_beg[idx];
|
return p_beg[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
void put(const RangeValue<Rtype> &v) {
|
bool put(const RangeValue<Rtype> &v) {
|
||||||
p_beg.range().put(v);
|
return p_beg.range().put(v);
|
||||||
}
|
}
|
||||||
void put(RangeValue<Rtype> &&v) {
|
bool put(RangeValue<Rtype> &&v) {
|
||||||
p_beg.range().put(octa::move(v));
|
return p_beg.range().put(octa::move(v));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -714,8 +714,8 @@ public:
|
||||||
return MoveRange<T>(p_range.slice(start, end));
|
return MoveRange<T>(p_range.slice(start, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
void put(const Rval &v) { p_range.put(v); }
|
bool put(const Rval &v) { return p_range.put(v); }
|
||||||
void put(Rval &&v) { p_range.put(octa::move(v)); }
|
bool put(Rval &&v) { return p_range.put(octa::move(v)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -847,11 +847,15 @@ struct PointerRange: InputRange<PointerRange<T>, FiniteRandomAccessRangeTag, T>
|
||||||
T &operator[](octa::Size i) const { return p_beg[i]; }
|
T &operator[](octa::Size i) const { return p_beg[i]; }
|
||||||
|
|
||||||
/* satisfy OutputRange */
|
/* satisfy OutputRange */
|
||||||
void put(const T &v) {
|
bool put(const T &v) {
|
||||||
|
if (empty()) return false;
|
||||||
*(p_beg++) = v;
|
*(p_beg++) = v;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
void put(T &&v) {
|
bool put(T &&v) {
|
||||||
|
if (empty()) return false;
|
||||||
*(p_beg++) = octa::move(v);
|
*(p_beg++) = octa::move(v);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -40,7 +40,13 @@ namespace detail {
|
||||||
FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {}
|
FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {}
|
||||||
char *buf;
|
char *buf;
|
||||||
octa::Size idx;
|
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<T, true>: InputRange<
|
||||||
return p_stream->tell() == s.p_stream->tell();
|
return p_stream->tell() == s.p_stream->tell();
|
||||||
}
|
}
|
||||||
|
|
||||||
void put(T val) {
|
bool put(T val) {
|
||||||
p_size += p_stream->write_bytes(&val, sizeof(T));
|
octa::Size v = p_stream->write_bytes(&val, sizeof(T));
|
||||||
|
p_size += v;
|
||||||
|
return (v == sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -118,9 +118,10 @@ struct StringRangeBase: InputRange<
|
||||||
|
|
||||||
T &operator[](octa::Size i) const { return p_beg[i]; }
|
T &operator[](octa::Size i) const { return p_beg[i]; }
|
||||||
|
|
||||||
void put(T v) {
|
bool put(T v) {
|
||||||
if (empty()) return;
|
if (empty()) return false;
|
||||||
*(p_beg++) = v;
|
*(p_beg++) = v;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* non-range methods */
|
/* non-range methods */
|
||||||
|
|
Loading…
Reference in a new issue