use size_t and ptrdiff_t
parent
1db7529ad9
commit
2884f4b47b
|
@ -22,7 +22,7 @@ namespace detail {
|
|||
using func_t = std::function<void(C &, A...)>;
|
||||
byte *bufp = new byte[sizeof(func_t) * p_nfuncs];
|
||||
func_t *nbuf = reinterpret_cast<func_t *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i)
|
||||
for (size_t i = 0; i < p_nfuncs; ++i)
|
||||
new (&nbuf[i]) func_t(ev.p_funcs[i]);
|
||||
p_funcs = nbuf;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace detail {
|
|||
p_nfuncs = ev.p_nfuncs;
|
||||
byte *bufp = new byte[sizeof(func_t) * p_nfuncs];
|
||||
func_t *nbuf = reinterpret_cast<func_t *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
for (size_t i = 0; i < p_nfuncs; ++i) {
|
||||
new (&nbuf[i]) func_t(ev.p_funcs[i]);
|
||||
}
|
||||
p_funcs = nbuf;
|
||||
|
@ -54,7 +54,7 @@ namespace detail {
|
|||
~SignalBase() { clear(); }
|
||||
|
||||
void clear() {
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
for (size_t i = 0; i < p_nfuncs; ++i) {
|
||||
using func = std::function<void(C &, A...)>;
|
||||
p_funcs[i].~func();
|
||||
}
|
||||
|
@ -64,9 +64,9 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename F>
|
||||
Size connect(F &&func) {
|
||||
size_t connect(F &&func) {
|
||||
using func_t = std::function<void(C &, A...)>;
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
for (size_t i = 0; i < p_nfuncs; ++i) {
|
||||
if (!p_funcs[i]) {
|
||||
p_funcs[i] = std::forward<F>(func);
|
||||
return i;
|
||||
|
@ -74,7 +74,7 @@ namespace detail {
|
|||
}
|
||||
byte *bufp = new byte[sizeof(func_t) * (p_nfuncs + 1)];
|
||||
func_t *nbuf = reinterpret_cast<func_t *>(bufp);
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
for (size_t i = 0; i < p_nfuncs; ++i) {
|
||||
new (&nbuf[i]) func_t(std::move(p_funcs[i]));
|
||||
p_funcs[i].~func_t();
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ namespace detail {
|
|||
return p_nfuncs++;
|
||||
}
|
||||
|
||||
bool disconnect(Size idx) {
|
||||
bool disconnect(size_t idx) {
|
||||
if ((idx >= p_nfuncs) || !p_funcs[idx]) {
|
||||
return false;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace detail {
|
|||
if (!p_class) {
|
||||
return;
|
||||
}
|
||||
for (Size i = 0; i < p_nfuncs; ++i) {
|
||||
for (size_t i = 0; i < p_nfuncs; ++i) {
|
||||
if (p_funcs[i]) {
|
||||
p_funcs[i](*p_class, args...);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ namespace detail {
|
|||
private:
|
||||
C *p_class;
|
||||
std::function<void(C &, A...)> *p_funcs;
|
||||
Size p_nfuncs;
|
||||
size_t p_nfuncs;
|
||||
};
|
||||
} /* namespace detail */
|
||||
|
||||
|
@ -151,9 +151,9 @@ public:
|
|||
void clear() { p_base.clear(); }
|
||||
|
||||
template<typename F>
|
||||
Size connect(F &&func) { return p_base.connect(std::forward<F>(func)); }
|
||||
size_t connect(F &&func) { return p_base.connect(std::forward<F>(func)); }
|
||||
|
||||
bool disconnect(Size idx) { return p_base.disconnect(idx); }
|
||||
bool disconnect(size_t idx) { return p_base.disconnect(idx); }
|
||||
|
||||
template<typename ...Args>
|
||||
void emit(Args &&...args) { p_base.emit(std::forward<Args>(args)...); }
|
||||
|
@ -190,9 +190,9 @@ public:
|
|||
void clear() { p_base.clear(); }
|
||||
|
||||
template<typename F>
|
||||
Size connect(F &&func) { return p_base.connect(std::forward<F>(func)); }
|
||||
size_t connect(F &&func) { return p_base.connect(std::forward<F>(func)); }
|
||||
|
||||
bool disconnect(Size idx) { return p_base.disconnect(idx); }
|
||||
bool disconnect(size_t idx) { return p_base.disconnect(idx); }
|
||||
|
||||
template<typename ...Args>
|
||||
void emit(Args &&...args) const { p_base.emit(std::forward<Args>(args)...); }
|
||||
|
|
|
@ -50,12 +50,12 @@ inline SDL_RWops *stream_to_rwops(Stream &s) {
|
|||
return -1;
|
||||
};
|
||||
|
||||
rwr->read = [](SDL_RWops *rw, void *buf, Size size, Size nb) -> Size {
|
||||
rwr->read = [](SDL_RWops *rw, void *buf, size_t size, size_t nb) -> size_t {
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
return is->read_bytes(buf, size * nb) / size;
|
||||
};
|
||||
|
||||
rwr->write = [](SDL_RWops *rw, const void *buf, Size size, Size nb) -> Size {
|
||||
rwr->write = [](SDL_RWops *rw, const void *buf, size_t size, size_t nb) -> size_t {
|
||||
Stream *is = static_cast<Stream *>(rw->hidden.unknown.data1);
|
||||
return is->write_bytes(buf, size * nb) / size;
|
||||
};
|
||||
|
|
|
@ -215,7 +215,7 @@ private:
|
|||
#endif
|
||||
}
|
||||
|
||||
Size p_slash = std::string::npos, p_dot = std::string::npos;
|
||||
size_t p_slash = std::string::npos, p_dot = std::string::npos;
|
||||
FileType p_type = FileType::unknown;
|
||||
std::string p_path;
|
||||
|
||||
|
@ -531,7 +531,7 @@ inline void swap(DirectoryStream &a, DirectoryStream &b) {
|
|||
}
|
||||
|
||||
struct DirectoryRange: InputRange<
|
||||
DirectoryRange, InputRangeTag, FileInfo, FileInfo, Size, long
|
||||
DirectoryRange, InputRangeTag, FileInfo, FileInfo, size_t, long
|
||||
> {
|
||||
DirectoryRange() = delete;
|
||||
DirectoryRange(DirectoryStream &s): p_stream(&s) {}
|
||||
|
@ -567,7 +567,7 @@ inline DirectoryRange DirectoryStream::iter() {
|
|||
}
|
||||
|
||||
namespace detail {
|
||||
template<Size I>
|
||||
template<size_t I>
|
||||
struct PathJoin {
|
||||
template<typename T, typename ...A>
|
||||
static void join(std::string &s, T const &a, A const &...b) {
|
||||
|
|
148
ostd/format.hh
148
ostd/format.hh
|
@ -43,8 +43,8 @@ namespace detail {
|
|||
return ret;
|
||||
}
|
||||
|
||||
inline Size read_digits(ConstCharRange &fmt, char *buf) {
|
||||
Size ret = 0;
|
||||
inline size_t read_digits(ConstCharRange &fmt, char *buf) {
|
||||
size_t ret = 0;
|
||||
for (; !fmt.empty() && isdigit(fmt.front()); ++ret) {
|
||||
*buf++ = fmt.front();
|
||||
fmt.pop_front();
|
||||
|
@ -127,7 +127,7 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool get_arg_param(Size idx, int ¶m, T const &val) {
|
||||
bool get_arg_param(size_t idx, int ¶m, T const &val) {
|
||||
if (idx) {
|
||||
assert(false && "not enough format args");
|
||||
return false;
|
||||
|
@ -135,7 +135,7 @@ namespace detail {
|
|||
return convert_arg_param(val, param);
|
||||
}
|
||||
template<typename T, typename ...A>
|
||||
bool get_arg_param(Size idx, int ¶m, T const &val, A const &...args) {
|
||||
bool get_arg_param(size_t idx, int ¶m, T const &val, A const &...args) {
|
||||
if (idx) {
|
||||
return get_arg_param(idx - 1, param, args...);
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ struct FormatSpec {
|
|||
{}
|
||||
|
||||
template<typename R>
|
||||
bool read_until_spec(R &writer, Size *wret) {
|
||||
Size written = 0;
|
||||
bool read_until_spec(R &writer, size_t *wret) {
|
||||
size_t written = 0;
|
||||
if (wret) {
|
||||
*wret = 0;
|
||||
}
|
||||
|
@ -182,7 +182,7 @@ struct FormatSpec {
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
Size write_spaces(R &writer, Size n, bool left, char c = ' ') const {
|
||||
size_t write_spaces(R &writer, size_t n, bool left, char c = ' ') const {
|
||||
if (left == bool(p_flags & FMT_FLAG_DASH)) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -199,8 +199,8 @@ struct FormatSpec {
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
Size build_spec(R &&out, ConstCharRange spec) {
|
||||
Size ret = out.put('%');
|
||||
size_t build_spec(R &&out, ConstCharRange spec) {
|
||||
size_t ret = out.put('%');
|
||||
if (p_flags & FMT_FLAG_DASH ) {
|
||||
ret += out.put('-');
|
||||
}
|
||||
|
@ -231,12 +231,12 @@ struct FormatSpec {
|
|||
bool arg_precision() const { return p_arg_precision; }
|
||||
|
||||
template<typename ...A>
|
||||
bool set_width(Size idx, A const &...args) {
|
||||
bool set_width(size_t idx, A const &...args) {
|
||||
return detail::get_arg_param(idx, p_width, args...);
|
||||
}
|
||||
|
||||
template<typename ...A>
|
||||
bool set_precision(Size idx, A const &...args) {
|
||||
bool set_precision(size_t idx, A const &...args) {
|
||||
return detail::get_arg_param(idx, p_precision, args...);
|
||||
}
|
||||
|
||||
|
@ -348,7 +348,7 @@ protected:
|
|||
}
|
||||
|
||||
bool read_spec() {
|
||||
Size ndig = detail::read_digits(p_fmt, p_buf);
|
||||
size_t ndig = detail::read_digits(p_fmt, p_buf);
|
||||
|
||||
bool havepos = false;
|
||||
p_index = 0;
|
||||
|
@ -364,11 +364,11 @@ protected:
|
|||
|
||||
/* parse flags */
|
||||
p_flags = 0;
|
||||
Size skipd = 0;
|
||||
size_t skipd = 0;
|
||||
if (havepos || !ndig) {
|
||||
p_flags = detail::parse_fmt_flags(p_fmt, 0);
|
||||
} else {
|
||||
for (Size i = 0; i < ndig; ++i) {
|
||||
for (size_t i = 0; i < ndig; ++i) {
|
||||
if (p_buf[i] != '0') {
|
||||
break;
|
||||
}
|
||||
|
@ -449,10 +449,10 @@ inline bool to_format(T const &v, R &writer, FormatSpec const &fs) {
|
|||
|
||||
namespace detail {
|
||||
template<typename R, typename T>
|
||||
inline Ptrdiff write_u(R &writer, FormatSpec const *fl, bool neg, T val) {
|
||||
inline ptrdiff_t write_u(R &writer, FormatSpec const *fl, bool neg, T val) {
|
||||
char buf[20];
|
||||
Ptrdiff r = 0;
|
||||
Size n = 0;
|
||||
ptrdiff_t r = 0;
|
||||
size_t n = 0;
|
||||
|
||||
char spec = fl->spec();
|
||||
if (spec == 's') spec = 'd';
|
||||
|
@ -505,16 +505,16 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename ...A>
|
||||
static Ptrdiff format_impl(
|
||||
R &writer, Size &fmtn, bool escape,
|
||||
static ptrdiff_t format_impl(
|
||||
R &writer, size_t &fmtn, bool escape,
|
||||
ConstCharRange fmt, A const &...args
|
||||
);
|
||||
|
||||
template<Size I>
|
||||
template<size_t I>
|
||||
struct FmtTupleUnpacker {
|
||||
template<typename R, typename T, typename ...A>
|
||||
static inline Ptrdiff unpack(
|
||||
R &writer, Size &fmtn, bool esc, ConstCharRange fmt,
|
||||
static inline ptrdiff_t unpack(
|
||||
R &writer, size_t &fmtn, bool esc, ConstCharRange fmt,
|
||||
T const &item, A const &...args
|
||||
) {
|
||||
return FmtTupleUnpacker<I - 1>::unpack(
|
||||
|
@ -526,8 +526,8 @@ namespace detail {
|
|||
template<>
|
||||
struct FmtTupleUnpacker<0> {
|
||||
template<typename R, typename T, typename ...A>
|
||||
static inline Ptrdiff unpack(
|
||||
R &writer, Size &fmtn, bool esc, ConstCharRange fmt,
|
||||
static inline ptrdiff_t unpack(
|
||||
R &writer, size_t &fmtn, bool esc, ConstCharRange fmt,
|
||||
T const &, A const &...args
|
||||
) {
|
||||
return format_impl(writer, fmtn, esc, fmt, args...);
|
||||
|
@ -547,16 +547,16 @@ namespace detail {
|
|||
constexpr bool is_tuple_like = decltype(tuple_like_test<T>(0))::value;
|
||||
|
||||
template<typename R, typename T>
|
||||
inline Ptrdiff format_ritem(
|
||||
R &writer, Size &fmtn, bool esc, bool, ConstCharRange fmt,
|
||||
inline ptrdiff_t format_ritem(
|
||||
R &writer, size_t &fmtn, bool esc, bool, ConstCharRange fmt,
|
||||
T const &item, EnableIf<!is_tuple_like<T>, bool> = true
|
||||
) {
|
||||
return format_impl(writer, fmtn, esc, fmt, item);
|
||||
}
|
||||
|
||||
template<typename R, typename T>
|
||||
inline Ptrdiff format_ritem(
|
||||
R &writer, Size &fmtn, bool esc, bool expandval, ConstCharRange fmt,
|
||||
inline ptrdiff_t format_ritem(
|
||||
R &writer, size_t &fmtn, bool esc, bool expandval, ConstCharRange fmt,
|
||||
T const &item, EnableIf<is_tuple_like<T>, bool> = true
|
||||
) {
|
||||
if (expandval) {
|
||||
|
@ -568,7 +568,7 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename T>
|
||||
inline Ptrdiff write_range(
|
||||
inline ptrdiff_t write_range(
|
||||
R &writer, FormatSpec const *fl, bool escape, bool expandval,
|
||||
ConstCharRange sep, T const &val, EnableIf<detail::IterableTest<T>, bool> = true
|
||||
) {
|
||||
|
@ -576,10 +576,10 @@ namespace detail {
|
|||
if (range.empty()) {
|
||||
return 0;
|
||||
}
|
||||
Ptrdiff ret = 0;
|
||||
Size fmtn = 0;
|
||||
ptrdiff_t ret = 0;
|
||||
size_t fmtn = 0;
|
||||
/* test first item */
|
||||
Ptrdiff fret = format_ritem(
|
||||
ptrdiff_t fret = format_ritem(
|
||||
writer, fmtn, escape, expandval, fl->rest(), range.front()
|
||||
);
|
||||
if (fret < 0) {
|
||||
|
@ -606,7 +606,7 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename T>
|
||||
inline Ptrdiff write_range(
|
||||
inline ptrdiff_t write_range(
|
||||
R &, FormatSpec const *, bool, bool, ConstCharRange,
|
||||
T const &, EnableIf<!detail::IterableTest<T>, bool> = true
|
||||
) {
|
||||
|
@ -637,7 +637,7 @@ namespace detail {
|
|||
|
||||
inline char const *escape_fmt_char(char v, char quote) {
|
||||
if ((v >= 0 && v < 0x20) || (v == quote)) {
|
||||
return fmt_escapes[Size(v)];
|
||||
return fmt_escapes[size_t(v)];
|
||||
} else if (v == 0x7F) {
|
||||
return "\\x7F";
|
||||
}
|
||||
|
@ -678,15 +678,15 @@ namespace detail {
|
|||
|
||||
/* string base writer */
|
||||
template<typename R>
|
||||
Ptrdiff write_str(R &writer, bool escape, ConstCharRange val) {
|
||||
ptrdiff_t write_str(R &writer, bool escape, ConstCharRange val) {
|
||||
if (escape) {
|
||||
return write_str(writer, false, escape_fmt_str(val));
|
||||
}
|
||||
Size n = val.size();
|
||||
size_t n = val.size();
|
||||
if (this->precision()) {
|
||||
n = this->precision();
|
||||
}
|
||||
Ptrdiff r = n;
|
||||
ptrdiff_t r = n;
|
||||
r += this->write_spaces(writer, n, true);
|
||||
writer.put_n(&val[0], n);
|
||||
r += this->write_spaces(writer, n, false);
|
||||
|
@ -695,7 +695,7 @@ namespace detail {
|
|||
|
||||
/* any string value */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool escape, T const &val, EnableIf<
|
||||
IsConstructible<ConstCharRange, T const &>, bool
|
||||
> = true
|
||||
|
@ -709,7 +709,7 @@ namespace detail {
|
|||
|
||||
/* character */
|
||||
template<typename R>
|
||||
Ptrdiff write(R &writer, bool escape, char val) {
|
||||
ptrdiff_t write(R &writer, bool escape, char val) {
|
||||
if (this->spec() != 's' && this->spec() != 'c') {
|
||||
assert(false && "cannot print chars with the given spec");
|
||||
return -1;
|
||||
|
@ -719,7 +719,7 @@ namespace detail {
|
|||
if (esc) {
|
||||
char buf[6];
|
||||
buf[0] = '\'';
|
||||
Size elen = strlen(esc);
|
||||
size_t elen = strlen(esc);
|
||||
memcpy(buf + 1, esc, elen);
|
||||
buf[elen + 1] = '\'';
|
||||
/* invoke proper overload via ptr */
|
||||
|
@ -727,7 +727,7 @@ namespace detail {
|
|||
return write(writer, false, bufp, elen + 2);
|
||||
}
|
||||
}
|
||||
Ptrdiff r = 1 + escape * 2;
|
||||
ptrdiff_t r = 1 + escape * 2;
|
||||
r += this->write_spaces(writer, 1 + escape * 2, true);
|
||||
if (escape) {
|
||||
writer.put('\'');
|
||||
|
@ -742,7 +742,7 @@ namespace detail {
|
|||
|
||||
/* bool */
|
||||
template<typename R>
|
||||
Ptrdiff write(R &writer, bool, bool val) {
|
||||
ptrdiff_t write(R &writer, bool, bool val) {
|
||||
if (this->spec() == 's') {
|
||||
return write(writer, ("false\0true") + (6 * val));
|
||||
} else {
|
||||
|
@ -752,7 +752,7 @@ namespace detail {
|
|||
|
||||
/* signed integers */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<
|
||||
IsIntegral<T> && IsSigned<T>, bool
|
||||
> = true
|
||||
|
@ -766,7 +766,7 @@ namespace detail {
|
|||
|
||||
/* unsigned integers */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<
|
||||
IsIntegral<T> && IsUnsigned<T>, bool
|
||||
> = true
|
||||
|
@ -775,7 +775,7 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename T, bool Long = IsSame<T, ldouble>>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T val, EnableIf<IsFloatingPoint<T>, bool> = true
|
||||
) {
|
||||
char buf[16], rbuf[128];
|
||||
|
@ -795,13 +795,13 @@ namespace detail {
|
|||
}
|
||||
|
||||
buf[this->build_spec(iter(buf), fmtspec)] = '\0';
|
||||
Ptrdiff ret = snprintf(
|
||||
ptrdiff_t ret = snprintf(
|
||||
rbuf, sizeof(rbuf), buf, this->width(),
|
||||
this->has_precision() ? this->precision() : 6, val
|
||||
);
|
||||
|
||||
char *dbuf = nullptr;
|
||||
if (Size(ret) >= sizeof(rbuf)) {
|
||||
if (size_t(ret) >= sizeof(rbuf)) {
|
||||
/* this should typically never happen */
|
||||
dbuf = new char[ret + 1];
|
||||
ret = snprintf(
|
||||
|
@ -818,7 +818,7 @@ namespace detail {
|
|||
|
||||
/* pointer value */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T *val, EnableIf<
|
||||
!IsConstructible<ConstCharRange, T *>, bool
|
||||
> = true
|
||||
|
@ -827,12 +827,12 @@ namespace detail {
|
|||
this->p_spec = 'x';
|
||||
this->p_flags |= FMT_FLAG_HASH;
|
||||
}
|
||||
return write(writer, false, Size(val));
|
||||
return write(writer, false, size_t(val));
|
||||
}
|
||||
|
||||
/* generic value */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T const &val, EnableIf<
|
||||
!IsArithmetic<T> &&
|
||||
!IsConstructible<ConstCharRange, T const &> &&
|
||||
|
@ -848,7 +848,7 @@ namespace detail {
|
|||
|
||||
/* custom format case */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &writer, bool, T const &val,
|
||||
EnableIf<FmtTofmtTest<T, TostrRange<R>>, bool> = true
|
||||
) {
|
||||
|
@ -861,7 +861,7 @@ namespace detail {
|
|||
|
||||
/* generic failure case */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write(
|
||||
ptrdiff_t write(
|
||||
R &, bool, T const &, EnableIf<
|
||||
!IsArithmetic<T> &&
|
||||
!IsConstructible<ConstCharRange, T const &> &&
|
||||
|
@ -874,7 +874,7 @@ namespace detail {
|
|||
|
||||
/* actual writer */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write_arg(R &writer, Size idx, T const &val) {
|
||||
ptrdiff_t write_arg(R &writer, size_t idx, T const &val) {
|
||||
if (idx) {
|
||||
assert(false && "not enough format args");
|
||||
return -1;
|
||||
|
@ -883,8 +883,8 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename T, typename ...A>
|
||||
Ptrdiff write_arg(
|
||||
R &writer, Size idx, T const &val, A const &...args
|
||||
ptrdiff_t write_arg(
|
||||
R &writer, size_t idx, T const &val, A const &...args
|
||||
) {
|
||||
if (idx) {
|
||||
return write_arg(writer, idx - 1, args...);
|
||||
|
@ -894,8 +894,8 @@ namespace detail {
|
|||
|
||||
/* range writer */
|
||||
template<typename R, typename T>
|
||||
Ptrdiff write_range(
|
||||
R &writer, Size idx, bool expandval,
|
||||
ptrdiff_t write_range(
|
||||
R &writer, size_t idx, bool expandval,
|
||||
ConstCharRange sep, T const &val
|
||||
) {
|
||||
if (idx) {
|
||||
|
@ -908,8 +908,8 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename T, typename ...A>
|
||||
Ptrdiff write_range(
|
||||
R &writer, Size idx, bool expandval, ConstCharRange sep,
|
||||
ptrdiff_t write_range(
|
||||
R &writer, size_t idx, bool expandval, ConstCharRange sep,
|
||||
T const &val, A const &...args
|
||||
) {
|
||||
if (idx) {
|
||||
|
@ -922,22 +922,22 @@ namespace detail {
|
|||
};
|
||||
|
||||
template<typename R, typename ...A>
|
||||
inline Ptrdiff format_impl(
|
||||
R &writer, Size &fmtn, bool escape, ConstCharRange fmt, A const &...args
|
||||
inline ptrdiff_t format_impl(
|
||||
R &writer, size_t &fmtn, bool escape, ConstCharRange fmt, A const &...args
|
||||
) {
|
||||
Size argidx = 1, retn = 0, twr = 0;
|
||||
Ptrdiff written = 0;
|
||||
size_t argidx = 1, retn = 0, twr = 0;
|
||||
ptrdiff_t written = 0;
|
||||
detail::WriteSpec spec(fmt, escape);
|
||||
while (spec.read_until_spec(writer, &twr)) {
|
||||
written += twr;
|
||||
Size argpos = spec.index();
|
||||
size_t argpos = spec.index();
|
||||
if (spec.is_nested()) {
|
||||
if (!argpos) {
|
||||
argpos = argidx++;
|
||||
}
|
||||
/* FIXME: figure out a better way */
|
||||
detail::WriteSpec nspec(spec.nested(), spec.nested_escape());
|
||||
Ptrdiff sw = nspec.write_range(
|
||||
ptrdiff_t sw = nspec.write_range(
|
||||
writer, argpos - 1, (spec.flags() & FMT_FLAG_HASH),
|
||||
spec.nested_sep(), args...
|
||||
);
|
||||
|
@ -973,7 +973,7 @@ namespace detail {
|
|||
}
|
||||
}
|
||||
if (spec.arg_width()) {
|
||||
if (argpos <= (Size(argprec) + 1)) {
|
||||
if (argpos <= (size_t(argprec) + 1)) {
|
||||
assert(false && "argument width not given");
|
||||
return -1;
|
||||
}
|
||||
|
@ -982,7 +982,7 @@ namespace detail {
|
|||
}
|
||||
}
|
||||
}
|
||||
Ptrdiff sw = spec.write_arg(writer, argpos - 1, args...);
|
||||
ptrdiff_t sw = spec.write_arg(writer, argpos - 1, args...);
|
||||
if (sw < 0) {
|
||||
return sw;
|
||||
}
|
||||
|
@ -994,10 +994,10 @@ namespace detail {
|
|||
}
|
||||
|
||||
template<typename R, typename ...A>
|
||||
inline Ptrdiff format_impl(
|
||||
R &writer, Size &fmtn, bool, ConstCharRange fmt
|
||||
inline ptrdiff_t format_impl(
|
||||
R &writer, size_t &fmtn, bool, ConstCharRange fmt
|
||||
) {
|
||||
Size written = 0;
|
||||
size_t written = 0;
|
||||
detail::WriteSpec spec(fmt, false);
|
||||
if (spec.read_until_spec(writer, &written)) {
|
||||
return -1;
|
||||
|
@ -1008,15 +1008,15 @@ namespace detail {
|
|||
} /* namespace detail */
|
||||
|
||||
template<typename R, typename ...A>
|
||||
inline Ptrdiff format(
|
||||
R &&writer, Size &fmtn, ConstCharRange fmt, A const &...args
|
||||
inline ptrdiff_t format(
|
||||
R &&writer, size_t &fmtn, ConstCharRange fmt, A const &...args
|
||||
) {
|
||||
return detail::format_impl(writer, fmtn, false, fmt, args...);
|
||||
}
|
||||
|
||||
template<typename R, typename ...A>
|
||||
Ptrdiff format(R &&writer, ConstCharRange fmt, A const &...args) {
|
||||
Size fmtn = 0;
|
||||
ptrdiff_t format(R &&writer, ConstCharRange fmt, A const &...args) {
|
||||
size_t fmtn = 0;
|
||||
return format(writer, fmtn, fmt, args...);
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ BinaryNegate<T> not2(T const &fn) {
|
|||
|
||||
/* endian swap */
|
||||
|
||||
template<typename T, Size N = sizeof(T), bool IsNum = IsArithmetic<T>>
|
||||
template<typename T, size_t N = sizeof(T), bool IsNum = IsArithmetic<T>>
|
||||
struct EndianSwap;
|
||||
|
||||
template<typename T>
|
||||
|
@ -182,7 +182,7 @@ template<typename T>
|
|||
T endian_swap(T x) { return EndianSwap<T>()(x); }
|
||||
|
||||
namespace detail {
|
||||
template<typename T, Size N = sizeof(T), bool IsNum = IsArithmetic<T>>
|
||||
template<typename T, size_t N = sizeof(T), bool IsNum = IsArithmetic<T>>
|
||||
struct EndianSame;
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -26,14 +26,14 @@ namespace detail {
|
|||
};
|
||||
|
||||
template<typename R>
|
||||
static inline Size estimate_hrsize(
|
||||
static inline size_t estimate_hrsize(
|
||||
const R &range, EnableIf<IsFiniteRandomAccessRange<R>, bool> = true
|
||||
) {
|
||||
return range.size();
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
static inline Size estimate_hrsize(
|
||||
static inline size_t estimate_hrsize(
|
||||
const R &, EnableIf<!IsFiniteRandomAccessRange<R>, bool> = true
|
||||
) {
|
||||
/* we have no idea how big the range actually is */
|
||||
|
@ -139,49 +139,49 @@ namespace detail {
|
|||
* If this is not possible, use the upper bound and pad the
|
||||
* structure with some extra bytes.
|
||||
*/
|
||||
static constexpr Size CacheLineSize = 64;
|
||||
static constexpr Size ChunkLowerBound = 32;
|
||||
static constexpr Size ChunkUpperBound = 128;
|
||||
static constexpr size_t CacheLineSize = 64;
|
||||
static constexpr size_t ChunkLowerBound = 32;
|
||||
static constexpr size_t ChunkUpperBound = 128;
|
||||
|
||||
template<typename E, Size N> constexpr Size HashChainAlign =
|
||||
template<typename E, size_t N> constexpr size_t HashChainAlign =
|
||||
(((sizeof(HashChain<E>[N]) + sizeof(void *)) % CacheLineSize) == 0)
|
||||
? N : HashChainAlign<E, N + 1>;
|
||||
|
||||
template<typename E>
|
||||
constexpr Size HashChainAlign<E, ChunkUpperBound> = ChunkUpperBound;
|
||||
constexpr size_t HashChainAlign<E, ChunkUpperBound> = ChunkUpperBound;
|
||||
|
||||
template<Size N, bool B>
|
||||
template<size_t N, bool B>
|
||||
struct HashChainPad;
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct HashChainPad<N, true> {};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct HashChainPad<N, false> {
|
||||
byte pad[CacheLineSize - (N % CacheLineSize)];
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct HashPad: HashChainPad<N, N % CacheLineSize == 0> {};
|
||||
|
||||
template<
|
||||
typename E, Size V = HashChainAlign<E, ChunkLowerBound>,
|
||||
typename E, size_t V = HashChainAlign<E, ChunkLowerBound>,
|
||||
bool P = (V == ChunkUpperBound)
|
||||
>
|
||||
struct HashChunk;
|
||||
|
||||
template<typename E, Size V>
|
||||
template<typename E, size_t V>
|
||||
struct HashChunk<E, V, false> {
|
||||
static constexpr Size num = V;
|
||||
static constexpr size_t num = V;
|
||||
HashChain<E> chains[num];
|
||||
HashChunk *next;
|
||||
};
|
||||
|
||||
template<typename E, Size V>
|
||||
template<typename E, size_t V>
|
||||
struct HashChunk<E, V, true>: HashPad<
|
||||
sizeof(HashChain<E>[V]) + sizeof(void *)
|
||||
> {
|
||||
static constexpr Size num = V;
|
||||
static constexpr size_t num = V;
|
||||
HashChain<E> chains[num];
|
||||
HashChunk *next;
|
||||
};
|
||||
|
@ -201,8 +201,8 @@ private:
|
|||
using Chain = HashChain<E>;
|
||||
using Chunk = HashChunk<E>;
|
||||
|
||||
Size p_size;
|
||||
Size p_len;
|
||||
size_t p_size;
|
||||
size_t p_len;
|
||||
|
||||
Chunk *p_chunks;
|
||||
Chain *p_unused;
|
||||
|
@ -234,7 +234,7 @@ private:
|
|||
clear_buckets();
|
||||
}
|
||||
|
||||
Chain *find(const K &key, Size &h) const {
|
||||
Chain *find(const K &key, size_t &h) const {
|
||||
if (!p_size) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -248,7 +248,7 @@ private:
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Chain *insert_node(Size h, Chain *c) {
|
||||
Chain *insert_node(size_t h, Chain *c) {
|
||||
Chain **cp = p_data.first();
|
||||
Chain *it = cp[h + 1];
|
||||
c->next = it;
|
||||
|
@ -287,7 +287,7 @@ private:
|
|||
allocator_construct(get_challoc(), chunk);
|
||||
chunk->next = p_chunks;
|
||||
p_chunks = chunk;
|
||||
for (Size i = 0; i < (Chunk::num - 1); ++i) {
|
||||
for (size_t i = 0; i < (Chunk::num - 1); ++i) {
|
||||
chunk->chains[i].next = &chunk->chains[i + 1];
|
||||
}
|
||||
chunk->chains[Chunk::num - 1].next = p_unused;
|
||||
|
@ -299,7 +299,7 @@ private:
|
|||
return c;
|
||||
}
|
||||
|
||||
Chain *insert(Size h) {
|
||||
Chain *insert(size_t h) {
|
||||
return insert_node(h, request_node());
|
||||
}
|
||||
|
||||
|
@ -311,24 +311,24 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void rehash_ahead(Size n) {
|
||||
void rehash_ahead(size_t n) {
|
||||
if (!bucket_count()) {
|
||||
reserve(n);
|
||||
} else if ((float(size() + n) / bucket_count()) > max_load_factor()) {
|
||||
rehash(Size((size() + 1) / max_load_factor()) * 2);
|
||||
rehash(size_t((size() + 1) / max_load_factor()) * 2);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
template<typename U>
|
||||
T &insert(Size h, U &&key) {
|
||||
T &insert(size_t h, U &&key) {
|
||||
Chain *c = insert(h);
|
||||
B::set_key(c->value, std::forward<U>(key), get_alloc());
|
||||
return B::get_data(c->value);
|
||||
}
|
||||
|
||||
T &access_or_insert(const K &key) {
|
||||
Size h = 0;
|
||||
size_t h = 0;
|
||||
Chain *c = find(key, h);
|
||||
if (c) {
|
||||
return B::get_data(c->value);
|
||||
|
@ -338,7 +338,7 @@ protected:
|
|||
}
|
||||
|
||||
T &access_or_insert(K &&key) {
|
||||
Size h = 0;
|
||||
size_t h = 0;
|
||||
Chain *c = find(key, h);
|
||||
if (c) {
|
||||
return B::get_data(c->value);
|
||||
|
@ -348,7 +348,7 @@ protected:
|
|||
}
|
||||
|
||||
T *access(const K &key) const {
|
||||
Size h;
|
||||
size_t h;
|
||||
Chain *c = find(key, h);
|
||||
if (c) {
|
||||
return &B::get_data(c->value);
|
||||
|
@ -391,7 +391,7 @@ protected:
|
|||
return p_data.second().first().second().second();
|
||||
}
|
||||
|
||||
Hashtable(Size size, const H &hf, const C &eqf, const A &alloc):
|
||||
Hashtable(size_t size, const H &hf, const C &eqf, const A &alloc):
|
||||
p_size(size), p_len(0), p_chunks(nullptr), p_unused(nullptr),
|
||||
p_data(nullptr, FAPair(AllocPair(alloc, CoreAllocPair(alloc, alloc)),
|
||||
FuncPair(hf, eqf))),
|
||||
|
@ -413,7 +413,7 @@ protected:
|
|||
init_buckets();
|
||||
Chain **och = ht.p_data.first();
|
||||
for (Chain *oc = *och; oc; oc = oc->next) {
|
||||
Size h = bucket(B::get_key(oc->value));
|
||||
size_t h = bucket(B::get_key(oc->value));
|
||||
Chain *nc = insert(h);
|
||||
allocator_destroy(get_alloc(), &nc->value);
|
||||
allocator_construct(get_alloc(), &nc->value, oc->value);
|
||||
|
@ -451,7 +451,7 @@ protected:
|
|||
init_buckets();
|
||||
Chain **och = ht.p_data.first();
|
||||
for (Chain *oc = *och; oc; oc = oc->next) {
|
||||
Size h = bucket(B::get_key(oc->value));
|
||||
size_t h = bucket(B::get_key(oc->value));
|
||||
Chain *nc = insert(h);
|
||||
B::swap_elem(oc->value, nc->value);
|
||||
}
|
||||
|
@ -495,11 +495,11 @@ protected:
|
|||
if (load_factor() <= max_load_factor()) {
|
||||
return;
|
||||
}
|
||||
rehash(Size(size() / max_load_factor()) * 2);
|
||||
rehash(size_t(size() / max_load_factor()) * 2);
|
||||
}
|
||||
|
||||
void reserve_at_least(Size count) {
|
||||
Size nc = Size(ceil(count / max_load_factor()));
|
||||
void reserve_at_least(size_t count) {
|
||||
size_t nc = size_t(ceil(count / max_load_factor()));
|
||||
if (p_size > nc) {
|
||||
return;
|
||||
}
|
||||
|
@ -542,18 +542,18 @@ public:
|
|||
}
|
||||
|
||||
bool empty() const { return p_len == 0; }
|
||||
Size size() const { return p_len; }
|
||||
Size max_size() const { return Size(~0) / sizeof(E); }
|
||||
size_t size() const { return p_len; }
|
||||
size_t max_size() const { return size_t(~0) / sizeof(E); }
|
||||
|
||||
Size bucket_count() const { return p_size; }
|
||||
Size max_bucket_count() const { return Size(~0) / sizeof(Chain); }
|
||||
size_t bucket_count() const { return p_size; }
|
||||
size_t max_bucket_count() const { return size_t(~0) / sizeof(Chain); }
|
||||
|
||||
Size bucket(const K &key) const {
|
||||
size_t bucket(const K &key) const {
|
||||
return get_hash()(key) & (p_size - 1);
|
||||
}
|
||||
|
||||
Size bucket_size(Size n) const {
|
||||
Size ret = 0;
|
||||
size_t bucket_size(size_t n) const {
|
||||
size_t ret = 0;
|
||||
if (n >= p_size) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -573,12 +573,12 @@ public:
|
|||
* gotta make sure that equal keys always come after
|
||||
* each other (this is then used by other APIs)
|
||||
*/
|
||||
Size h = bucket(B::get_key(elem));
|
||||
size_t h = bucket(B::get_key(elem));
|
||||
Chain *ch = insert(h);
|
||||
B::swap_elem(ch->value, elem);
|
||||
return std::make_pair(Range(ch), true);
|
||||
}
|
||||
Size h = bucket(B::get_key(elem));
|
||||
size_t h = bucket(B::get_key(elem));
|
||||
Chain *found = nullptr;
|
||||
bool ins = true;
|
||||
Chain **cp = p_data.first();
|
||||
|
@ -596,20 +596,20 @@ public:
|
|||
return std::make_pair(Range(found), ins);
|
||||
}
|
||||
|
||||
Size erase(const K &key) {
|
||||
Size h = 0;
|
||||
size_t erase(const K &key) {
|
||||
size_t h = 0;
|
||||
Chain *c = find(key, h);
|
||||
if (!c) {
|
||||
return 0;
|
||||
}
|
||||
Chain **cp = p_data.first();
|
||||
Size olen = p_len;
|
||||
size_t olen = p_len;
|
||||
for (Chain *e = cp[h + 1]; c != e; c = c->next) {
|
||||
if (!get_eq()(key, B::get_key(c->value))) {
|
||||
break;
|
||||
}
|
||||
--p_len;
|
||||
Size hh = h;
|
||||
size_t hh = h;
|
||||
Chain *next = c->next;
|
||||
for (; cp[hh] == c; --hh) {
|
||||
cp[hh] = next;
|
||||
|
@ -635,13 +635,13 @@ public:
|
|||
return olen - p_len;
|
||||
}
|
||||
|
||||
Size count(const K &key) {
|
||||
Size h = 0;
|
||||
size_t count(const K &key) {
|
||||
size_t h = 0;
|
||||
Chain *c = find(key, h);
|
||||
if (!c) {
|
||||
return 0;
|
||||
}
|
||||
Size ret = 1;
|
||||
size_t ret = 1;
|
||||
if (!Multihash) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -654,12 +654,12 @@ public:
|
|||
}
|
||||
|
||||
Range find(const K &key) {
|
||||
Size h = 0;
|
||||
size_t h = 0;
|
||||
return Range(find(key, h));
|
||||
}
|
||||
|
||||
ConstRange find(const K &key) const {
|
||||
Size h = 0;
|
||||
size_t h = 0;
|
||||
return ConstRange(reinterpret_cast<detail::HashChain<const E> *>(
|
||||
find(key, h)
|
||||
));
|
||||
|
@ -669,14 +669,14 @@ public:
|
|||
float max_load_factor() const { return p_maxlf; }
|
||||
void max_load_factor(float lf) { p_maxlf = lf; }
|
||||
|
||||
void rehash(Size count) {
|
||||
Size fbcount = Size(p_len / max_load_factor());
|
||||
void rehash(size_t count) {
|
||||
size_t fbcount = size_t(p_len / max_load_factor());
|
||||
if (fbcount > count) {
|
||||
count = fbcount;
|
||||
}
|
||||
|
||||
Chain **och = p_data.first();
|
||||
Size osize = p_size;
|
||||
size_t osize = p_size;
|
||||
|
||||
p_size = count;
|
||||
init_buckets();
|
||||
|
@ -684,7 +684,7 @@ public:
|
|||
Chain *p = och ? *och : nullptr;
|
||||
while (p) {
|
||||
Chain *pp = p->next;
|
||||
Size h = bucket(B::get_key(p->value));
|
||||
size_t h = bucket(B::get_key(p->value));
|
||||
p->prev = p->next = nullptr;
|
||||
insert_node(h, p);
|
||||
p = pp;
|
||||
|
@ -695,8 +695,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void reserve(Size count) {
|
||||
rehash(Size(ceil(count / max_load_factor())));
|
||||
void reserve(size_t count) {
|
||||
rehash(size_t(ceil(count / max_load_factor())));
|
||||
}
|
||||
|
||||
Range iter() {
|
||||
|
@ -720,13 +720,13 @@ public:
|
|||
return ConstRange(reinterpret_cast<Chain *>(*p_data.first()));
|
||||
}
|
||||
|
||||
LocalRange iter(Size n) {
|
||||
LocalRange iter(size_t n) {
|
||||
if (n >= p_size) {
|
||||
return LocalRange();
|
||||
}
|
||||
return LocalRange(p_data.first()[n], p_data.first()[n + 1]);
|
||||
}
|
||||
ConstLocalRange iter(Size n) const {
|
||||
ConstLocalRange iter(size_t n) const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (n >= p_size) {
|
||||
return ConstLocalRange();
|
||||
|
@ -736,7 +736,7 @@ public:
|
|||
reinterpret_cast<Chain *>(p_data.first()[n + 1])
|
||||
);
|
||||
}
|
||||
ConstLocalRange citer(Size n) const {
|
||||
ConstLocalRange citer(size_t n) const {
|
||||
using Chain = detail::HashChain<const E>;
|
||||
if (n >= p_size) {
|
||||
return ConstLocalRange();
|
||||
|
|
12
ostd/io.hh
12
ostd/io.hh
|
@ -59,9 +59,9 @@ struct FileStream: Stream {
|
|||
buf[path.size()] = '\0';
|
||||
p_owned = false;
|
||||
#ifndef OSTD_PLATFORM_WIN32
|
||||
p_f = fopen(buf, detail::filemodes[Size(mode)]);
|
||||
p_f = fopen(buf, detail::filemodes[size_t(mode)]);
|
||||
#else
|
||||
if (fopen_s(&p_f, buf, detail::filemodes[Size(mode)]) != 0) {
|
||||
if (fopen_s(&p_f, buf, detail::filemodes[size_t(mode)]) != 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
@ -111,11 +111,11 @@ struct FileStream: Stream {
|
|||
|
||||
bool flush() { return !fflush(p_f); }
|
||||
|
||||
Size read_bytes(void *buf, Size count) {
|
||||
size_t read_bytes(void *buf, size_t count) {
|
||||
return fread(buf, 1, count, p_f);
|
||||
}
|
||||
|
||||
Size write_bytes(void const *buf, Size count) {
|
||||
size_t write_bytes(void const *buf, size_t count) {
|
||||
return fwrite(buf, 1, count, p_f);
|
||||
}
|
||||
|
||||
|
@ -194,12 +194,12 @@ inline void writeln(T const &v, A const &...args) {
|
|||
template<typename ...A>
|
||||
inline void writef(ConstCharRange fmt, A const &...args) {
|
||||
char buf[512];
|
||||
Ptrdiff need = format(
|
||||
ptrdiff_t need = format(
|
||||
detail::FormatOutRange<sizeof(buf)>(buf), fmt, args...
|
||||
);
|
||||
if (need < 0) {
|
||||
return;
|
||||
} else if (Size(need) < sizeof(buf)) {
|
||||
} else if (size_t(need) < sizeof(buf)) {
|
||||
fwrite(buf, 1, need, stdout);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ namespace detail {
|
|||
public:
|
||||
using Key = KeysetKey<T>;
|
||||
using Mapped = T;
|
||||
using Size = ostd::Size;
|
||||
using Difference = Ptrdiff;
|
||||
using Size = size_t;
|
||||
using Difference = ptrdiff_t;
|
||||
using Hasher = H;
|
||||
using KeyEqual = C;
|
||||
using Value = T;
|
||||
|
|
|
@ -55,8 +55,8 @@ namespace detail {
|
|||
public:
|
||||
using Key = K;
|
||||
using Mapped = T;
|
||||
using Size = ostd::Size;
|
||||
using Difference = Ptrdiff;
|
||||
using Size = size_t;
|
||||
using Difference = ptrdiff_t;
|
||||
using Hasher = H;
|
||||
using KeyEqual = C;
|
||||
using Value = std::pair<K const, T>;
|
||||
|
|
|
@ -75,7 +75,7 @@ namespace detail {
|
|||
|
||||
template<typename T, bool = HasDifference<T>::value>
|
||||
struct PointerDifferenceBase {
|
||||
using Type = Ptrdiff;
|
||||
using Type = ptrdiff_t;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -90,7 +90,7 @@ namespace detail {
|
|||
|
||||
template<typename T>
|
||||
struct PointerDifferenceType<T *> {
|
||||
using Type = Ptrdiff;
|
||||
using Type = ptrdiff_t;
|
||||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
|
@ -225,11 +225,11 @@ struct Allocator {
|
|||
template<typename U>
|
||||
Allocator(Allocator<U> const &) noexcept {}
|
||||
|
||||
Value *allocate(Size n) {
|
||||
Value *allocate(size_t n) {
|
||||
return reinterpret_cast<Value *>(::new byte[n * sizeof(T)]);
|
||||
}
|
||||
|
||||
void deallocate(Value *p, Size) noexcept {
|
||||
void deallocate(Value *p, size_t) noexcept {
|
||||
::delete[] reinterpret_cast<byte *>(p);
|
||||
}
|
||||
};
|
||||
|
@ -752,7 +752,7 @@ namespace detail {
|
|||
template<typename A>
|
||||
struct AllocatorDestructor {
|
||||
using Pointer = AllocatorPointer<A>;
|
||||
using Size = ostd::Size;
|
||||
using Size = size_t;
|
||||
AllocatorDestructor(A &a, Size s) noexcept: p_alloc(a), p_size(s) {}
|
||||
void operator()(Pointer p) noexcept {
|
||||
allocator_deallocate(p_alloc, p, p_size);
|
||||
|
|
|
@ -507,7 +507,7 @@ struct ZipRange;
|
|||
|
||||
template<
|
||||
typename B, typename C, typename V, typename R = V &,
|
||||
typename S = Size, typename D = Ptrdiff
|
||||
typename S = size_t, typename D = ptrdiff_t
|
||||
>
|
||||
struct InputRange {
|
||||
using Category = C;
|
||||
|
@ -689,7 +689,7 @@ inline auto chunks(T n) {
|
|||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename T, typename ...R, Size ...I>
|
||||
template<typename T, typename ...R, size_t ...I>
|
||||
inline auto join_proxy(
|
||||
T &&obj, std::tuple<R &&...> &&tup, std::index_sequence<I...>
|
||||
) {
|
||||
|
@ -698,7 +698,7 @@ namespace detail {
|
|||
)...);
|
||||
}
|
||||
|
||||
template<typename T, typename ...R, Size ...I>
|
||||
template<typename T, typename ...R, size_t ...I>
|
||||
inline auto zip_proxy(
|
||||
T &&obj, std::tuple<R &&...> &&tup, std::index_sequence<I...>
|
||||
) {
|
||||
|
@ -790,7 +790,7 @@ inline auto citer(T const &r) -> decltype(ranged_traits<T const>::iter(r)) {
|
|||
|
||||
template<
|
||||
typename B, typename V, typename R = V &,
|
||||
typename S = Size, typename D = Ptrdiff
|
||||
typename S = size_t, typename D = ptrdiff_t
|
||||
>
|
||||
struct OutputRange {
|
||||
using Category = OutputRangeTag;
|
||||
|
@ -1100,7 +1100,7 @@ public:
|
|||
(IsPointer<U> || IsNullPointer<U>) && IsConvertible<U, T *>, Nat
|
||||
> = Nat()): p_beg(beg), p_end(end) {}
|
||||
|
||||
PointerRange(T *beg, Size n): p_beg(beg), p_end(beg + n) {}
|
||||
PointerRange(T *beg, size_t n): p_beg(beg), p_end(beg + n) {}
|
||||
|
||||
template<typename U, typename = EnableIf<IsConvertible<U *, T *>>>
|
||||
PointerRange(PointerRange<U> const &v): p_beg(&v[0]), p_end(&v[v.size()]) {}
|
||||
|
@ -1125,8 +1125,8 @@ public:
|
|||
--p_beg; return true;
|
||||
}
|
||||
|
||||
Size pop_front_n(Size n) {
|
||||
Size olen = p_end - p_beg;
|
||||
size_t pop_front_n(size_t n) {
|
||||
size_t olen = p_end - p_beg;
|
||||
p_beg += n;
|
||||
if (p_beg > p_end) {
|
||||
p_beg = p_end;
|
||||
|
@ -1135,7 +1135,7 @@ public:
|
|||
return n;
|
||||
}
|
||||
|
||||
Size push_front_n(Size n) {
|
||||
size_t push_front_n(size_t n) {
|
||||
p_beg -= n; return true;
|
||||
}
|
||||
|
||||
|
@ -1145,7 +1145,7 @@ public:
|
|||
return p_beg == range.p_beg;
|
||||
}
|
||||
|
||||
Ptrdiff distance_front(PointerRange const &range) const {
|
||||
ptrdiff_t distance_front(PointerRange const &range) const {
|
||||
return range.p_beg - p_beg;
|
||||
}
|
||||
|
||||
|
@ -1161,8 +1161,8 @@ public:
|
|||
++p_end; return true;
|
||||
}
|
||||
|
||||
Size pop_back_n(Size n) {
|
||||
Size olen = p_end - p_beg;
|
||||
size_t pop_back_n(size_t n) {
|
||||
size_t olen = p_end - p_beg;
|
||||
p_end -= n;
|
||||
if (p_end < p_beg) {
|
||||
p_end = p_beg;
|
||||
|
@ -1171,7 +1171,7 @@ public:
|
|||
return n;
|
||||
}
|
||||
|
||||
Size push_back_n(Size n) {
|
||||
size_t push_back_n(size_t n) {
|
||||
p_end += n; return true;
|
||||
}
|
||||
|
||||
|
@ -1181,18 +1181,18 @@ public:
|
|||
return p_end == range.p_end;
|
||||
}
|
||||
|
||||
Ptrdiff distance_back(PointerRange const &range) const {
|
||||
ptrdiff_t distance_back(PointerRange const &range) const {
|
||||
return range.p_end - p_end;
|
||||
}
|
||||
|
||||
/* satisfy FiniteRandomAccessRange */
|
||||
Size size() const { return p_end - p_beg; }
|
||||
size_t size() const { return p_end - p_beg; }
|
||||
|
||||
PointerRange slice(Size start, Size end) const {
|
||||
PointerRange slice(size_t start, size_t end) const {
|
||||
return PointerRange(p_beg + start, p_beg + end);
|
||||
}
|
||||
|
||||
T &operator[](Size i) const { return p_beg[i]; }
|
||||
T &operator[](size_t i) const { return p_beg[i]; }
|
||||
|
||||
/* satisfy OutputRange */
|
||||
bool put(T const &v) {
|
||||
|
@ -1210,8 +1210,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
Size put_n(T const *p, Size n) {
|
||||
Size ret = size();
|
||||
size_t put_n(T const *p, size_t n) {
|
||||
size_t ret = size();
|
||||
if (n < ret) {
|
||||
ret = n;
|
||||
}
|
||||
|
@ -1220,23 +1220,23 @@ public:
|
|||
p_beg += ret;
|
||||
return ret;
|
||||
}
|
||||
for (Size i = ret; i; --i) {
|
||||
for (size_t i = ret; i; --i) {
|
||||
*p_beg++ = *p++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
EnableIf<IsOutputRange<R>, Size> copy(R &&orange, Size n = -1) {
|
||||
Size c = size();
|
||||
EnableIf<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
size_t c = size();
|
||||
if (n < c) {
|
||||
c = n;
|
||||
}
|
||||
return orange.put_n(p_beg, c);
|
||||
}
|
||||
|
||||
Size copy(RemoveCv<T> *p, Size n = -1) {
|
||||
Size c = size();
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
size_t c = size();
|
||||
if (n < c) {
|
||||
c = n;
|
||||
}
|
||||
|
@ -1254,17 +1254,17 @@ private:
|
|||
T *p_beg, *p_end;
|
||||
};
|
||||
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
inline PointerRange<T> iter(T (&array)[N]) {
|
||||
return PointerRange<T>(array, N);
|
||||
}
|
||||
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
inline PointerRange<T const> iter(T const (&array)[N]) {
|
||||
return PointerRange<T const>(array, N);
|
||||
}
|
||||
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
inline PointerRange<T const> citer(T const (&array)[N]) {
|
||||
return PointerRange<T const>(array, N);
|
||||
}
|
||||
|
@ -1281,7 +1281,7 @@ inline PointerRange<T> iter(T *a, U b, EnableIf<
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
inline PointerRange<T> iter(T *a, ostd::Size b) {
|
||||
inline PointerRange<T> iter(T *a, size_t b) {
|
||||
return PointerRange<T>(a, b);
|
||||
}
|
||||
|
||||
|
@ -1459,7 +1459,7 @@ public:
|
|||
};
|
||||
|
||||
namespace detail {
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct JoinRangeEmpty {
|
||||
template<typename T>
|
||||
static bool empty(T const &tup) {
|
||||
|
@ -1470,7 +1470,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct JoinRangeEmpty<N, N> {
|
||||
template<typename T>
|
||||
static bool empty(T const &) {
|
||||
|
@ -1478,7 +1478,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct TupleRangeEqual {
|
||||
template<typename T>
|
||||
static bool equal(T const &tup1, T const &tup2) {
|
||||
|
@ -1489,7 +1489,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct TupleRangeEqual<N, N> {
|
||||
template<typename T>
|
||||
static bool equal(T const &, T const &) {
|
||||
|
@ -1497,7 +1497,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct JoinRangePop {
|
||||
template<typename T>
|
||||
static bool pop(T &tup) {
|
||||
|
@ -1508,7 +1508,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct JoinRangePop<N, N> {
|
||||
template<typename T>
|
||||
static bool pop(T &) {
|
||||
|
@ -1516,7 +1516,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size I, Size N, typename T>
|
||||
template<size_t I, size_t N, typename T>
|
||||
struct JoinRangeFront {
|
||||
template<typename U>
|
||||
static T front(U const &tup) {
|
||||
|
@ -1527,7 +1527,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N, typename T>
|
||||
template<size_t N, typename T>
|
||||
struct JoinRangeFront<N, N, T> {
|
||||
template<typename U>
|
||||
static T front(U const &tup) {
|
||||
|
@ -1595,7 +1595,7 @@ namespace detail {
|
|||
template<typename ...T>
|
||||
using ZipValue = typename detail::ZipValueType<T...>::Type;
|
||||
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct ZipRangeEmpty {
|
||||
template<typename T>
|
||||
static bool empty(T const &tup) {
|
||||
|
@ -1606,7 +1606,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct ZipRangeEmpty<N, N> {
|
||||
template<typename T>
|
||||
static bool empty(T const &) {
|
||||
|
@ -1614,7 +1614,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct ZipRangePop {
|
||||
template<typename T>
|
||||
static bool pop(T &tup) {
|
||||
|
@ -1624,7 +1624,7 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct ZipRangePop<N, N> {
|
||||
template<typename T>
|
||||
static bool pop(T &) {
|
||||
|
@ -1634,7 +1634,7 @@ namespace detail {
|
|||
|
||||
template<typename ...T>
|
||||
struct ZipRangeFront {
|
||||
template<typename U, Size ...I>
|
||||
template<typename U, size_t ...I>
|
||||
static ZipValue<T...> tup_get(U const &tup, std::index_sequence<I...>) {
|
||||
return ZipValue<T...>(std::get<I>(tup).front()...);
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ namespace detail {
|
|||
|
||||
public:
|
||||
using Key = T;
|
||||
using Size = ostd::Size;
|
||||
using Difference = Ptrdiff;
|
||||
using Size = size_t;
|
||||
using Difference = ptrdiff_t;
|
||||
using Hasher = H;
|
||||
using KeyEqual = C;
|
||||
using Value = T;
|
||||
|
|
|
@ -36,12 +36,12 @@ template<typename T = char, bool = IsPod<T>>
|
|||
struct StreamRange;
|
||||
|
||||
namespace detail {
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct FormatOutRange: OutputRange<FormatOutRange<N>, char> {
|
||||
FormatOutRange(char *ibuf): buf(ibuf), idx(0) {}
|
||||
FormatOutRange(FormatOutRange const &r): buf(r.buf), idx(r.idx) {}
|
||||
char *buf;
|
||||
Size idx;
|
||||
size_t idx;
|
||||
bool put(char v) {
|
||||
if (idx < N) {
|
||||
buf[idx++] = v;
|
||||
|
@ -104,8 +104,8 @@ public:
|
|||
|
||||
virtual bool flush() { return true; }
|
||||
|
||||
virtual Size read_bytes(void *, Size) { return 0; }
|
||||
virtual Size write_bytes(void const *, Size) { return 0; }
|
||||
virtual size_t read_bytes(void *, size_t) { return 0; }
|
||||
virtual size_t write_bytes(void const *, size_t) { return 0; }
|
||||
|
||||
virtual int getchar() {
|
||||
byte c;
|
||||
|
@ -140,18 +140,18 @@ public:
|
|||
template<typename ...A>
|
||||
bool writef(ConstCharRange fmt, A const &...args) {
|
||||
char buf[512];
|
||||
Ptrdiff need = format(
|
||||
ptrdiff_t need = format(
|
||||
detail::FormatOutRange<sizeof(buf)>(buf), fmt, args...
|
||||
);
|
||||
if (need < 0) {
|
||||
return false;
|
||||
} else if (Size(need) < sizeof(buf)) {
|
||||
return write_bytes(buf, need) == Size(need);
|
||||
} else if (size_t(need) < sizeof(buf)) {
|
||||
return write_bytes(buf, need) == size_t(need);
|
||||
}
|
||||
std::vector<char> s;
|
||||
s.reserve(need);
|
||||
format(detail::UnsafeWritefRange(s.data()), fmt, args...);
|
||||
return write_bytes(s.data(), need) == Size(need);
|
||||
return write_bytes(s.data(), need) == size_t(need);
|
||||
}
|
||||
|
||||
template<typename ...A>
|
||||
|
@ -163,7 +163,7 @@ public:
|
|||
StreamRange<T> iter();
|
||||
|
||||
template<typename T>
|
||||
Size put(T const *v, Size count) {
|
||||
size_t put(T const *v, size_t count) {
|
||||
return write_bytes(v, count * sizeof(T)) / sizeof(T);
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
Size get(T *v, Size count) {
|
||||
size_t get(T *v, size_t count) {
|
||||
return read_bytes(v, count * sizeof(T)) / sizeof(T);
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ public:
|
|||
|
||||
template<typename T>
|
||||
struct StreamRange<T, true>: InputRange<
|
||||
StreamRange<T>, InputRangeTag, T, T, Size, StreamOffset
|
||||
StreamRange<T>, InputRangeTag, T, T, size_t, StreamOffset
|
||||
> {
|
||||
StreamRange() = delete;
|
||||
StreamRange(Stream &s): p_stream(&s), p_size(s.size()) {}
|
||||
|
@ -220,17 +220,17 @@ struct StreamRange<T, true>: InputRange<
|
|||
}
|
||||
|
||||
bool put(T val) {
|
||||
Size v = p_stream->write_bytes(&val, sizeof(T));
|
||||
size_t v = p_stream->write_bytes(&val, sizeof(T));
|
||||
p_size += v;
|
||||
return (v == sizeof(T));
|
||||
}
|
||||
|
||||
Size put_n(T const *p, Size n) {
|
||||
size_t put_n(T const *p, size_t n) {
|
||||
return p_stream->put(p, n);
|
||||
}
|
||||
|
||||
Size copy(RemoveCv<T> *p, Size n = -1) {
|
||||
if (n == Size(-1)) {
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
if (n == size_t(-1)) {
|
||||
n = p_stream->size() / sizeof(T);
|
||||
}
|
||||
return p_stream->get(p, n);
|
||||
|
|
|
@ -37,7 +37,7 @@ public:
|
|||
(IsPointer<U> || IsNullPointer<U>) && IsConvertible<U, T *>, Nat
|
||||
> = Nat()): p_beg(beg), p_end(end) {}
|
||||
|
||||
CharRangeBase(T *beg, Size n): p_beg(beg), p_end(beg + n) {}
|
||||
CharRangeBase(T *beg, size_t n): p_beg(beg), p_end(beg + n) {}
|
||||
|
||||
/* TODO: traits for utf-16/utf-32 string lengths, for now assume char */
|
||||
template<typename U>
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
CharRangeBase(Nullptr): p_beg(nullptr), p_end(nullptr) {}
|
||||
|
||||
template<typename U, Size N>
|
||||
template<typename U, size_t N>
|
||||
CharRangeBase(U (&beg)[N], EnableIf<IsConvertible<U *, T *>, Nat> = Nat()):
|
||||
p_beg(beg), p_end(beg + N - (beg[N - 1] == '\0'))
|
||||
{}
|
||||
|
@ -88,8 +88,8 @@ public:
|
|||
}
|
||||
bool push_front() { --p_beg; return true; }
|
||||
|
||||
Size pop_front_n(Size n) {
|
||||
Size olen = p_end - p_beg;
|
||||
size_t pop_front_n(size_t n) {
|
||||
size_t olen = p_end - p_beg;
|
||||
p_beg += n;
|
||||
if (p_beg > p_end) {
|
||||
p_beg = p_end;
|
||||
|
@ -98,7 +98,7 @@ public:
|
|||
return n;
|
||||
}
|
||||
|
||||
Size push_front_n(Size n) { p_beg -= n; return true; }
|
||||
size_t push_front_n(size_t n) { p_beg -= n; return true; }
|
||||
|
||||
T &front() const { return *p_beg; }
|
||||
|
||||
|
@ -106,7 +106,7 @@ public:
|
|||
return p_beg == range.p_beg;
|
||||
}
|
||||
|
||||
Ptrdiff distance_front(CharRangeBase const &range) const {
|
||||
ptrdiff_t distance_front(CharRangeBase const &range) const {
|
||||
return range.p_beg - p_beg;
|
||||
}
|
||||
|
||||
|
@ -119,8 +119,8 @@ public:
|
|||
}
|
||||
bool push_back() { ++p_end; return true; }
|
||||
|
||||
Size pop_back_n(Size n) {
|
||||
Size olen = p_end - p_beg;
|
||||
size_t pop_back_n(size_t n) {
|
||||
size_t olen = p_end - p_beg;
|
||||
p_end -= n;
|
||||
if (p_end < p_beg) {
|
||||
p_end = p_beg;
|
||||
|
@ -129,7 +129,7 @@ public:
|
|||
return n;
|
||||
}
|
||||
|
||||
Size push_back_n(Size n) { p_end += n; return true; }
|
||||
size_t push_back_n(size_t n) { p_end += n; return true; }
|
||||
|
||||
T &back() const { return *(p_end - 1); }
|
||||
|
||||
|
@ -137,17 +137,17 @@ public:
|
|||
return p_end == range.p_end;
|
||||
}
|
||||
|
||||
Ptrdiff distance_back(CharRangeBase const &range) const {
|
||||
ptrdiff_t distance_back(CharRangeBase const &range) const {
|
||||
return range.p_end - p_end;
|
||||
}
|
||||
|
||||
Size size() const { return p_end - p_beg; }
|
||||
size_t size() const { return p_end - p_beg; }
|
||||
|
||||
CharRangeBase slice(Size start, Size end) const {
|
||||
CharRangeBase slice(size_t start, size_t end) const {
|
||||
return CharRangeBase(p_beg + start, p_beg + end);
|
||||
}
|
||||
|
||||
T &operator[](Size i) const { return p_beg[i]; }
|
||||
T &operator[](size_t i) const { return p_beg[i]; }
|
||||
|
||||
bool put(T v) {
|
||||
if (empty()) {
|
||||
|
@ -157,8 +157,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
Size put_n(T const *p, Size n) {
|
||||
Size an = ostd::min(n, size());
|
||||
size_t put_n(T const *p, size_t n) {
|
||||
size_t an = ostd::min(n, size());
|
||||
memcpy(p_beg, p, an * sizeof(T));
|
||||
p_beg += an;
|
||||
return an;
|
||||
|
@ -169,7 +169,7 @@ public:
|
|||
|
||||
/* non-range */
|
||||
int compare(CharRangeBase<T const> s) const {
|
||||
ostd::Size s1 = size(), s2 = s.size();
|
||||
size_t s1 = size(), s2 = s.size();
|
||||
int ret;
|
||||
if (!s1 || !s2) {
|
||||
goto diffsize;
|
||||
|
@ -182,8 +182,8 @@ diffsize:
|
|||
}
|
||||
|
||||
int case_compare(CharRangeBase<T const> s) const {
|
||||
ostd::Size s1 = size(), s2 = s.size();
|
||||
for (ostd::Size i = 0, ms = ostd::min(s1, s2); i < ms; ++i) {
|
||||
size_t s1 = size(), s2 = s.size();
|
||||
for (size_t i = 0, ms = ostd::min(s1, s2); i < ms; ++i) {
|
||||
int d = toupper(p_beg[i]) - toupper(s[i]);
|
||||
if (d) {
|
||||
return d;
|
||||
|
@ -193,12 +193,12 @@ diffsize:
|
|||
}
|
||||
|
||||
template<typename R>
|
||||
EnableIf<IsOutputRange<R>, Size> copy(R &&orange, Size n = -1) {
|
||||
EnableIf<IsOutputRange<R>, size_t> copy(R &&orange, size_t n = -1) {
|
||||
return orange.put_n(data(), ostd::min(n, size()));
|
||||
}
|
||||
|
||||
Size copy(RemoveCv<T> *p, Size n = -1) {
|
||||
Size c = ostd::min(n, size());
|
||||
size_t copy(RemoveCv<T> *p, size_t n = -1) {
|
||||
size_t c = ostd::min(n, size());
|
||||
memcpy(p, data(), c * sizeof(T));
|
||||
return c;
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ inline std::basic_string<RemoveCv<RangeValue<R>>> make_string(R range) {
|
|||
|
||||
inline namespace literals {
|
||||
inline namespace string_literals {
|
||||
inline ConstCharRange operator "" _sr(char const *str, Size len) {
|
||||
inline ConstCharRange operator "" _sr(char const *str, size_t len) {
|
||||
return ConstCharRange(str, len);
|
||||
}
|
||||
}
|
||||
|
@ -370,18 +370,18 @@ namespace detail {
|
|||
p_written += ret;
|
||||
return ret;
|
||||
}
|
||||
Size put_n(char const *v, Size n) {
|
||||
Size ret = p_out.put_n(v, n);
|
||||
size_t put_n(char const *v, size_t n) {
|
||||
size_t ret = p_out.put_n(v, n);
|
||||
p_written += ret;
|
||||
return ret;
|
||||
}
|
||||
Size put_string(ConstCharRange r) {
|
||||
size_t put_string(ConstCharRange r) {
|
||||
return put_n(&r[0], r.size());
|
||||
}
|
||||
Size get_written() const { return p_written; }
|
||||
size_t get_written() const { return p_written; }
|
||||
private:
|
||||
R &p_out;
|
||||
Size p_written;
|
||||
size_t p_written;
|
||||
};
|
||||
|
||||
template<typename T, typename R>
|
||||
|
@ -565,7 +565,7 @@ struct ToString<std::pair<T, U>> {
|
|||
};
|
||||
|
||||
namespace detail {
|
||||
template<Size I, Size N>
|
||||
template<size_t I, size_t N>
|
||||
struct TupleToString {
|
||||
template<typename T>
|
||||
static void append(std::string &ret, T const &tup) {
|
||||
|
@ -577,13 +577,13 @@ namespace detail {
|
|||
}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct TupleToString<N, N> {
|
||||
template<typename T>
|
||||
static void append(std::string &, T const &) {}
|
||||
};
|
||||
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct TupleToString<0, N> {
|
||||
template<typename T>
|
||||
static void append(std::string &ret, T const &tup) {
|
||||
|
@ -630,7 +630,7 @@ public:
|
|||
s.p_buf = nullptr;
|
||||
s.p_allocated = false;
|
||||
}
|
||||
TempCString(R input, RemoveCv<RangeValue<R>> *sbuf, Size bufsize)
|
||||
TempCString(R input, RemoveCv<RangeValue<R>> *sbuf, size_t bufsize)
|
||||
: p_buf(nullptr), p_allocated(false) {
|
||||
if (input.empty()) {
|
||||
return;
|
||||
|
@ -672,7 +672,7 @@ inline void swap(TempCString<R> &a, TempCString<R> &b) {
|
|||
|
||||
template<typename R>
|
||||
inline TempCString<R> to_temp_cstr(
|
||||
R input, RemoveCv<RangeValue<R>> *buf, Size bufsize
|
||||
R input, RemoveCv<RangeValue<R>> *buf, size_t bufsize
|
||||
) {
|
||||
return TempCString<R>(input, buf, bufsize);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ using RemoveAllExtents = typename detail::RemoveAllExtentsBase<T>::Type;
|
|||
/* size in bits */
|
||||
|
||||
template<typename T>
|
||||
constexpr Size SizeInBits = sizeof(T) * CHAR_BIT;
|
||||
constexpr size_t SizeInBits = sizeof(T) * CHAR_BIT;
|
||||
|
||||
/* integral constant */
|
||||
|
||||
|
@ -166,7 +166,7 @@ template<typename>
|
|||
constexpr bool IsArray = false;
|
||||
template<typename T>
|
||||
constexpr bool IsArray<T[]> = true;
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
constexpr bool IsArray<T[N]> = true;
|
||||
|
||||
/* is pointer */
|
||||
|
@ -679,11 +679,11 @@ namespace detail {
|
|||
CtibleVoidCheck<CtibleContainsVoid<T, A...> || IsAbstract<T>, T, A...>;
|
||||
|
||||
/* array types are default constructible if their element type is */
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
constexpr bool CtibleCore<false, T[N]> = Ctible<RemoveAllExtents<T>>;
|
||||
|
||||
/* otherwise array types are not constructible by this syntax */
|
||||
template<typename T, Size N, typename ...A>
|
||||
template<typename T, size_t N, typename ...A>
|
||||
constexpr bool CtibleCore<false, T[N], A...> = false;
|
||||
|
||||
/* incomplete array types are not constructible */
|
||||
|
@ -735,7 +735,7 @@ namespace detail {
|
|||
template<typename T, typename ...A> constexpr bool IsNothrowConstructible =
|
||||
detail::NothrowCtibleCore<IsConstructible<T, A...>, IsReference<T>, T, A...>;
|
||||
|
||||
template<typename T, Size N> constexpr bool IsNothrowConstructible<T[N]> =
|
||||
template<typename T, size_t N> constexpr bool IsNothrowConstructible<T[N]> =
|
||||
detail::NothrowCtibleCore<IsConstructible<T>, IsReference<T>, T>;
|
||||
|
||||
/* is nothrow default constructible */
|
||||
|
@ -884,7 +884,7 @@ namespace detail {
|
|||
template<typename T>
|
||||
constexpr bool IsNothrowDestructible = detail::NothrowDtibleCore<IsDestructible<T>, T>;
|
||||
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
constexpr bool IsNothrowDestructible<T[N]> = IsNothrowDestructible<T>;
|
||||
|
||||
/* is trivially constructible */
|
||||
|
@ -1006,39 +1006,39 @@ constexpr bool IsConvertible = detail::IsConvertibleBase<F, T>::value;
|
|||
|
||||
namespace detail {
|
||||
template<typename, uint>
|
||||
constexpr Size ExtentBase = 0;
|
||||
constexpr size_t ExtentBase = 0;
|
||||
|
||||
template<typename T>
|
||||
constexpr Size ExtentBase<T[], 0> = 0;
|
||||
constexpr size_t ExtentBase<T[], 0> = 0;
|
||||
|
||||
template<typename T, uint I>
|
||||
constexpr Size ExtentBase<T[], I> = detail::ExtentBase<T, I - 1>;
|
||||
constexpr size_t ExtentBase<T[], I> = detail::ExtentBase<T, I - 1>;
|
||||
|
||||
template<typename T, Size N>
|
||||
constexpr Size ExtentBase<T[N], 0> = N;
|
||||
template<typename T, size_t N>
|
||||
constexpr size_t ExtentBase<T[N], 0> = N;
|
||||
|
||||
template<typename T, Size N, uint I>
|
||||
constexpr Size ExtentBase<T[N], I> = detail::ExtentBase<T, I - 1>;
|
||||
template<typename T, size_t N, uint I>
|
||||
constexpr size_t ExtentBase<T[N], I> = detail::ExtentBase<T, I - 1>;
|
||||
} /* namespace detail */
|
||||
|
||||
template<typename T, uint I = 0>
|
||||
constexpr Size Extent = detail::ExtentBase<T, I>;
|
||||
constexpr size_t Extent = detail::ExtentBase<T, I>;
|
||||
|
||||
/* rank */
|
||||
|
||||
namespace detail {
|
||||
template<typename>
|
||||
constexpr Size RankBase = 0;
|
||||
constexpr size_t RankBase = 0;
|
||||
|
||||
template<typename T>
|
||||
constexpr Size RankBase<T[]> = detail::RankBase<T> + 1;
|
||||
constexpr size_t RankBase<T[]> = detail::RankBase<T> + 1;
|
||||
|
||||
template<typename T, Size N>
|
||||
constexpr Size RankBase<T[N]> = detail::RankBase<T> + 1;
|
||||
template<typename T, size_t N>
|
||||
constexpr size_t RankBase<T[N]> = detail::RankBase<T> + 1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr Size Rank = detail::RankBase<T>;
|
||||
constexpr size_t Rank = detail::RankBase<T>;
|
||||
|
||||
/* remove const, volatile, cv */
|
||||
|
||||
|
@ -1205,7 +1205,7 @@ namespace detail {
|
|||
struct RemoveExtentBase { using Type = T; };
|
||||
template<typename T>
|
||||
struct RemoveExtentBase<T[]> { using Type = T; };
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
struct RemoveExtentBase<T[N]> { using Type = T; };
|
||||
}
|
||||
|
||||
|
@ -1223,7 +1223,7 @@ namespace detail {
|
|||
using Type = RemoveAllExtentsBase<T>;
|
||||
};
|
||||
|
||||
template<typename T, Size N>
|
||||
template<typename T, size_t N>
|
||||
struct RemoveAllExtentsBase<T[N]> {
|
||||
using Type = RemoveAllExtentsBase<T>;
|
||||
};
|
||||
|
@ -1272,15 +1272,15 @@ namespace detail {
|
|||
>
|
||||
>;
|
||||
|
||||
template<typename T, Size N, bool = (N <= sizeof(typename T::First))>
|
||||
template<typename T, size_t N, bool = (N <= sizeof(typename T::First))>
|
||||
struct TypeFindFirst;
|
||||
|
||||
template<typename T, typename U, Size N>
|
||||
template<typename T, typename U, size_t N>
|
||||
struct TypeFindFirst<TypeList<T, U>, N, true> {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
template<typename T, typename U, Size N>
|
||||
template<typename T, typename U, size_t N>
|
||||
struct TypeFindFirst<TypeList<T, U>, N, false> {
|
||||
using Type = typename TypeFindFirst<U, N>::Type;
|
||||
};
|
||||
|
@ -1605,7 +1605,7 @@ using CommonType = typename detail::CommonTypeBase<A...>::Type;
|
|||
/* aligned storage */
|
||||
|
||||
namespace detail {
|
||||
template<Size N>
|
||||
template<size_t N>
|
||||
struct AlignedTest {
|
||||
union Type {
|
||||
byte data[N];
|
||||
|
@ -1613,7 +1613,7 @@ namespace detail {
|
|||
};
|
||||
};
|
||||
|
||||
template<Size N, Size A>
|
||||
template<size_t N, size_t A>
|
||||
struct AlignedStorageBase {
|
||||
struct Type {
|
||||
alignas(A) byte data[N];
|
||||
|
@ -1621,7 +1621,7 @@ namespace detail {
|
|||
};
|
||||
}
|
||||
|
||||
template<Size N, Size A
|
||||
template<size_t N, size_t A
|
||||
= alignof(typename detail::AlignedTest<N>::Type)
|
||||
>
|
||||
using AlignedStorage = typename detail::AlignedStorageBase<N, A>::Type;
|
||||
|
@ -1629,20 +1629,20 @@ using AlignedStorage = typename detail::AlignedStorageBase<N, A>::Type;
|
|||
/* aligned union */
|
||||
|
||||
namespace detail {
|
||||
template<Size ...N>
|
||||
constexpr Size AlignMax = 0;
|
||||
template<Size N>
|
||||
constexpr Size AlignMax<N> = N;
|
||||
template<size_t ...N>
|
||||
constexpr size_t AlignMax = 0;
|
||||
template<size_t N>
|
||||
constexpr size_t AlignMax<N> = N;
|
||||
|
||||
template<Size N1, Size N2>
|
||||
constexpr Size AlignMax<N1, N2> = (N1 > N2) ? N1 : N2;
|
||||
template<size_t N1, size_t N2>
|
||||
constexpr size_t AlignMax<N1, N2> = (N1 > N2) ? N1 : N2;
|
||||
|
||||
template<Size N1, Size N2, Size ...N>
|
||||
constexpr Size AlignMax<N1, N2, N...> = AlignMax<AlignMax<N1, N2>, N...>;
|
||||
template<size_t N1, size_t N2, size_t ...N>
|
||||
constexpr size_t AlignMax<N1, N2, N...> = AlignMax<AlignMax<N1, N2>, N...>;
|
||||
|
||||
template<Size N, typename ...T>
|
||||
template<size_t N, typename ...T>
|
||||
struct AlignedUnionBase {
|
||||
static constexpr Size alignment_value = AlignMax<alignof(T)...>;
|
||||
static constexpr size_t alignment_value = AlignMax<alignof(T)...>;
|
||||
|
||||
struct Type {
|
||||
alignas(alignment_value) byte data[AlignMax<N, sizeof(T)...>];
|
||||
|
@ -1650,7 +1650,7 @@ namespace detail {
|
|||
};
|
||||
} /* namespace detail */
|
||||
|
||||
template<Size N, typename ...T>
|
||||
template<size_t N, typename ...T>
|
||||
using AlignedUnion = typename detail::AlignedUnionBase<N, T...>::Type;
|
||||
|
||||
/* underlying type */
|
||||
|
|
|
@ -55,11 +55,6 @@ using MaxAlign = ::max_align_t;
|
|||
using MaxAlign = long double;
|
||||
#endif
|
||||
|
||||
/* stddef */
|
||||
|
||||
using Ptrdiff = ptrdiff_t;
|
||||
using Size = size_t;
|
||||
|
||||
/* stdint */
|
||||
|
||||
using Intmax = intmax_t;
|
||||
|
|
|
@ -20,29 +20,29 @@ namespace detail {
|
|||
bool = IsSame<RemoveCv<T>, RemoveCv<U>>,
|
||||
bool = IsEmpty<T>, bool = IsEmpty<U>
|
||||
>
|
||||
constexpr Size CompressedPairSwitch = detail::Undefined<T>();
|
||||
constexpr size_t CompressedPairSwitch = detail::Undefined<T>();
|
||||
|
||||
/* neither empty */
|
||||
template<typename T, typename U, bool Same>
|
||||
constexpr Size CompressedPairSwitch<T, U, Same, false, false> = 0;
|
||||
constexpr size_t CompressedPairSwitch<T, U, Same, false, false> = 0;
|
||||
|
||||
/* first empty */
|
||||
template<typename T, typename U, bool Same>
|
||||
constexpr Size CompressedPairSwitch<T, U, Same, true, false> = 1;
|
||||
constexpr size_t CompressedPairSwitch<T, U, Same, true, false> = 1;
|
||||
|
||||
/* second empty */
|
||||
template<typename T, typename U, bool Same>
|
||||
constexpr Size CompressedPairSwitch<T, U, Same, false, true> = 2;
|
||||
constexpr size_t CompressedPairSwitch<T, U, Same, false, true> = 2;
|
||||
|
||||
/* both empty, not the same */
|
||||
template<typename T, typename U>
|
||||
constexpr Size CompressedPairSwitch<T, U, false, true, true> = 3;
|
||||
constexpr size_t CompressedPairSwitch<T, U, false, true, true> = 3;
|
||||
|
||||
/* both empty and same */
|
||||
template<typename T, typename U>
|
||||
constexpr Size CompressedPairSwitch<T, U, true, true, true> = 1;
|
||||
constexpr size_t CompressedPairSwitch<T, U, true, true, true> = 1;
|
||||
|
||||
template<typename T, typename U, Size = CompressedPairSwitch<T, U>>
|
||||
template<typename T, typename U, size_t = CompressedPairSwitch<T, U>>
|
||||
struct CompressedPairBase;
|
||||
|
||||
template<typename T, typename U>
|
||||
|
@ -55,7 +55,7 @@ namespace detail {
|
|||
p_first(std::forward<TT>(a)), p_second(std::forward<UU>(b))
|
||||
{}
|
||||
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase(
|
||||
std::piecewise_construct_t,
|
||||
std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
|
@ -83,7 +83,7 @@ namespace detail {
|
|||
T(std::forward<TT>(a)), p_second(std::forward<UU>(b))
|
||||
{}
|
||||
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase(
|
||||
std::piecewise_construct_t,
|
||||
std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
|
@ -110,7 +110,7 @@ namespace detail {
|
|||
U(std::forward<UU>(b)), p_first(std::forward<TT>(a))
|
||||
{}
|
||||
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase(
|
||||
std::piecewise_construct_t,
|
||||
std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
|
@ -135,7 +135,7 @@ namespace detail {
|
|||
T(std::forward<TT>(a)), U(std::forward<UU>(b))
|
||||
{}
|
||||
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase(
|
||||
std::piecewise_construct_t,
|
||||
std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
|
@ -184,7 +184,7 @@ namespace detail {
|
|||
};
|
||||
|
||||
template<typename T, typename U>
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase<T, U, 0>::CompressedPairBase(
|
||||
std::piecewise_construct_t, std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
std::index_sequence<I1...>, std::index_sequence<I2...>
|
||||
|
@ -194,7 +194,7 @@ namespace detail {
|
|||
{}
|
||||
|
||||
template<typename T, typename U>
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase<T, U, 1>::CompressedPairBase(
|
||||
std::piecewise_construct_t, std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
std::index_sequence<I1...>, std::index_sequence<I2...>
|
||||
|
@ -204,7 +204,7 @@ namespace detail {
|
|||
{}
|
||||
|
||||
template<typename T, typename U>
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase<T, U, 2>::CompressedPairBase(
|
||||
std::piecewise_construct_t, std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
std::index_sequence<I1...>, std::index_sequence<I2...>
|
||||
|
@ -214,7 +214,7 @@ namespace detail {
|
|||
{}
|
||||
|
||||
template<typename T, typename U>
|
||||
template<typename ...A1, typename ...A2, Size ...I1, Size ...I2>
|
||||
template<typename ...A1, typename ...A2, size_t ...I1, size_t ...I2>
|
||||
CompressedPairBase<T, U, 3>::CompressedPairBase(
|
||||
std::piecewise_construct_t, std::tuple<A1...> &fa, std::tuple<A2...> &sa,
|
||||
std::index_sequence<I1...>, std::index_sequence<I2...>
|
||||
|
|
|
@ -22,8 +22,8 @@ struct Vec2 {
|
|||
Vec2(T v): x(v), y(v) {}
|
||||
Vec2(T x, T y): x(x), y(y) {}
|
||||
|
||||
T &operator[](Size idx) { return value[idx]; }
|
||||
T operator[](Size idx) const { return value[idx]; }
|
||||
T &operator[](size_t idx) { return value[idx]; }
|
||||
T operator[](size_t idx) const { return value[idx]; }
|
||||
|
||||
Vec2 &add(T v) {
|
||||
x += v; y += v;
|
||||
|
@ -148,8 +148,8 @@ struct Vec3 {
|
|||
Vec3(T v): x(v), y(v), z(v) {}
|
||||
Vec3(T x, T y, T z): x(x), y(y), z(z) {}
|
||||
|
||||
T &operator[](Size idx) { return value[idx]; }
|
||||
T operator[](Size idx) const { return value[idx]; }
|
||||
T &operator[](size_t idx) { return value[idx]; }
|
||||
T operator[](size_t idx) const { return value[idx]; }
|
||||
|
||||
Vec3 &add(T v) {
|
||||
x += v; y += v; z += v;
|
||||
|
@ -274,8 +274,8 @@ struct Vec4 {
|
|||
Vec4(T v): x(v), y(v), z(v), w(v) {}
|
||||
Vec4(T x, T y, T z, T w): x(x), y(y), z(z), w(w) {}
|
||||
|
||||
T &operator[](Size idx) { return value[idx]; }
|
||||
T operator[](Size idx) const { return value[idx]; }
|
||||
T &operator[](size_t idx) { return value[idx]; }
|
||||
T operator[](size_t idx) const { return value[idx]; }
|
||||
|
||||
Vec4 &add(T v) {
|
||||
x += v; y += v; z += v; w += v;
|
||||
|
|
Loading…
Reference in New Issue