From 2884f4b47b1c4ea00e5ce3d7f83244a46a3eae07 Mon Sep 17 00:00:00 2001 From: q66 Date: Mon, 30 Jan 2017 19:11:39 +0100 Subject: [PATCH] use size_t and ptrdiff_t --- ostd/event.hh | 26 +++---- ostd/ext/sdl_rwops.hh | 4 +- ostd/filesystem.hh | 6 +- ostd/format.hh | 148 ++++++++++++++++++------------------- ostd/functional.hh | 4 +- ostd/internal/hashtable.hh | 122 +++++++++++++++--------------- ostd/io.hh | 12 +-- ostd/keyset.hh | 4 +- ostd/map.hh | 4 +- ostd/memory.hh | 10 +-- ostd/range.hh | 80 ++++++++++---------- ostd/set.hh | 4 +- ostd/stream.hh | 30 ++++---- ostd/string.hh | 64 ++++++++-------- ostd/type_traits.hh | 76 +++++++++---------- ostd/types.hh | 5 -- ostd/utility.hh | 30 ++++---- ostd/vecmath.hh | 12 +-- 18 files changed, 318 insertions(+), 323 deletions(-) diff --git a/ostd/event.hh b/ostd/event.hh index fd68051..f90d93d 100644 --- a/ostd/event.hh +++ b/ostd/event.hh @@ -22,7 +22,7 @@ namespace detail { using func_t = std::function; byte *bufp = new byte[sizeof(func_t) * p_nfuncs]; func_t *nbuf = reinterpret_cast(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(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; p_funcs[i].~func(); } @@ -64,9 +64,9 @@ namespace detail { } template - Size connect(F &&func) { + size_t connect(F &&func) { using func_t = std::function; - 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(func); return i; @@ -74,7 +74,7 @@ namespace detail { } byte *bufp = new byte[sizeof(func_t) * (p_nfuncs + 1)]; func_t *nbuf = reinterpret_cast(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 *p_funcs; - Size p_nfuncs; + size_t p_nfuncs; }; } /* namespace detail */ @@ -151,9 +151,9 @@ public: void clear() { p_base.clear(); } template - Size connect(F &&func) { return p_base.connect(std::forward(func)); } + size_t connect(F &&func) { return p_base.connect(std::forward(func)); } - bool disconnect(Size idx) { return p_base.disconnect(idx); } + bool disconnect(size_t idx) { return p_base.disconnect(idx); } template void emit(Args &&...args) { p_base.emit(std::forward(args)...); } @@ -190,9 +190,9 @@ public: void clear() { p_base.clear(); } template - Size connect(F &&func) { return p_base.connect(std::forward(func)); } + size_t connect(F &&func) { return p_base.connect(std::forward(func)); } - bool disconnect(Size idx) { return p_base.disconnect(idx); } + bool disconnect(size_t idx) { return p_base.disconnect(idx); } template void emit(Args &&...args) const { p_base.emit(std::forward(args)...); } diff --git a/ostd/ext/sdl_rwops.hh b/ostd/ext/sdl_rwops.hh index c0985a6..63afe24 100644 --- a/ostd/ext/sdl_rwops.hh +++ b/ostd/ext/sdl_rwops.hh @@ -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(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(rw->hidden.unknown.data1); return is->write_bytes(buf, size * nb) / size; }; diff --git a/ostd/filesystem.hh b/ostd/filesystem.hh index fee3845..b1754db 100644 --- a/ostd/filesystem.hh +++ b/ostd/filesystem.hh @@ -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 + template struct PathJoin { template static void join(std::string &s, T const &a, A const &...b) { diff --git a/ostd/format.hh b/ostd/format.hh index b2f5fb5..c7f1e68 100644 --- a/ostd/format.hh +++ b/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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 - 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 + template struct FmtTupleUnpacker { template - 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::unpack( @@ -526,8 +526,8 @@ namespace detail { template<> struct FmtTupleUnpacker<0> { template - 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(0))::value; template - 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, bool> = true ) { return format_impl(writer, fmtn, esc, fmt, item); } template - 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, bool> = true ) { if (expandval) { @@ -568,7 +568,7 @@ namespace detail { } template - inline Ptrdiff write_range( + inline ptrdiff_t write_range( R &writer, FormatSpec const *fl, bool escape, bool expandval, ConstCharRange sep, T const &val, EnableIf, 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 - inline Ptrdiff write_range( + inline ptrdiff_t write_range( R &, FormatSpec const *, bool, bool, ConstCharRange, T const &, EnableIf, 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 - 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 - Ptrdiff write( + ptrdiff_t write( R &writer, bool escape, T const &val, EnableIf< IsConstructible, bool > = true @@ -709,7 +709,7 @@ namespace detail { /* character */ template - 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 - 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 - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T val, EnableIf< IsIntegral && IsSigned, bool > = true @@ -766,7 +766,7 @@ namespace detail { /* unsigned integers */ template - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T val, EnableIf< IsIntegral && IsUnsigned, bool > = true @@ -775,7 +775,7 @@ namespace detail { } template> - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T val, EnableIf, 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 - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T *val, EnableIf< !IsConstructible, 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 - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T const &val, EnableIf< !IsArithmetic && !IsConstructible && @@ -848,7 +848,7 @@ namespace detail { /* custom format case */ template - Ptrdiff write( + ptrdiff_t write( R &writer, bool, T const &val, EnableIf>, bool> = true ) { @@ -861,7 +861,7 @@ namespace detail { /* generic failure case */ template - Ptrdiff write( + ptrdiff_t write( R &, bool, T const &, EnableIf< !IsArithmetic && !IsConstructible && @@ -874,7 +874,7 @@ namespace detail { /* actual writer */ template - 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 - 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 - 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 - 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 - 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 - 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 -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 -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...); } diff --git a/ostd/functional.hh b/ostd/functional.hh index 934c456..6e1d82f 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -139,7 +139,7 @@ BinaryNegate not2(T const &fn) { /* endian swap */ -template> +template> struct EndianSwap; template @@ -182,7 +182,7 @@ template T endian_swap(T x) { return EndianSwap()(x); } namespace detail { - template> + template> struct EndianSame; template diff --git a/ostd/internal/hashtable.hh b/ostd/internal/hashtable.hh index 8d40367..a0d29d7 100644 --- a/ostd/internal/hashtable.hh +++ b/ostd/internal/hashtable.hh @@ -26,14 +26,14 @@ namespace detail { }; template - static inline Size estimate_hrsize( + static inline size_t estimate_hrsize( const R &range, EnableIf, bool> = true ) { return range.size(); } template - static inline Size estimate_hrsize( + static inline size_t estimate_hrsize( const R &, EnableIf, 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 constexpr Size HashChainAlign = + template constexpr size_t HashChainAlign = (((sizeof(HashChain[N]) + sizeof(void *)) % CacheLineSize) == 0) ? N : HashChainAlign; template - constexpr Size HashChainAlign = ChunkUpperBound; + constexpr size_t HashChainAlign = ChunkUpperBound; - template + template struct HashChainPad; - template + template struct HashChainPad {}; - template + template struct HashChainPad { byte pad[CacheLineSize - (N % CacheLineSize)]; }; - template + template struct HashPad: HashChainPad {}; template< - typename E, Size V = HashChainAlign, + typename E, size_t V = HashChainAlign, bool P = (V == ChunkUpperBound) > struct HashChunk; - template + template struct HashChunk { - static constexpr Size num = V; + static constexpr size_t num = V; HashChain chains[num]; HashChunk *next; }; - template + template struct HashChunk: HashPad< sizeof(HashChain[V]) + sizeof(void *) > { - static constexpr Size num = V; + static constexpr size_t num = V; HashChain chains[num]; HashChunk *next; }; @@ -201,8 +201,8 @@ private: using Chain = HashChain; using Chunk = HashChunk; - 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 - T &insert(Size h, U &&key) { + T &insert(size_t h, U &&key) { Chain *c = insert(h); B::set_key(c->value, std::forward(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 *>( 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(*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; if (n >= p_size) { return ConstLocalRange(); @@ -736,7 +736,7 @@ public: reinterpret_cast(p_data.first()[n + 1]) ); } - ConstLocalRange citer(Size n) const { + ConstLocalRange citer(size_t n) const { using Chain = detail::HashChain; if (n >= p_size) { return ConstLocalRange(); diff --git a/ostd/io.hh b/ostd/io.hh index 94cc35a..d819209 100644 --- a/ostd/io.hh +++ b/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 inline void writef(ConstCharRange fmt, A const &...args) { char buf[512]; - Ptrdiff need = format( + ptrdiff_t need = format( detail::FormatOutRange(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; } diff --git a/ostd/keyset.hh b/ostd/keyset.hh index 612f08c..2e2e9af 100644 --- a/ostd/keyset.hh +++ b/ostd/keyset.hh @@ -55,8 +55,8 @@ namespace detail { public: using Key = KeysetKey; 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; diff --git a/ostd/map.hh b/ostd/map.hh index aca06f7..65d9747 100644 --- a/ostd/map.hh +++ b/ostd/map.hh @@ -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; diff --git a/ostd/memory.hh b/ostd/memory.hh index dd26bf1..ff16d18 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -75,7 +75,7 @@ namespace detail { template::value> struct PointerDifferenceBase { - using Type = Ptrdiff; + using Type = ptrdiff_t; }; template @@ -90,7 +90,7 @@ namespace detail { template struct PointerDifferenceType { - using Type = Ptrdiff; + using Type = ptrdiff_t; }; template @@ -225,11 +225,11 @@ struct Allocator { template Allocator(Allocator const &) noexcept {} - Value *allocate(Size n) { + Value *allocate(size_t n) { return reinterpret_cast(::new byte[n * sizeof(T)]); } - void deallocate(Value *p, Size) noexcept { + void deallocate(Value *p, size_t) noexcept { ::delete[] reinterpret_cast(p); } }; @@ -752,7 +752,7 @@ namespace detail { template struct AllocatorDestructor { using Pointer = AllocatorPointer; - 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); diff --git a/ostd/range.hh b/ostd/range.hh index 31f2530..0675d6e 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -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 + template inline auto join_proxy( T &&obj, std::tuple &&tup, std::index_sequence ) { @@ -698,7 +698,7 @@ namespace detail { )...); } - template + template inline auto zip_proxy( T &&obj, std::tuple &&tup, std::index_sequence ) { @@ -790,7 +790,7 @@ inline auto citer(T const &r) -> decltype(ranged_traits::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 || IsNullPointer) && IsConvertible, 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>> PointerRange(PointerRange 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 - EnableIf, Size> copy(R &&orange, Size n = -1) { - Size c = size(); + EnableIf, 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 *p, Size n = -1) { - Size c = size(); + size_t copy(RemoveCv *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 +template inline PointerRange iter(T (&array)[N]) { return PointerRange(array, N); } -template +template inline PointerRange iter(T const (&array)[N]) { return PointerRange(array, N); } -template +template inline PointerRange citer(T const (&array)[N]) { return PointerRange(array, N); } @@ -1281,7 +1281,7 @@ inline PointerRange iter(T *a, U b, EnableIf< } template -inline PointerRange iter(T *a, ostd::Size b) { +inline PointerRange iter(T *a, size_t b) { return PointerRange(a, b); } @@ -1459,7 +1459,7 @@ public: }; namespace detail { - template + template struct JoinRangeEmpty { template static bool empty(T const &tup) { @@ -1470,7 +1470,7 @@ namespace detail { } }; - template + template struct JoinRangeEmpty { template static bool empty(T const &) { @@ -1478,7 +1478,7 @@ namespace detail { } }; - template + template struct TupleRangeEqual { template static bool equal(T const &tup1, T const &tup2) { @@ -1489,7 +1489,7 @@ namespace detail { } }; - template + template struct TupleRangeEqual { template static bool equal(T const &, T const &) { @@ -1497,7 +1497,7 @@ namespace detail { } }; - template + template struct JoinRangePop { template static bool pop(T &tup) { @@ -1508,7 +1508,7 @@ namespace detail { } }; - template + template struct JoinRangePop { template static bool pop(T &) { @@ -1516,7 +1516,7 @@ namespace detail { } }; - template + template struct JoinRangeFront { template static T front(U const &tup) { @@ -1527,7 +1527,7 @@ namespace detail { } }; - template + template struct JoinRangeFront { template static T front(U const &tup) { @@ -1595,7 +1595,7 @@ namespace detail { template using ZipValue = typename detail::ZipValueType::Type; - template + template struct ZipRangeEmpty { template static bool empty(T const &tup) { @@ -1606,7 +1606,7 @@ namespace detail { } }; - template + template struct ZipRangeEmpty { template static bool empty(T const &) { @@ -1614,7 +1614,7 @@ namespace detail { } }; - template + template struct ZipRangePop { template static bool pop(T &tup) { @@ -1624,7 +1624,7 @@ namespace detail { } }; - template + template struct ZipRangePop { template static bool pop(T &) { @@ -1634,7 +1634,7 @@ namespace detail { template struct ZipRangeFront { - template + template static ZipValue tup_get(U const &tup, std::index_sequence) { return ZipValue(std::get(tup).front()...); } diff --git a/ostd/set.hh b/ostd/set.hh index e3d9855..b7f1476 100644 --- a/ostd/set.hh +++ b/ostd/set.hh @@ -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; diff --git a/ostd/stream.hh b/ostd/stream.hh index 229fe57..3e489ad 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -36,12 +36,12 @@ template> struct StreamRange; namespace detail { - template + template struct FormatOutRange: OutputRange, 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 bool writef(ConstCharRange fmt, A const &...args) { char buf[512]; - Ptrdiff need = format( + ptrdiff_t need = format( detail::FormatOutRange(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 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 @@ -163,7 +163,7 @@ public: StreamRange iter(); template - 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 - 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 struct StreamRange: InputRange< - StreamRange, InputRangeTag, T, T, Size, StreamOffset + StreamRange, InputRangeTag, T, T, size_t, StreamOffset > { StreamRange() = delete; StreamRange(Stream &s): p_stream(&s), p_size(s.size()) {} @@ -220,17 +220,17 @@ struct StreamRange: 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 *p, Size n = -1) { - if (n == Size(-1)) { + size_t copy(RemoveCv *p, size_t n = -1) { + if (n == size_t(-1)) { n = p_stream->size() / sizeof(T); } return p_stream->get(p, n); diff --git a/ostd/string.hh b/ostd/string.hh index c2c3032..aca74e5 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -37,7 +37,7 @@ public: (IsPointer || IsNullPointer) && IsConvertible, 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 @@ -47,7 +47,7 @@ public: CharRangeBase(Nullptr): p_beg(nullptr), p_end(nullptr) {} - template + template CharRangeBase(U (&beg)[N], EnableIf, 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 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 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 - EnableIf, Size> copy(R &&orange, Size n = -1) { + EnableIf, size_t> copy(R &&orange, size_t n = -1) { return orange.put_n(data(), ostd::min(n, size())); } - Size copy(RemoveCv *p, Size n = -1) { - Size c = ostd::min(n, size()); + size_t copy(RemoveCv *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>> 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 @@ -565,7 +565,7 @@ struct ToString> { }; namespace detail { - template + template struct TupleToString { template static void append(std::string &ret, T const &tup) { @@ -577,13 +577,13 @@ namespace detail { } }; - template + template struct TupleToString { template static void append(std::string &, T const &) {} }; - template + template struct TupleToString<0, N> { template 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> *sbuf, Size bufsize) + TempCString(R input, RemoveCv> *sbuf, size_t bufsize) : p_buf(nullptr), p_allocated(false) { if (input.empty()) { return; @@ -672,7 +672,7 @@ inline void swap(TempCString &a, TempCString &b) { template inline TempCString to_temp_cstr( - R input, RemoveCv> *buf, Size bufsize + R input, RemoveCv> *buf, size_t bufsize ) { return TempCString(input, buf, bufsize); } diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index 1406ab6..b8b13a1 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -56,7 +56,7 @@ using RemoveAllExtents = typename detail::RemoveAllExtentsBase::Type; /* size in bits */ template -constexpr Size SizeInBits = sizeof(T) * CHAR_BIT; +constexpr size_t SizeInBits = sizeof(T) * CHAR_BIT; /* integral constant */ @@ -166,7 +166,7 @@ template constexpr bool IsArray = false; template constexpr bool IsArray = true; -template +template constexpr bool IsArray = true; /* is pointer */ @@ -679,11 +679,11 @@ namespace detail { CtibleVoidCheck || IsAbstract, T, A...>; /* array types are default constructible if their element type is */ - template + template constexpr bool CtibleCore = Ctible>; /* otherwise array types are not constructible by this syntax */ - template + template constexpr bool CtibleCore = false; /* incomplete array types are not constructible */ @@ -735,7 +735,7 @@ namespace detail { template constexpr bool IsNothrowConstructible = detail::NothrowCtibleCore, IsReference, T, A...>; -template constexpr bool IsNothrowConstructible = +template constexpr bool IsNothrowConstructible = detail::NothrowCtibleCore, IsReference, T>; /* is nothrow default constructible */ @@ -884,7 +884,7 @@ namespace detail { template constexpr bool IsNothrowDestructible = detail::NothrowDtibleCore, T>; -template +template constexpr bool IsNothrowDestructible = IsNothrowDestructible; /* is trivially constructible */ @@ -1006,39 +1006,39 @@ constexpr bool IsConvertible = detail::IsConvertibleBase::value; namespace detail { template - constexpr Size ExtentBase = 0; + constexpr size_t ExtentBase = 0; template - constexpr Size ExtentBase = 0; + constexpr size_t ExtentBase = 0; template - constexpr Size ExtentBase = detail::ExtentBase; + constexpr size_t ExtentBase = detail::ExtentBase; - template - constexpr Size ExtentBase = N; + template + constexpr size_t ExtentBase = N; - template - constexpr Size ExtentBase = detail::ExtentBase; + template + constexpr size_t ExtentBase = detail::ExtentBase; } /* namespace detail */ template -constexpr Size Extent = detail::ExtentBase; +constexpr size_t Extent = detail::ExtentBase; /* rank */ namespace detail { template - constexpr Size RankBase = 0; + constexpr size_t RankBase = 0; template - constexpr Size RankBase = detail::RankBase + 1; + constexpr size_t RankBase = detail::RankBase + 1; - template - constexpr Size RankBase = detail::RankBase + 1; + template + constexpr size_t RankBase = detail::RankBase + 1; } template -constexpr Size Rank = detail::RankBase; +constexpr size_t Rank = detail::RankBase; /* remove const, volatile, cv */ @@ -1205,7 +1205,7 @@ namespace detail { struct RemoveExtentBase { using Type = T; }; template struct RemoveExtentBase { using Type = T; }; - template + template struct RemoveExtentBase { using Type = T; }; } @@ -1223,7 +1223,7 @@ namespace detail { using Type = RemoveAllExtentsBase; }; - template + template struct RemoveAllExtentsBase { using Type = RemoveAllExtentsBase; }; @@ -1272,15 +1272,15 @@ namespace detail { > >; - template + template struct TypeFindFirst; - template + template struct TypeFindFirst, N, true> { using Type = T; }; - template + template struct TypeFindFirst, N, false> { using Type = typename TypeFindFirst::Type; }; @@ -1605,7 +1605,7 @@ using CommonType = typename detail::CommonTypeBase::Type; /* aligned storage */ namespace detail { - template + template struct AlignedTest { union Type { byte data[N]; @@ -1613,7 +1613,7 @@ namespace detail { }; }; - template + template struct AlignedStorageBase { struct Type { alignas(A) byte data[N]; @@ -1621,7 +1621,7 @@ namespace detail { }; } -template::Type) > using AlignedStorage = typename detail::AlignedStorageBase::Type; @@ -1629,20 +1629,20 @@ using AlignedStorage = typename detail::AlignedStorageBase::Type; /* aligned union */ namespace detail { - template - constexpr Size AlignMax = 0; - template - constexpr Size AlignMax = N; + template + constexpr size_t AlignMax = 0; + template + constexpr size_t AlignMax = N; - template - constexpr Size AlignMax = (N1 > N2) ? N1 : N2; + template + constexpr size_t AlignMax = (N1 > N2) ? N1 : N2; - template - constexpr Size AlignMax = AlignMax, N...>; + template + constexpr size_t AlignMax = AlignMax, N...>; - template + template struct AlignedUnionBase { - static constexpr Size alignment_value = AlignMax; + static constexpr size_t alignment_value = AlignMax; struct Type { alignas(alignment_value) byte data[AlignMax]; @@ -1650,7 +1650,7 @@ namespace detail { }; } /* namespace detail */ -template +template using AlignedUnion = typename detail::AlignedUnionBase::Type; /* underlying type */ diff --git a/ostd/types.hh b/ostd/types.hh index dde0c7d..36686d7 100644 --- a/ostd/types.hh +++ b/ostd/types.hh @@ -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; diff --git a/ostd/utility.hh b/ostd/utility.hh index 3759150..5454fe8 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -20,29 +20,29 @@ namespace detail { bool = IsSame, RemoveCv>, bool = IsEmpty, bool = IsEmpty > - constexpr Size CompressedPairSwitch = detail::Undefined(); + constexpr size_t CompressedPairSwitch = detail::Undefined(); /* neither empty */ template - constexpr Size CompressedPairSwitch = 0; + constexpr size_t CompressedPairSwitch = 0; /* first empty */ template - constexpr Size CompressedPairSwitch = 1; + constexpr size_t CompressedPairSwitch = 1; /* second empty */ template - constexpr Size CompressedPairSwitch = 2; + constexpr size_t CompressedPairSwitch = 2; /* both empty, not the same */ template - constexpr Size CompressedPairSwitch = 3; + constexpr size_t CompressedPairSwitch = 3; /* both empty and same */ template - constexpr Size CompressedPairSwitch = 1; + constexpr size_t CompressedPairSwitch = 1; - template> + template> struct CompressedPairBase; template @@ -55,7 +55,7 @@ namespace detail { p_first(std::forward(a)), p_second(std::forward(b)) {} - template + template CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, @@ -83,7 +83,7 @@ namespace detail { T(std::forward(a)), p_second(std::forward(b)) {} - template + template CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, @@ -110,7 +110,7 @@ namespace detail { U(std::forward(b)), p_first(std::forward(a)) {} - template + template CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, @@ -135,7 +135,7 @@ namespace detail { T(std::forward(a)), U(std::forward(b)) {} - template + template CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, @@ -184,7 +184,7 @@ namespace detail { }; template - template + template CompressedPairBase::CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, std::index_sequence, std::index_sequence @@ -194,7 +194,7 @@ namespace detail { {} template - template + template CompressedPairBase::CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, std::index_sequence, std::index_sequence @@ -204,7 +204,7 @@ namespace detail { {} template - template + template CompressedPairBase::CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, std::index_sequence, std::index_sequence @@ -214,7 +214,7 @@ namespace detail { {} template - template + template CompressedPairBase::CompressedPairBase( std::piecewise_construct_t, std::tuple &fa, std::tuple &sa, std::index_sequence, std::index_sequence diff --git a/ostd/vecmath.hh b/ostd/vecmath.hh index e135371..9eb946e 100644 --- a/ostd/vecmath.hh +++ b/ostd/vecmath.hh @@ -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;