diff --git a/examples/format.cc b/examples/format.cc index e477fbe..d3b4435 100644 --- a/examples/format.cc +++ b/examples/format.cc @@ -41,7 +41,7 @@ struct Bar { }; int main() { - Vector x = { 5, 10, 15, 20 }; + std::vector x = { 5, 10, 15, 20 }; writefln("[%(%s|%)]", x); int y[] = { 2, 4, 8, 16, 32 }; diff --git a/examples/range_pipe.cc b/examples/range_pipe.cc index c9e9e6d..146cab8 100644 --- a/examples/range_pipe.cc +++ b/examples/range_pipe.cc @@ -81,7 +81,7 @@ int main() { /* "list comprehensions" */ writeln("list initialization"); - Vector test( + auto test = make_vector( range(20) | filter([](int v) { return v % 2 == 0; }) | map ([](int v) { return v * 2; }) diff --git a/ostd/algorithm.hh b/ostd/algorithm.hh index 5b03657..0d261c9 100644 --- a/ostd/algorithm.hh +++ b/ostd/algorithm.hh @@ -31,8 +31,10 @@ inline R partition(R range, U pred) { template inline auto partition(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return partition(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return partition( + std::forward(obj), std::forward(func) + ); }; } @@ -49,8 +51,10 @@ inline bool is_partitioned(R range, P pred) { template inline auto is_partitioned(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return is_partitioned(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return is_partitioned( + std::forward(obj), std::forward(func) + ); }; } @@ -62,12 +66,12 @@ namespace detail { RangeSize rlen = range.size(); for (RangeSize i = 1; i < rlen; ++i) { RangeSize j = i; - RangeValue v(move(range[i])); + RangeValue v(std::move(range[i])); while (j > 0 && !compare(range[j - 1], v)) { range[j] = range[j - 1]; --j; } - range[j] = move(v); + range[j] = std::move(v); } } @@ -154,8 +158,10 @@ inline R sort_cmp(R range, C compare) { } template inline auto sort_cmp(C &&compare) { - return [compare = forward(compare)](auto &&obj) mutable { - return sort_cmp(forward(obj), forward(compare)); + return [compare = std::forward(compare)](auto &&obj) mutable { + return sort_cmp( + std::forward(obj), std::forward(compare) + ); }; } @@ -164,7 +170,7 @@ inline R sort(R range) { return sort_cmp(range, Less>()); } inline auto sort() { - return [](auto &&obj) { return sort(forward(obj)); }; + return [](auto &&obj) { return sort(std::forward(obj)); }; } /* min/max(_element) */ @@ -208,12 +214,16 @@ inline R min_element_cmp(R range, C compare) { return r; } inline auto min_element() { - return [](auto &&obj) { return min_element(forward(obj)); }; + return [](auto &&obj) { + return min_element(std::forward(obj)); + }; } template inline auto min_element_cmp(C &&compare) { - return [compare = forward(compare)](auto &&obj) mutable { - return min_element_cmp(forward(obj), forward(compare)); + return [compare = std::forward(compare)](auto &&obj) mutable { + return min_element_cmp( + std::forward(obj), std::forward(compare) + ); }; } @@ -238,12 +248,16 @@ inline R max_element_cmp(R range, C compare) { return r; } inline auto max_element() { - return [](auto &&obj) { return max_element(forward(obj)); }; + return [](auto &&obj) { + return max_element(std::forward(obj)); + }; } template inline auto max_element_cmp(C &&compare) { - return [compare = forward(compare)](auto &&obj) mutable { - return max_element_cmp(forward(obj), forward(compare)); + return [compare = std::forward(compare)](auto &&obj) mutable { + return max_element_cmp( + std::forward(obj), std::forward(compare) + ); }; } @@ -296,9 +310,9 @@ inline bool lexicographical_compare(R1 range1, R2 range2) { } template inline auto lexicographical_compare(R &&range) { - return [range = forward(range)](auto &&obj) mutable { + return [range = std::forward(range)](auto &&obj) mutable { return lexicographical_compare( - forward(obj), forward(range) + std::forward(obj), std::forward(range) ); }; } @@ -320,10 +334,11 @@ inline bool lexicographical_compare_cmp(R1 range1, R2 range2, C compare) { template inline auto lexicographical_compare_cmp(R &&range, C &&compare) { return [ - range = forward(range), compare = forward(compare) + range = std::forward(range), compare = std::forward(compare) ](auto &&obj) mutable { return lexicographical_compare_cmp( - forward(obj), forward(range), forward(compare) + std::forward(obj), std::forward(range), + std::forward(compare) ); }; } @@ -335,13 +350,13 @@ inline F for_each(R range, F func) { for (; !range.empty(); range.pop_front()) { func(range.front()); } - return move(func); + return std::move(func); } template inline auto for_each(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return for_each(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return for_each(std::forward(obj), std::forward(func)); }; } @@ -357,8 +372,8 @@ inline bool all_of(R range, P pred) { template inline auto all_of(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return all_of(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return all_of(std::forward(obj), std::forward(func)); }; } @@ -371,8 +386,8 @@ inline bool any_of(R range, P pred) { template inline auto any_of(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return any_of(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return any_of(std::forward(obj), std::forward(func)); }; } @@ -385,8 +400,8 @@ inline bool none_of(R range, P pred) { template inline auto none_of(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return none_of(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return none_of(std::forward(obj), std::forward(func)); }; } @@ -402,8 +417,8 @@ inline R find(R range, T const &v) { template inline auto find(T &&v) { - return [v = forward(v)](auto &&obj) mutable { - return find(forward(obj), forward(v)); + return [v = std::forward(v)](auto &&obj) mutable { + return find(std::forward(obj), std::forward(v)); }; } @@ -426,8 +441,8 @@ inline R find_last(R range, T const &v) { template inline auto find_last(T &&v) { - return [v = forward(v)](auto &&obj) mutable { - return find_last(forward(obj), forward(v)); + return [v = std::forward(v)](auto &&obj) mutable { + return find_last(std::forward(obj), std::forward(v)); }; } @@ -443,8 +458,8 @@ inline R find_if(R range, P pred) { template inline auto find_if(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return find_if(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return find_if(std::forward(obj), std::forward(func)); }; } @@ -460,8 +475,10 @@ inline R find_if_not(R range, P pred) { template inline auto find_if_not(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return find_if_not(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return find_if_not( + std::forward(obj), std::forward(func) + ); }; } @@ -479,10 +496,11 @@ inline R1 find_one_of_cmp(R1 range, R2 values, C compare) { template inline auto find_one_of_cmp(R &&values, C &&compare) { return [ - values = forward(values), compare = forward(compare) + values = std::forward(values), compare = std::forward(compare) ](auto &&obj) mutable { return find_one_of_cmp( - forward(obj), forward(values), forward(compare) + std::forward(obj), std::forward(values), + std::forward(compare) ); }; } @@ -500,8 +518,10 @@ inline R1 find_one_of(R1 range, R2 values) { } template inline auto find_one_of(R &&values) { - return [values = forward(values)](auto &&obj) mutable { - return find_one_of(forward(obj), forward(values)); + return [values = std::forward(values)](auto &&obj) mutable { + return find_one_of( + std::forward(obj), std::forward(values) + ); }; } @@ -518,8 +538,8 @@ inline RangeSize count(R range, T const &v) { template inline auto count(T &&v) { - return [v = forward(v)](auto &&obj) mutable { - return count(forward(obj), forward(v)); + return [v = std::forward(v)](auto &&obj) mutable { + return count(std::forward(obj), std::forward(v)); }; } @@ -536,8 +556,8 @@ inline RangeSize count_if(R range, P pred) { template inline auto count_if(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return count_if(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return count_if(std::forward(obj), std::forward(func)); }; } @@ -554,8 +574,10 @@ inline RangeSize count_if_not(R range, P pred) { template inline auto count_if_not(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return count_if_not(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return count_if_not( + std::forward(obj), std::forward(func) + ); }; } @@ -572,8 +594,8 @@ inline bool equal(R range1, R range2) { template inline auto equal(R &&range) { - return [range = forward(range)](auto &&obj) mutable { - return equal(forward(obj), forward(range)); + return [range = std::forward(range)](auto &&obj) mutable { + return equal(std::forward(obj), std::forward(range)); }; } @@ -584,8 +606,10 @@ R slice_until(R range1, R range2) { template inline auto slice_until(R &&range) { - return [range = forward(range)](auto &&obj) mutable { - return slice_until(forward(obj), forward(range)); + return [range = std::forward(range)](auto &&obj) mutable { + return slice_until( + std::forward(obj), std::forward(range) + ); }; } @@ -622,7 +646,7 @@ inline R2 copy_if_not(R1 irange, R2 orange, P pred) { template inline R2 move(R1 irange, R2 orange) { for (; !irange.empty(); irange.pop_front()) { - orange.put(move(irange.front())); + orange.put(std::move(irange.front())); } return orange; } @@ -693,17 +717,18 @@ inline T foldl_f(R range, T init, F func) { template inline auto foldl(T &&init) { - return [init = forward(init)](auto &&obj) mutable { - return foldl(forward(obj), forward(init)); + return [init = std::forward(init)](auto &&obj) mutable { + return foldl(std::forward(obj), std::forward(init)); }; } template inline auto foldl_f(T &&init, F &&func) { return [ - init = forward(init), func = forward(func) + init = std::forward(init), func = std::forward(func) ](auto &&obj) mutable { return foldl_f( - forward(obj), forward(init), forward(func) + std::forward(obj), std::forward(init), + std::forward(func) ); }; } @@ -726,17 +751,18 @@ inline T foldr_f(R range, T init, F func) { template inline auto foldr(T &&init) { - return [init = forward(init)](auto &&obj) mutable { - return foldr(forward(obj), forward(init)); + return [init = std::forward(init)](auto &&obj) mutable { + return foldr(std::forward(obj), std::forward(init)); }; } template inline auto foldr_f(T &&init, F &&func) { return [ - init = forward(init), func = forward(func) + init = std::forward(init), func = std::forward(func) ](auto &&obj) mutable { return foldr_f( - forward(obj), forward(init), forward(func) + std::forward(obj), std::forward(init), + std::forward(func) ); }; } @@ -753,11 +779,11 @@ public: MapRange() = delete; template MapRange(T const &range, FF &&func): - p_range(range), p_func(forward(func)) {} + p_range(range), p_func(std::forward(func)) {} MapRange(MapRange const &it): p_range(it.p_range), p_func(it.p_func) {} MapRange(MapRange &&it): - p_range(move(it.p_range)), p_func(move(it.p_func)) {} + p_range(std::move(it.p_range)), p_func(std::move(it.p_func)) {} MapRange &operator=(MapRange const &v) { p_range = v.p_range; @@ -765,8 +791,8 @@ public: return *this; } MapRange &operator=(MapRange &&v) { - p_range = move(v.p_range); - p_func = move(v.p_func); + p_range = std::move(v.p_range); + p_func = std::move(v.p_func); return *this; } @@ -826,13 +852,13 @@ namespace detail { template inline MapRange> map(R range, F func) { - return MapRange>(range, move(func)); + return MapRange>(range, std::move(func)); } template inline auto map(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return map(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return map(std::forward(obj), std::forward(func)); }; } @@ -855,7 +881,7 @@ public: FilterRange() = delete; template FilterRange(T const &range, P &&pred): - p_range(range), p_pred(forward

(pred)) + p_range(range), p_pred(std::forward

(pred)) { advance_valid(); } @@ -865,7 +891,7 @@ public: advance_valid(); } FilterRange(FilterRange &&it): - p_range(move(it.p_range)), p_pred(move(it.p_pred)) + p_range(std::move(it.p_range)), p_pred(std::move(it.p_pred)) { advance_valid(); } @@ -877,8 +903,8 @@ public: return *this; } FilterRange &operator=(FilterRange &&v) { - p_range = move(v.p_range); - p_pred = move(v.p_pred); + p_range = std::move(v.p_range); + p_pred = std::move(v.p_pred); advance_valid(); return *this; } @@ -907,13 +933,13 @@ namespace detail { template inline FilterRange> filter(R range, P pred) { - return FilterRange(range, move(pred)); + return FilterRange(range, std::move(pred)); } template inline auto filter(F &&func) { - return [func = forward(func)](auto &&obj) mutable { - return filter(forward(obj), forward(func)); + return [func = std::forward(func)](auto &&obj) mutable { + return filter(std::forward(obj), std::forward(func)); }; } diff --git a/ostd/array.hh b/ostd/array.hh index 4af4af8..077460c 100644 --- a/ostd/array.hh +++ b/ostd/array.hh @@ -103,12 +103,12 @@ inline TupleElement> const &get(Array const &a) noexcept { template inline TupleElement> &&get(Array &&a) noexcept { - return move(a.p_buf[I]); + return std::move(a.p_buf[I]); } template inline TupleElement> const &&get(Array const &&a) noexcept { - return move(a.p_buf[I]); + return std::move(a.p_buf[I]); } template diff --git a/ostd/environ.hh b/ostd/environ.hh index d3e5bdc..7b18ff2 100644 --- a/ostd/environ.hh +++ b/ostd/environ.hh @@ -27,7 +27,7 @@ inline Maybe env_get(ConstCharRange name) { if (!ret) { return ostd::nothing; } - return ostd::move(String(ret)); + return std::move(String(ret)); #else String rbuf; for (;;) { @@ -43,7 +43,7 @@ inline Maybe env_get(ConstCharRange name) { } rbuf.reserve(ret - 1); } - return ostd::move(rbuf); + return std::move(rbuf); #endif } diff --git a/ostd/event.hh b/ostd/event.hh index 4a60e6a..7b96958 100644 --- a/ostd/event.hh +++ b/ostd/event.hh @@ -67,17 +67,17 @@ namespace detail { using Func = Function; for (Size i = 0; i < p_nfuncs; ++i) { if (!p_funcs[i]) { - p_funcs[i] = forward(func); + p_funcs[i] = std::forward(func); return i; } } byte *bufp = new byte[sizeof(Func) * (p_nfuncs + 1)]; Func *nbuf = reinterpret_cast(bufp); for (Size i = 0; i < p_nfuncs; ++i) { - new (&nbuf[i]) Func(move(p_funcs[i])); + new (&nbuf[i]) Func(std::move(p_funcs[i])); p_funcs[i].~Func(); } - new (&nbuf[p_nfuncs]) Func(forward(func)); + new (&nbuf[p_nfuncs]) Func(std::forward(func)); delete[] reinterpret_cast(p_funcs); p_funcs = nbuf; return p_nfuncs++; @@ -134,7 +134,7 @@ private: public: Signal(C *cl): p_base(cl) {} Signal(Signal const &ev): p_base(ev.p_base) {} - Signal(Signal &&ev): p_base(move(ev.p_base)) {} + Signal(Signal &&ev): p_base(std::move(ev.p_base)) {} Signal &operator=(Signal const &ev) { p_base = ev.p_base; @@ -142,22 +142,22 @@ public: } Signal &operator=(Signal &&ev) { - p_base = move(ev.p_base); + p_base = std::move(ev.p_base); return *this; } void clear() { p_base.clear(); } template - Size connect(F &&func) { return p_base.connect(forward(func)); } + Size connect(F &&func) { return p_base.connect(std::forward(func)); } bool disconnect(Size idx) { return p_base.disconnect(idx); } template - void emit(Args &&...args) { p_base.emit(forward(args)...); } + void emit(Args &&...args) { p_base.emit(std::forward(args)...); } template - void operator()(Args &&...args) { emit(forward(args)...); } + void operator()(Args &&...args) { emit(std::forward(args)...); } C *get_class() const { return p_base.get_class(); } C *set_class(C *cl) { return p_base.set_class(cl); } @@ -173,7 +173,7 @@ private: public: Signal(C *cl): p_base(cl) {} Signal(Signal const &ev): p_base(ev.p_base) {} - Signal(Signal &&ev): p_base(move(ev.p_base)) {} + Signal(Signal &&ev): p_base(std::move(ev.p_base)) {} Signal &operator=(Signal const &ev) { p_base = ev.p_base; @@ -181,22 +181,22 @@ public: } Signal &operator=(Signal &&ev) { - p_base = move(ev.p_base); + p_base = std::move(ev.p_base); return *this; } void clear() { p_base.clear(); } template - Size connect(F &&func) { return p_base.connect(forward(func)); } + Size connect(F &&func) { return p_base.connect(std::forward(func)); } bool disconnect(Size idx) { return p_base.disconnect(idx); } template - void emit(Args &&...args) const { p_base.emit(forward(args)...); } + void emit(Args &&...args) const { p_base.emit(std::forward(args)...); } template - void operator()(Args &&...args) const { emit(forward(args)...); } + void operator()(Args &&...args) const { emit(std::forward(args)...); } C *get_class() const { return p_base.get_class(); } C *set_class(C *cl) { return p_base.set_class(cl); } diff --git a/ostd/filesystem.hh b/ostd/filesystem.hh index 752c660..7641bca 100644 --- a/ostd/filesystem.hh +++ b/ostd/filesystem.hh @@ -64,7 +64,7 @@ struct FileInfo { FileInfo(FileInfo &&i): p_slash(i.p_slash), p_dot(i.p_dot), p_type(i.p_type), - p_path(move(i.p_path)), p_atime(i.p_atime), p_mtime(i.p_mtime), + p_path(std::move(i.p_path)), p_atime(i.p_atime), p_mtime(i.p_mtime), p_ctime(i.p_ctime) { i.p_slash = i.p_dot = npos; @@ -228,7 +228,7 @@ struct DirectoryStream { DirectoryStream(): p_d(), p_de(), p_path() {} DirectoryStream(DirectoryStream const &) = delete; DirectoryStream(DirectoryStream &&s): - p_d(s.p_d), p_de(s.p_de), p_path(move(s.p_path)) + p_d(s.p_d), p_de(s.p_de), p_path(std::move(s.p_path)) { s.p_d = nullptr; s.p_de = nullptr; @@ -364,7 +364,7 @@ struct DirectoryStream { DirectoryStream(): p_handle(INVALID_HANDLE_VALUE), p_data(), p_path() {} DirectoryStream(DirectoryStream const &) = delete; DirectoryStream(DirectoryStream &&s): - p_handle(s.p_handle), p_data(s.p_data), p_path(move(s.p_path)) + p_handle(s.p_handle), p_data(s.p_data), p_path(std::move(s.p_path)) { s.p_handle = INVALID_HANDLE_VALUE; memset(&s.p_data, 0, sizeof(s.p_data)); diff --git a/ostd/format.hh b/ostd/format.hh index a7b2cb6..2013978 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -509,14 +509,6 @@ namespace detail { ConstCharRange fmt, A const &...args ); - template> - static True test_fmt_range(int); - template - static False test_fmt_range(...); - - template - constexpr bool FmtRangeTest = decltype(test_fmt_range(0))::value; - template struct FmtTupleUnpacker { template @@ -565,7 +557,7 @@ namespace detail { template inline Ptrdiff write_range( R &writer, FormatSpec const *fl, bool escape, bool expandval, - ConstCharRange sep, T const &val, EnableIf, bool> = true + ConstCharRange sep, T const &val, EnableIf, bool> = true ) { auto range = ostd::iter(val); if (range.empty()) { @@ -603,7 +595,7 @@ namespace detail { template inline Ptrdiff write_range( R &, FormatSpec const *, bool, bool, ConstCharRange, - T const &, EnableIf, bool> = true + T const &, EnableIf, bool> = true ) { assert(false && "invalid value for ranged format"); return -1; diff --git a/ostd/functional.hh b/ostd/functional.hh index c6021ee..93a6427 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -514,27 +514,27 @@ namespace detail { MemFn(R T::*ptr): p_ptr(ptr) {} template auto operator()(T &obj, A &&...args) -> - decltype(((obj).*(p_ptr))(forward(args)...)) + decltype(((obj).*(p_ptr))(std::forward(args)...)) { - return ((obj).*(p_ptr))(forward(args)...); + return ((obj).*(p_ptr))(std::forward(args)...); } template auto operator()(T const &obj, A &&...args) -> - decltype(((obj).*(p_ptr))(forward(args)...)) + decltype(((obj).*(p_ptr))(std::forward(args)...)) const { - return ((obj).*(p_ptr))(forward(args)...); + return ((obj).*(p_ptr))(std::forward(args)...); } template auto operator()(T *obj, A &&...args) -> - decltype(((obj)->*(p_ptr))(forward(args)...)) + decltype(((obj)->*(p_ptr))(std::forward(args)...)) { - return ((obj)->*(p_ptr))(forward(args)...); + return ((obj)->*(p_ptr))(std::forward(args)...); } template auto operator()(T const *obj, A &&...args) -> - decltype(((obj)->*(p_ptr))(forward(args)...)) + decltype(((obj)->*(p_ptr))(std::forward(args)...)) const { - return ((obj)->*(p_ptr))(forward(args)...); + return ((obj)->*(p_ptr))(std::forward(args)...); } }; } /* namespace detail */ @@ -575,7 +575,7 @@ namespace detail { struct FuncInvokeVoidReturnWrapper { template static R call(A &&...args) { - return func_invoke(forward(args)...); + return func_invoke(std::forward(args)...); } }; @@ -583,7 +583,7 @@ namespace detail { struct FuncInvokeVoidReturnWrapper { template static void call(A &&...args) { - func_invoke(forward(args)...); + func_invoke(std::forward(args)...); } }; @@ -614,7 +614,7 @@ public: explicit FuncCore(F &&f): f_stor( piecewise_construct, - forward_as_tuple(ostd::move(f)), + forward_as_tuple(std::move(f)), forward_as_tuple() ) {} @@ -631,15 +631,15 @@ public: f_stor( piecewise_construct, forward_as_tuple(f), - forward_as_tuple(ostd::move(a)) + forward_as_tuple(std::move(a)) ) {} explicit FuncCore(F &&f, A &&a): f_stor( piecewise_construct, - forward_as_tuple(ostd::move(f)), - forward_as_tuple(ostd::move(a)) + forward_as_tuple(std::move(f)), + forward_as_tuple(std::move(a)) ) {} @@ -681,7 +681,7 @@ public: template R FuncCore::operator()(AT &&...args) { using Invoker = FuncInvokeVoidReturnWrapper; - return Invoker::call(f_stor.first(), forward(args)...); + return Invoker::call(f_stor.first(), std::forward(args)...); } } /* namespace detail */ @@ -752,7 +752,7 @@ public: Callable> && !IsSame, Function>, Function & > operator=(F &&f) { - Function(forward(f)).swap(*this); + Function(std::forward(f)).swap(*this); return *this; } @@ -769,7 +769,7 @@ public: bool operator!=(Function &) const = delete; R operator()(Args ...a) const { - return (*p_f)(forward(a)...); + return (*p_f)(std::forward(a)...); } }; @@ -837,14 +837,14 @@ Function::Function(F f): p_f(nullptr) { } using FF = detail::FuncCore, R(Args...)>; if ((sizeof(FF) <= sizeof(p_buf)) && IsNothrowCopyConstructible) { - p_f = ::new(static_cast(&p_buf)) FF(move(f)); + p_f = ::new(static_cast(&p_buf)) FF(std::move(f)); return; } using AA = Allocator; AA a; using D = detail::AllocatorDestructor; Box hold(a.allocate(1), D(a, 1)); - ::new(hold.get()) FF(move(f), Allocator(a)); + ::new(hold.get()) FF(std::move(f), Allocator(a)); p_f = hold.release(); } @@ -863,12 +863,12 @@ Function::Function(AllocatorArg, A const &a, F f): (sizeof(FF) <= sizeof(p_buf)) && IsNothrowCopyConstructible && IsNothrowCopyConstructible ) { - p_f = ::new(static_cast(&p_buf)) FF(move(f), A(aa)); + p_f = ::new(static_cast(&p_buf)) FF(std::move(f), A(aa)); return; } using D = detail::AllocatorDestructor; Box hold(aa.allocate(1), D(aa, 1)); - ::new(hold.get()) FF(move(f), A(aa)); + ::new(hold.get()) FF(std::move(f), A(aa)); p_f = hold.release(); } diff --git a/ostd/internal/hashtable.hh b/ostd/internal/hashtable.hh index 9587c46..f10e541 100644 --- a/ostd/internal/hashtable.hh +++ b/ostd/internal/hashtable.hh @@ -323,7 +323,7 @@ protected: template T &insert(Size h, U &&key) { Chain *c = insert(h); - B::set_key(c->value, forward(key), get_alloc()); + B::set_key(c->value, std::forward(key), get_alloc()); return B::get_data(c->value); } @@ -344,7 +344,7 @@ protected: return B::get_data(c->value); } rehash_ahead(1); - return insert(bucket(key), move(key)); + return insert(bucket(key), std::move(key)); } T *access(const K &key) const { @@ -422,7 +422,7 @@ protected: Hashtable(Hashtable &&ht): p_size(ht.p_size), p_len(ht.p_len), p_chunks(ht.p_chunks), p_unused(ht.p_unused), - p_data(move(ht.p_data)), p_maxlf(ht.p_maxlf) { + p_data(std::move(ht.p_data)), p_maxlf(ht.p_maxlf) { ht.p_size = ht.p_len = 0; ht.p_chunks = nullptr; ht.p_unused = nullptr; @@ -565,7 +565,7 @@ public: template Pair emplace(Args &&...args) { rehash_ahead(1); - E elem(forward(args)...); + E elem(std::forward(args)...); if (Multihash) { /* multihash: always insert * gotta make sure that equal keys always come after diff --git a/ostd/io.hh b/ostd/io.hh index 4a7ac11..7426a2b 100644 --- a/ostd/io.hh +++ b/ostd/io.hh @@ -8,6 +8,8 @@ #include +#include + #include "ostd/platform.hh" #include "ostd/string.hh" #include "ostd/stream.hh" @@ -196,7 +198,7 @@ inline void writef(ConstCharRange fmt, A const &...args) { fwrite(buf, 1, need, stdout); return; } - Vector s; + std::vector s; s.reserve(need); format(detail::UnsafeWritefRange(s.data()), fmt, args...); fwrite(s.data(), 1, need, stdout); diff --git a/ostd/keyset.hh b/ostd/keyset.hh index 95d9eb0..cade171 100644 --- a/ostd/keyset.hh +++ b/ostd/keyset.hh @@ -87,8 +87,8 @@ namespace detail { KeysetImpl(KeysetImpl const &m, A const &alloc): Base(m, alloc) {} - KeysetImpl(KeysetImpl &&m): Base(move(m)) {} - KeysetImpl(KeysetImpl &&m, A const &alloc): Base(move(m), alloc) {} + KeysetImpl(KeysetImpl &&m): Base(std::move(m)) {} + KeysetImpl(KeysetImpl &&m, A const &alloc): Base(std::move(m), alloc) {} template && IsConvertible, Value> @@ -138,7 +138,7 @@ namespace detail { } KeysetImpl &operator=(KeysetImpl &&m) { - Base::operator=(move(m)); + Base::operator=(std::move(m)); return *this; } @@ -170,7 +170,7 @@ namespace detail { } T &operator[](Key &&key) { static_assert(!IsMultihash, "operator[] only allowed on regular keysets"); - return Base::access_or_insert(move(key)); + return Base::access_or_insert(std::move(key)); } void swap(KeysetImpl &v) { diff --git a/ostd/map.hh b/ostd/map.hh index 2ee17d5..13be355 100644 --- a/ostd/map.hh +++ b/ostd/map.hh @@ -29,7 +29,7 @@ namespace detail { template static inline void set_key(Element &e, U &&key, A &alloc) { allocator_destroy(alloc, &e); - allocator_construct(alloc, &e, forward(key), move(T())); + allocator_construct(alloc, &e, std::forward(key), std::move(T())); } static inline void swap_elem(Element &a, Element &b) { swap_adl(const_cast(a.first), const_cast(b.first)); @@ -89,8 +89,8 @@ namespace detail { MapImpl(MapImpl const &m, A const &alloc): Base(m, alloc) {} - MapImpl(MapImpl &&m): Base(move(m)) {} - MapImpl(MapImpl &&m, A const &alloc): Base(move(m), alloc) {} + MapImpl(MapImpl &&m): Base(std::move(m)) {} + MapImpl(MapImpl &&m, A const &alloc): Base(std::move(m), alloc) {} template && IsConvertible, Value> @@ -140,7 +140,7 @@ namespace detail { } MapImpl &operator=(MapImpl &&m) { - Base::operator=(move(m)); + Base::operator=(std::move(m)); return *this; } @@ -172,7 +172,7 @@ namespace detail { } T &operator[](K &&key) { static_assert(!IsMultihash, "operator[] only allowed on regular maps"); - return Base::access_or_insert(move(key)); + return Base::access_or_insert(std::move(key)); } void swap(MapImpl &v) { diff --git a/ostd/maybe.hh b/ostd/maybe.hh index 5757221..467ceeb 100644 --- a/ostd/maybe.hh +++ b/ostd/maybe.hh @@ -44,16 +44,16 @@ namespace detail { MaybeStorage(MaybeStorage &&v): p_engaged(v.p_engaged) { if (p_engaged) { - ::new(address_of(p_value)) Value(move(v.p_value)); + ::new(address_of(p_value)) Value(std::move(v.p_value)); } } constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {} - constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {} + constexpr MaybeStorage(Value &&v): p_value(std::move(v)), p_engaged(true) {} template constexpr MaybeStorage(InPlace, A &&...args): - p_value(forward(args)...), p_engaged(true) + p_value(std::forward(args)...), p_engaged(true) {} ~MaybeStorage() { @@ -83,16 +83,16 @@ namespace detail { MaybeStorage(MaybeStorage &&v): p_engaged(v.p_engaged) { if (p_engaged) { - ::new(address_of(p_value)) Value(move(v.p_value)); + ::new(address_of(p_value)) Value(std::move(v.p_value)); } } constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {} - constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {} + constexpr MaybeStorage(Value &&v): p_value(std::move(v)), p_engaged(true) {} template constexpr MaybeStorage(InPlace, A &&...args): - p_value(forward(args)...), p_engaged(true) + p_value(std::forward(args)...), p_engaged(true) {} }; } @@ -129,18 +129,18 @@ public: Maybe(Maybe &&) = default; constexpr Maybe(Nothing) {} constexpr Maybe(Value const &v): Base(v) {} - constexpr Maybe(Value &&v): Base(move(v)) {} + constexpr Maybe(Value &&v): Base(std::move(v)) {} template>> constexpr explicit Maybe(InPlace, A &&...args): - Base(in_place, forward(args)...) + Base(in_place, std::forward(args)...) {} template &, A...>> > constexpr explicit Maybe(InPlace, std::initializer_list il, A &&...args): - Base(in_place, il, forward(args)...) + Base(in_place, il, std::forward(args)...) {} ~Maybe() = default; @@ -172,13 +172,13 @@ public: Maybe &operator=(Maybe &&v) { if (this->p_engaged == v.p_engaged) { if (this->p_engaged) { - this->p_value = move(v.p_value); + this->p_value = std::move(v.p_value); } } else { if (this->p_engaged) { this->p_value.~Value(); } else { - ::new(address_of(this->p_value)) Value(move(v.p_value)); + ::new(address_of(this->p_value)) Value(std::move(v.p_value)); } this->p_engaged = v.p_engaged; } @@ -191,9 +191,9 @@ public: >> Maybe &operator=(U &&v) { if (this->p_engaged) { - this->p_value = forward(v); + this->p_value = std::forward(v); } else { - ::new(address_of(this->p_value)) Value(forward(v)); + ::new(address_of(this->p_value)) Value(std::forward(v)); this->p_engaged = true; } return *this; @@ -202,7 +202,7 @@ public: template>> void emplace(A &&...args) { *this = nothing; - ::new(address_of(this->p_value)) Value(forward(args)...); + ::new(address_of(this->p_value)) Value(std::forward(args)...); this->p_engaged = true; } @@ -212,7 +212,7 @@ public: void emplace(std::initializer_list il, A &&...args) { *this = nothing; ::new(address_of(this->p_value)) - Value(il, forward(args)...); + Value(il, std::forward(args)...); this->p_engaged = true; } @@ -233,11 +233,11 @@ public: } constexpr Value const &&operator*() const && { - return ostd::move(this->p_value); + return std::move(this->p_value); } constexpr Value &&operator*() && { - return ostd::move(this->p_value); + return std::move(this->p_value); } constexpr explicit operator bool() const { return this->p_engaged; } @@ -251,11 +251,11 @@ public: } constexpr Value const &&value() const && { - return ostd::move(this->p_value); + return std::move(this->p_value); } constexpr Value &&value() && { - return ostd::move(this->p_value); + return std::move(this->p_value); } template @@ -268,7 +268,7 @@ public: IsConvertible, "Maybe::value_or: U must be convertible to T" ); - return this->p_engaged ? this->p_value : Value(forward(v)); + return this->p_engaged ? this->p_value : Value(std::forward(v)); } template @@ -281,7 +281,7 @@ public: IsConvertible, "Maybe::value_or: U must be convertible to T" ); - return this->p_engaged ? move(this->p_value) : Value(forward(v)); + return this->p_engaged ? std::move(this->p_value) : Value(std::forward(v)); } void swap(Maybe &v) { @@ -291,10 +291,10 @@ public: } } else { if (this->p_engaged) { - ::new(address_of(v.p_value)) Value(move(this->p_value)); + ::new(address_of(v.p_value)) Value(std::move(this->p_value)); this->p_value.~Value(); } else { - ::new(address_of(this->p_value)) Value(move(v.p_value)); + ::new(address_of(this->p_value)) Value(std::move(v.p_value)); v.p_value.~Value(); } detail::swap_adl(this->p_engaged, v.p_engaged); @@ -466,17 +466,17 @@ inline constexpr bool operator>=(T const &b, Maybe const &a) { template inline constexpr Maybe> make_maybe(T &&v) { - return Maybe>(forward(v)); + return Maybe>(std::forward(v)); } template inline constexpr Maybe make_maybe(A &&...args) { - return Maybe(in_place, forward(args)...); + return Maybe(in_place, std::forward(args)...); } template inline constexpr Maybe make_maybe(std::initializer_list il, A &&...args) { - return Maybe(in_place, il, forward(args)...); + return Maybe(in_place, il, std::forward(args)...); } } /* namespace ostd */ diff --git a/ostd/memory.hh b/ostd/memory.hh index dd3d28e..8ef4ef4 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -275,12 +275,14 @@ public: {} Box(Pointer p, RemoveReference &&d) noexcept: - p_stor(p, move(d)) + p_stor(p, std::move(d)) { static_assert(!IsReference, "rvalue deleter cannot be a ref"); } - Box(Box &&u) noexcept: p_stor(u.release(), forward(u.get_deleter())) {} + Box(Box &&u) noexcept: + p_stor(u.release(), std::forward(u.get_deleter())) + {} template Box( @@ -290,11 +292,11 @@ public: IsConvertible && (!IsReference || IsSame), Nat > = Nat() - ) noexcept: p_stor(u.release(), forward

(u.get_deleter())) {} + ) noexcept: p_stor(u.release(), std::forward
(u.get_deleter())) {} Box &operator=(Box &&u) noexcept { reset(u.release()); - p_stor.second() = forward(u.get_deleter()); + p_stor.second() = std::forward(u.get_deleter()); return *this; } @@ -306,7 +308,7 @@ public: Box & > operator=(Box &&u) noexcept { reset(u.release()); - p_stor.second() = forward
(u.get_deleter()); + p_stor.second() = std::forward
(u.get_deleter()); return *this; } @@ -412,18 +414,20 @@ public: template Box(U p, RemoveReference &&d, EnableIf, Nat> = Nat()) noexcept: - p_stor(p, move(d)) + p_stor(p, std::move(d)) { static_assert(!IsReference, "rvalue deleter cannot be a ref"); } Box(Nullptr, RemoveReference &&d) noexcept: - p_stor(nullptr, move(d)) + p_stor(nullptr, std::move(d)) { static_assert(!IsReference, "rvalue deleter cannot be a ref"); } - Box(Box &&u) noexcept: p_stor(u.release(), forward(u.get_deleter())) {} + Box(Box &&u) noexcept: + p_stor(u.release(), std::forward(u.get_deleter())) + {} template Box( @@ -434,12 +438,12 @@ public: Nat > = Nat() ) noexcept: - p_stor(u.release(), forward
(u.get_deleter())) + p_stor(u.release(), std::forward
(u.get_deleter())) {} Box &operator=(Box &&u) noexcept { reset(u.release()); - p_stor.second() = forward(u.get_deleter()); + p_stor.second() = std::forward(u.get_deleter()); return *this; } @@ -451,7 +455,7 @@ public: Box & > operator=(Box &&u) noexcept { reset(u.release()); - p_stor.second() = forward
(u.get_deleter()); + p_stor.second() = std::forward
(u.get_deleter()); return *this; } @@ -531,7 +535,7 @@ namespace detail { template typename detail::BoxIf::BoxType make_box(A &&...args) { - return Box(new T(forward(args)...)); + return Box(new T(std::forward(args)...)); } template @@ -904,7 +908,7 @@ inline void allocator_deallocate( namespace detail { template auto construct_test(A &&a, T *p, Args &&...args) -> - decltype(a.construct(p, forward(args)...), True()); + decltype(a.construct(p, std::forward(args)...), True()); template auto construct_test(A const &, T *, Args &&...) -> False; @@ -919,12 +923,12 @@ namespace detail { template inline void construct(True, A &a, T *p, Args &&...args) { - a.construct(p, forward(args)...); + a.construct(p, std::forward(args)...); } template inline void construct(False, A &, T *p, Args &&...args) { - ::new (p) T(forward(args)...); + ::new (p) T(std::forward(args)...); } } /* namespace detail */ @@ -932,7 +936,7 @@ template inline void allocator_construct(A &a, T *p, Args &&...args) { detail::construct( BoolConstant>(), - a, p, forward(args)... + a, p, std::forward(args)... ); } diff --git a/ostd/range.hh b/ostd/range.hh index 2d0710b..692f41f 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -224,13 +224,13 @@ namespace detail { ::new(&get_ref()) T(range); } explicit RangeIterator(T &&range): p_range(), p_init(true) { - ::new(&get_ref()) T(move(range)); + ::new(&get_ref()) T(std::move(range)); } RangeIterator(const RangeIterator &v): p_range(), p_init(true) { ::new(&get_ref()) T(v.get_ref()); } RangeIterator(RangeIterator &&v): p_range(), p_init(true) { - ::new(&get_ref()) T(move(v.get_ref())); + ::new(&get_ref()) T(std::move(v.get_ref())); } RangeIterator &operator=(const RangeIterator &v) { destroy(); @@ -332,7 +332,7 @@ public: RangeHalf(RangeHalf const &half): p_range(half.p_range) {} RangeHalf(RangeHalf const &half): p_range(half.p_range) {} - RangeHalf(RangeHalf &&half): p_range(move(half.p_range)) {} + RangeHalf(RangeHalf &&half): p_range(std::move(half.p_range)) {} RangeHalf &operator=(RangeHalf const &half) { p_range = half.p_range; @@ -340,7 +340,7 @@ public: } RangeHalf &operator=(RangeHalf &&half) { - p_range = move(half.p_range); + p_range = std::move(half.p_range); return *this; } @@ -562,12 +562,12 @@ struct InputRange { template JoinRange join(R1 r1, RR ...rr) const { - return JoinRange(iter(), move(r1), move(rr)...); + return JoinRange(iter(), std::move(r1), std::move(rr)...); } template ZipRange zip(R1 r1, RR ...rr) const { - return ZipRange(iter(), move(r1), move(rr)...); + return ZipRange(iter(), std::move(r1), std::move(rr)...); } RangeHalf half() const { @@ -660,7 +660,7 @@ struct InputRange { template>> inline auto operator|(R &&range, F &&func) { - return func(forward(range)); + return func(std::forward(range)); } inline auto reverse() { @@ -688,51 +688,55 @@ inline auto chunks(T n) { namespace detail { template inline auto join_proxy(T &&obj, Tuple &&tup, TupleIndices) { - return obj.join(forward(get(forward>(tup)))...); + return obj.join(std::forward( + get(std::forward>(tup)) + )...); } template inline auto zip_proxy(T &&obj, Tuple &&tup, TupleIndices) { - return obj.zip(forward(get(forward>(tup)))...); + return obj.zip(std::forward( + get(std::forward>(tup)) + )...); } } template inline auto join(R &&range) { - return [range = forward(range)](auto &&obj) mutable { - return obj.join(forward(range)); + return [range = std::forward(range)](auto &&obj) mutable { + return obj.join(std::forward(range)); }; } template inline auto join(R1 &&r1, R &&...rr) { return [ - ranges = forward_as_tuple(forward(r1), forward(rr)...) + ranges = forward_as_tuple(std::forward(r1), std::forward(rr)...) ] (auto &&obj) mutable { using Index = detail::MakeTupleIndices; return detail::join_proxy( - forward(obj), - forward(ranges), Index() + std::forward(obj), + std::forward(ranges), Index() ); }; } template inline auto zip(R &&range) { - return [range = forward(range)](auto &&obj) mutable { - return obj.zip(forward(range)); + return [range = std::forward(range)](auto &&obj) mutable { + return obj.zip(std::forward(range)); }; } template inline auto zip(R1 &&r1, R &&...rr) { return [ - ranges = forward_as_tuple(forward(r1), forward(rr)...) + ranges = forward_as_tuple(std::forward(r1), std::forward(rr)...) ] (auto &&obj) mutable { using Index = detail::MakeTupleIndices; return detail::zip_proxy( - forward(obj), - forward(ranges), Index() + std::forward(obj), + std::forward(ranges), Index() ); }; } @@ -789,13 +793,13 @@ public: p_beg(range.p_beg), p_end(range.p_end) {} HalfRange(HalfRange &&range): - p_beg(move(range.p_beg)), p_end(move(range.p_end)) + p_beg(std::move(range.p_beg)), p_end(std::move(range.p_end)) {} HalfRange(T const &beg, T const &end): p_beg(beg),p_end(end) {} HalfRange(T &&beg, T &&end): - p_beg(move(beg)), p_end(move(end)) + p_beg(std::move(beg)), p_end(std::move(end)) {} HalfRange &operator=(HalfRange const &range) { @@ -805,8 +809,8 @@ public: } HalfRange &operator=(HalfRange &&range) { - p_beg = move(range.p_beg); - p_end = move(range.p_end); + p_beg = std::move(range.p_beg); + p_end = std::move(range.p_end); return *this; } @@ -862,7 +866,7 @@ public: return p_beg.range().put(v); } bool put(RangeValue &&v) { - return p_beg.range().put(move(v)); + return p_beg.range().put(std::move(v)); } RangeValue *data() { return p_beg.data(); } @@ -884,14 +888,14 @@ public: ReverseRange() = delete; ReverseRange(T const &range): p_range(range) {} ReverseRange(ReverseRange const &it): p_range(it.p_range) {} - ReverseRange(ReverseRange &&it): p_range(move(it.p_range)) {} + ReverseRange(ReverseRange &&it): p_range(std::move(it.p_range)) {} ReverseRange &operator=(ReverseRange const &v) { p_range = v.p_range; return *this; } ReverseRange &operator=(ReverseRange &&v) { - p_range = move(v.p_range); + p_range = std::move(v.p_range); return *this; } ReverseRange &operator=(T const &v) { @@ -899,7 +903,7 @@ public: return *this; } ReverseRange &operator=(T &&v) { - p_range = move(v); + p_range = std::move(v); return *this; } @@ -959,14 +963,14 @@ public: MoveRange() = delete; MoveRange(T const &range): p_range(range) {} MoveRange(MoveRange const &it): p_range(it.p_range) {} - MoveRange(MoveRange &&it): p_range(move(it.p_range)) {} + MoveRange(MoveRange &&it): p_range(std::move(it.p_range)) {} MoveRange &operator=(MoveRange const &v) { p_range = v.p_range; return *this; } MoveRange &operator=(MoveRange &&v) { - p_range = move(v.p_range); + p_range = std::move(v.p_range); return *this; } MoveRange &operator=(T const &v) { @@ -974,7 +978,7 @@ public: return *this; } MoveRange &operator=(T &&v) { - p_range = move(v); + p_range = std::move(v); return *this; } @@ -1007,17 +1011,17 @@ public: Rsize push_front_n(Rsize n) { return p_range.push_front_n(n); } Rsize push_back_n(Rsize n) { return p_range.push_back_n(n); } - Rref front() const { return move(p_range.front()); } - Rref back() const { return move(p_range.back()); } + Rref front() const { return std::move(p_range.front()); } + Rref back() const { return std::move(p_range.back()); } - Rref operator[](Rsize i) const { return move(p_range[i]); } + Rref operator[](Rsize i) const { return std::move(p_range[i]); } MoveRange slice(Rsize start, Rsize end) const { return MoveRange(p_range.slice(start, end)); } bool put(Rval const &v) { return p_range.put(v); } - bool put(Rval &&v) { return p_range.put(move(v)); } + bool put(Rval &&v) { return p_range.put(std::move(v)); } }; template @@ -1170,7 +1174,7 @@ public: if (empty()) { return false; } - *(p_beg++) = move(v); + *(p_beg++) = std::move(v); return true; } @@ -1228,6 +1232,11 @@ inline PointerRange iter(T const (&array)[N]) { return PointerRange(array, N); } +template +inline PointerRange citer(T const (&array)[N]) { + return PointerRange(array, N); +} + namespace detail { struct PtrNat {}; } @@ -1273,7 +1282,7 @@ public: {} EnumeratedRange(EnumeratedRange &&it): - p_range(move(it.p_range)), p_index(it.p_index) + p_range(std::move(it.p_range)), p_index(it.p_index) {} EnumeratedRange &operator=(EnumeratedRange const &v) { @@ -1282,7 +1291,7 @@ public: return *this; } EnumeratedRange &operator=(EnumeratedRange &&v) { - p_range = move(v.p_range); + p_range = std::move(v.p_range); p_index = v.p_index; return *this; } @@ -1292,7 +1301,7 @@ public: return *this; } EnumeratedRange &operator=(T &&v) { - p_range = move(v); + p_range = std::move(v); p_index = 0; return *this; } @@ -1339,14 +1348,14 @@ public: p_range(it.p_range), p_remaining(it.p_remaining) {} TakeRange(TakeRange &&it): - p_range(move(it.p_range)), p_remaining(it.p_remaining) + p_range(std::move(it.p_range)), p_remaining(it.p_remaining) {} TakeRange &operator=(TakeRange const &v) { p_range = v.p_range; p_remaining = v.p_remaining; return *this; } TakeRange &operator=(TakeRange &&v) { - p_range = move(v.p_range); + p_range = std::move(v.p_range); p_remaining = v.p_remaining; return *this; } @@ -1391,14 +1400,14 @@ public: p_range(it.p_range), p_chunksize(it.p_chunksize) {} ChunksRange(ChunksRange &&it): - p_range(move(it.p_range)), p_chunksize(it.p_chunksize) + p_range(std::move(it.p_range)), p_chunksize(it.p_chunksize) {} ChunksRange &operator=(ChunksRange const &v) { p_range = v.p_range; p_chunksize = v.p_chunksize; return *this; } ChunksRange &operator=(ChunksRange &&v) { - p_range = move(v.p_range); + p_range = std::move(v.p_range); p_chunksize = v.p_chunksize; return *this; } @@ -1505,9 +1514,9 @@ private: public: JoinRange() = delete; JoinRange(R const &...ranges): p_ranges(ranges...) {} - JoinRange(R &&...ranges): p_ranges(forward(ranges)...) {} + JoinRange(R &&...ranges): p_ranges(std::forward(ranges)...) {} JoinRange(JoinRange const &v): p_ranges(v.p_ranges) {} - JoinRange(JoinRange &&v): p_ranges(move(v.p_ranges)) {} + JoinRange(JoinRange &&v): p_ranges(std::move(v.p_ranges)) {} JoinRange &operator=(JoinRange const &v) { p_ranges = v.p_ranges; @@ -1515,7 +1524,7 @@ public: } JoinRange &operator=(JoinRange &&v) { - p_ranges = move(v.p_ranges); + p_ranges = std::move(v.p_ranges); return *this; } @@ -1617,9 +1626,9 @@ private: public: ZipRange() = delete; ZipRange(R const &...ranges): p_ranges(ranges...) {} - ZipRange(R &&...ranges): p_ranges(forward(ranges)...) {} + ZipRange(R &&...ranges): p_ranges(std::forward(ranges)...) {} ZipRange(ZipRange const &v): p_ranges(v.p_ranges) {} - ZipRange(ZipRange &&v): p_ranges(move(v.p_ranges)) {} + ZipRange(ZipRange &&v): p_ranges(std::move(v.p_ranges)) {} ZipRange &operator=(ZipRange const &v) { p_ranges = v.p_ranges; @@ -1627,7 +1636,7 @@ public: } ZipRange &operator=(ZipRange &&v) { - p_ranges = move(v.p_ranges); + p_ranges = std::move(v.p_ranges); return *this; } @@ -1655,9 +1664,9 @@ struct AppenderRange: OutputRange, typename T::Value, typename T::Reference, typename T::Size, typename T::Difference> { AppenderRange(): p_data() {} AppenderRange(T const &v): p_data(v) {} - AppenderRange(T &&v): p_data(move(v)) {} + AppenderRange(T &&v): p_data(std::move(v)) {} AppenderRange(AppenderRange const &v): p_data(v.p_data) {} - AppenderRange(AppenderRange &&v): p_data(move(v.p_data)) {} + AppenderRange(AppenderRange &&v): p_data(std::move(v.p_data)) {} AppenderRange &operator=(AppenderRange const &v) { p_data = v.p_data; @@ -1665,7 +1674,7 @@ struct AppenderRange: OutputRange, typename T::Value, } AppenderRange &operator=(AppenderRange &&v) { - p_data = move(v.p_data); + p_data = std::move(v.p_data); return *this; } @@ -1675,7 +1684,7 @@ struct AppenderRange: OutputRange, typename T::Value, } AppenderRange &operator=(T &&v) { - p_data = move(v); + p_data = std::move(v); return *this; } @@ -1693,7 +1702,7 @@ struct AppenderRange: OutputRange, typename T::Value, } bool put(typename T::Value &&v) { - p_data.push(move(v)); + p_data.push(std::move(v)); return true; } @@ -1709,12 +1718,9 @@ inline AppenderRange appender() { template inline AppenderRange appender(T &&v) { - return AppenderRange(forward(v)); + return AppenderRange(std::forward(v)); } -// range of -template using RangeOf = decltype(iter(declval())); - } /* namespace ostd */ #endif diff --git a/ostd/set.hh b/ostd/set.hh index 21dc160..87104dd 100644 --- a/ostd/set.hh +++ b/ostd/set.hh @@ -78,8 +78,8 @@ namespace detail { SetImpl(SetImpl const &m, A const &alloc): Base(m, alloc) {} - SetImpl(SetImpl &&m): Base(move(m)) {} - SetImpl(SetImpl &&m, A const &alloc): Base(move(m), alloc) {} + SetImpl(SetImpl &&m): Base(std::move(m)) {} + SetImpl(SetImpl &&m, A const &alloc): Base(std::move(m), alloc) {} template && IsConvertible, Value> @@ -129,7 +129,7 @@ namespace detail { } SetImpl &operator=(SetImpl &&m) { - Base::operator=(move(m)); + Base::operator=(std::move(m)); return *this; } diff --git a/ostd/stream.hh b/ostd/stream.hh index 556313c..229fe57 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -8,6 +8,8 @@ #include +#include + #include "ostd/platform.hh" #include "ostd/types.hh" #include "ostd/range.hh" @@ -146,7 +148,7 @@ public: } else if (Size(need) < sizeof(buf)) { return write_bytes(buf, need) == Size(need); } - Vector s; + std::vector s; s.reserve(need); format(detail::UnsafeWritefRange(s.data()), fmt, args...); return write_bytes(s.data(), need) == Size(need); diff --git a/ostd/string.hh b/ostd/string.hh index 800446e..40dd7ac 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -15,6 +15,7 @@ #include "ostd/vector.hh" #include "ostd/functional.hh" #include "ostd/type_traits.hh" +#include "ostd/algorithm.hh" namespace ostd { static constexpr Size npos = -1; @@ -342,7 +343,7 @@ public: } StringBase(StringBase &&s): p_len(s.p_len), p_cap(s.p_cap), - p_buf(s.p_buf.first(), move(s.p_buf.second())) + p_buf(s.p_buf.first(), std::move(s.p_buf.second())) { s.p_len = s.p_cap = 0; s.p_buf.first() = reinterpret_cast(&s.p_len); @@ -455,7 +456,7 @@ public: p_len = v.p_len; p_cap = v.p_cap; p_buf.~StrPair(); - new (&p_buf) StrPair(v.release(), move(v.p_buf.second())); + new (&p_buf) StrPair(v.release(), std::move(v.p_buf.second())); if (!p_cap) { p_buf.first() = reinterpret_cast(&p_len); } @@ -835,7 +836,7 @@ struct ToString diff --git a/ostd/tuple.hh b/ostd/tuple.hh index d389f5a..2443655 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -64,7 +64,7 @@ namespace detail { template, TupleLeaf> && IsConstructible >> - explicit TupleLeaf(T &&t): p_value(forward(t)) { + explicit TupleLeaf(T &&t): p_value(std::forward(t)) { static_assert( !IsReference || ( IsLvalueReference && ( @@ -80,7 +80,7 @@ namespace detail { template explicit TupleLeaf(Constant, A const &, T &&t): - p_value(forward(t)) + p_value(std::forward(t)) { static_assert( !IsLvalueReference || ( @@ -97,7 +97,7 @@ namespace detail { template explicit TupleLeaf(Constant, A const &a, T &&t): - p_value(allocator_arg, a, forward(t)) + p_value(allocator_arg, a, std::forward(t)) { static_assert( !IsLvalueReference || ( @@ -114,7 +114,7 @@ namespace detail { template explicit TupleLeaf(Constant, A const &a, T &&t): - p_value(forward(t), a) + p_value(std::forward(t), a) { static_assert( !IsLvalueReference || ( @@ -134,7 +134,7 @@ namespace detail { template TupleLeaf &operator=(T &&t) { - p_value = forward(t); + p_value = std::forward(t); return *this; } @@ -168,21 +168,21 @@ namespace detail { template, TupleLeaf> && IsConstructible >> - explicit TupleLeaf(T &&t): H(forward(t)) {} + explicit TupleLeaf(T &&t): H(std::forward(t)) {} template explicit TupleLeaf(Constant, A const &, T &&t): - H(forward(t)) + H(std::forward(t)) {} template explicit TupleLeaf(Constant, A const &a, T &&t): - H(allocator_arg, a, forward(t)) + H(allocator_arg, a, std::forward(t)) {} template explicit TupleLeaf(Constant, A const &a, T &&t): - H(forward(t), a) + H(std::forward(t), a) {} TupleLeaf(TupleLeaf const &) = default; @@ -190,7 +190,7 @@ namespace detail { template TupleLeaf &operator=(T &&t) { - H::operator=(forward(t)); + H::operator=(std::forward(t)); return *this; } @@ -244,7 +244,7 @@ namespace detail { TupleIndices, TupleTypes, TupleIndices, TupleTypes, T &&...t ): - TupleLeaf(forward(t))..., + TupleLeaf(std::forward(t))..., TupleLeaf()... {} @@ -259,7 +259,7 @@ namespace detail { ): TupleLeaf( UsesAllocatorConstructor, a, - forward(t) + std::forward(t) )..., TupleLeaf(UsesAllocatorConstructor, a)... {} @@ -269,7 +269,7 @@ namespace detail { >> TupleBase(T &&t): TupleLeaf( - forward>>(get(t)) + std::forward>>(get(t)) )... {} @@ -280,14 +280,14 @@ namespace detail { TupleLeaf( UsesAllocatorConstructor< A, Alloc, TupleElement> - >, a, forward>>(get(t)) + >, a, std::forward>>(get(t)) )... {} template EnableIf>, TupleBase &> operator=(T &&t) { tuple_swallow(TupleLeaf::operator=( - forward>>(get(t)) + std::forward>>(get(t)) )...); return *this; } @@ -304,7 +304,7 @@ namespace detail { TupleBase &operator=(TupleBase &&t) { tuple_swallow(TupleLeaf::operator=( - forward((static_cast &>(t)).get()) + std::forward((static_cast &>(t)).get()) )...); return *this; } @@ -382,7 +382,7 @@ public: detail::MakeTupleTypes(), detail::MakeTupleIndices(), detail::MakeTupleTypes(), - forward(t)... + std::forward(t)... ) {} @@ -415,7 +415,7 @@ public: detail::MakeTupleTypes(), detail::MakeTupleIndices(), detail::MakeTupleTypes(), - forward(t)... + std::forward(t)... ) {} @@ -440,31 +440,31 @@ public: detail::MakeTupleTypes(), detail::MakeTupleIndices(), detail::MakeTupleTypes(), - forward(t)... + std::forward(t)... ) {} template, bool > = true> - Tuple(T &&t): p_base(forward(t)) {} + Tuple(T &&t): p_base(std::forward(t)) {} template && !detail::TupleConvertible, bool > = true> - Tuple(T &&t): p_base(forward(t)) {} + Tuple(T &&t): p_base(std::forward(t)) {} template >> Tuple(AllocatorArg, Alloc const &a, T &&t): - p_base(allocator_arg, a, forward(t)) + p_base(allocator_arg, a, std::forward(t)) {} template>> Tuple &operator=(T &&t) { - p_base.operator=(forward(t)); + p_base.operator=(std::forward(t)); return *this; } @@ -548,14 +548,14 @@ namespace detail { template inline Tuple::Type...> make_tuple(T &&...t) { - return Tuple::Type...>(forward(t)...); + return Tuple::Type...>(std::forward(t)...); } /* forward as tuple */ template inline Tuple forward_as_tuple(T &&...t) { - return Tuple(forward(t)...); + return Tuple(std::forward(t)...); } /* tuple relops */ @@ -642,7 +642,10 @@ Pair::Pair( PiecewiseConstruct, Tuple &fa, Tuple &sa, detail::TupleIndices, detail::TupleIndices ): - first(forward(get(fa))...), second(forward(get(sa))...) + first( + std::forward(get(fa))...), + second(std::forward(get(sa))... + ) {} namespace detail { @@ -652,8 +655,8 @@ namespace detail { PiecewiseConstruct, Tuple &fa, Tuple &sa, detail::TupleIndices, detail::TupleIndices ): - p_first(forward(get(fa))...), - p_second(forward(get(sa))...) + p_first(std::forward(get(fa))...), + p_second(std::forward(get(sa))...) {} template @@ -662,8 +665,8 @@ namespace detail { PiecewiseConstruct, Tuple &fa, Tuple &sa, detail::TupleIndices, detail::TupleIndices ): - T(forward(get(fa))...), - p_second(forward(get(sa))...) + T(std::forward(get(fa))...), + p_second(std::forward(get(sa))...) {} template @@ -672,8 +675,8 @@ namespace detail { PiecewiseConstruct, Tuple &fa, Tuple &sa, detail::TupleIndices, detail::TupleIndices ): - U(forward(get(sa))...), - p_first(forward(get(fa))...) + U(std::forward(get(sa))...), + p_first(std::forward(get(fa))...) {} template @@ -682,8 +685,8 @@ namespace detail { PiecewiseConstruct, Tuple &fa, Tuple &sa, detail::TupleIndices, detail::TupleIndices ): - T(forward(get(fa))...), - U(forward(get(sa))...) + T(std::forward(get(fa))...), + U(std::forward(get(sa))...) {} } /* namespace detail */ diff --git a/ostd/utility.hh b/ostd/utility.hh index 104093b..e55dc91 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -8,39 +8,13 @@ #include +#include + #include "ostd/type_traits.hh" #include "ostd/internal/tuple.hh" namespace ostd { -/* move */ - -template -inline constexpr RemoveReference &&move(T &&v) noexcept { - return static_cast &&>(v); -} - -/* forward */ - -template -inline constexpr T &&forward(RemoveReference &v) noexcept { - return static_cast(v); -} - -template -inline constexpr T &&forward(RemoveReference &&v) noexcept { - return static_cast(v); -} - -/* exchange */ - -template -inline T exchange(T &v, U &&nv) { - T old = move(v); - v = forward(nv); - return old; -} - /* declval */ template @@ -66,9 +40,9 @@ namespace detail { inline void swap_fb( T &a, T &b, EnableIf(0))::value, bool> = true ) noexcept(IsNothrowMoveConstructible && IsNothrowMoveAssignable) { - T c(move(a)); - a = move(b); - b = move(c); + T c(std::move(a)); + a = std::move(b); + b = std::move(c); } } @@ -118,7 +92,7 @@ struct Pair { template Pair(TT &&x, UU &&y): - first(forward(x)), second(forward(y)) + first(std::forward(x)), second(std::forward(y)) {} template @@ -126,7 +100,7 @@ struct Pair { template Pair(Pair &&v): - first(move(v.first)), second(move(v.second)) + first(std::move(v.first)), second(std::move(v.second)) {} template @@ -154,15 +128,15 @@ struct Pair { Pair &operator=(Pair &&v) noexcept( IsNothrowMoveAssignable && IsNothrowMoveAssignable ) { - first = move(v.first); - second = move(v.second); + first = std::move(v.first); + second = std::move(v.second); return *this; } template Pair &operator=(Pair &&v) { - first = forward(v.first); - second = forward(v.second); + first = std::forward(v.first); + second = std::forward(v.second); return *this; } @@ -209,7 +183,7 @@ inline Pair< return Pair< typename detail::MakePairRet::Type, typename detail::MakePairRet::Type - >(forward(a), forward(b)); + >(std::forward(a), std::forward(b)); } template @@ -272,10 +246,10 @@ namespace detail { template static T const &get(Pair const &p) { return p.first; } template - static T &&get(Pair &&p) { return forward(p.first); } + static T &&get(Pair &&p) { return std::forward(p.first); } template static T const &&get(Pair const &&p) { - return forward(p.first); + return std::forward(p.first); } }; @@ -286,10 +260,10 @@ namespace detail { template static U const &get(Pair const &p) { return p.second; } template - static U &&get(Pair &&p) { return forward(p.second); } + static U &&get(Pair &&p) { return std::forward(p.second); } template static T const &&get(Pair const &&p) { - return forward(p.second); + return std::forward(p.second); } }; } @@ -306,12 +280,12 @@ inline TupleElement> const &get(Pair const &p) noexcept { template inline TupleElement> &&get(Pair &&p) noexcept { - return detail::GetPair::get(move(p)); + return detail::GetPair::get(std::move(p)); } template inline TupleElement> const &&get(Pair const &&p) noexcept { - return detail::GetPair::get(move(p)); + return detail::GetPair::get(std::move(p)); } namespace detail { @@ -351,7 +325,7 @@ namespace detail { template CompressedPairBase(TT &&a, UU &&b): - p_first(forward(a)), p_second(forward(b)) + p_first(std::forward(a)), p_second(std::forward(b)) {} template @@ -378,7 +352,7 @@ namespace detail { template CompressedPairBase(TT &&a, UU &&b): - T(forward(a)), p_second(forward(b)) + T(std::forward(a)), p_second(std::forward(b)) {} template @@ -404,7 +378,7 @@ namespace detail { template CompressedPairBase(TT &&a, UU &&b): - U(forward(b)), p_first(forward(a)) + U(std::forward(b)), p_first(std::forward(a)) {} template @@ -428,7 +402,7 @@ namespace detail { struct CompressedPairBase: T, U { template CompressedPairBase(TT &&a, UU &&b): - T(forward(a)), U(forward(b)) + T(std::forward(a)), U(std::forward(b)) {} template @@ -452,7 +426,7 @@ namespace detail { template CompressedPair(TT &&a, UU &&b): - Base(forward(a), forward(b)) + Base(std::forward(a), std::forward(b)) {} template diff --git a/ostd/vector.hh b/ostd/vector.hh index b0e8340..0f205f7 100644 --- a/ostd/vector.hh +++ b/ostd/vector.hh @@ -1,4 +1,4 @@ -/* Self-expanding dynamic array implementation for OctaSTD. +/* OctaSTD extensions for std::vector. * * This file is part of OctaSTD. See COPYING.md for futher information. */ @@ -6,504 +6,40 @@ #ifndef OSTD_VECTOR_HH #define OSTD_VECTOR_HH -#include -#include +#include -#include "ostd/type_traits.hh" -#include "ostd/utility.hh" #include "ostd/range.hh" -#include "ostd/algorithm.hh" -#include "ostd/initializer_list.hh" -#include "ostd/memory.hh" namespace ostd { -template> -class Vector { - using VecPair = detail::CompressedPair, A>; - - ostd::Size p_len, p_cap; - VecPair p_buf; - - void insert_base(Size idx, Size n) { - if (p_len + n > p_cap) { - reserve(p_len + n); - } - p_len += n; - for (Size i = p_len - 1; i > idx + n - 1; --i) { - p_buf.first()[i] = move(p_buf.first()[i - n]); - } - } - - template - void ctor_from_range( - R &range, EnableIf< - IsFiniteRandomAccessRange && IsPod && - IsSame>>, bool - > = true - ) { - RangeSize l = range.size(); - reserve(l); - p_len = l; - range.copy(p_buf.first(), l); - } - - template - void ctor_from_range( - R &range, EnableIf< - !IsFiniteRandomAccessRange || !IsPod || - !IsSame>>, bool - > = true - ) { - Size i = 0; - for (; !range.empty(); range.pop_front()) { - reserve(i + 1); - allocator_construct( - p_buf.second(), &p_buf.first()[i], range.front() - ); - ++i; - p_len = i; - } - } - - void copy_contents(Vector const &v) { - if (IsPod) { - memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); - } else { - Pointer cur = p_buf.first(), last = p_buf.first() + p_len; - Pointer vbuf = v.p_buf.first(); - while (cur != last) { - allocator_construct(p_buf.second(), cur++, *vbuf++); - } - } - } - -public: - using Size = ostd::Size; - using Difference = Ptrdiff; - using Value = T; - using Reference = T &; - using ConstReference = T const &; - using Pointer = AllocatorPointer; - using ConstPointer = AllocatorConstPointer; - using Range = PointerRange; - using ConstRange = PointerRange; - using Allocator = A; - - Vector(A const &a = A()): p_len(0), p_cap(0), p_buf(nullptr, a) {} - - explicit Vector(Size n, T const &val = T(), A const &al = A()): Vector(al) { - if (!n) { - return; - } - p_buf.first() = allocator_allocate(p_buf.second(), n); - p_len = p_cap = n; - Pointer cur = p_buf.first(), last = p_buf.first() + n; - while (cur != last) { - allocator_construct(p_buf.second(), cur++, val); - } - } - - Vector(Vector const &v): - p_len(0), p_cap(0), p_buf(nullptr, allocator_container_copy( - v.p_buf.second()) - ) - { - reserve(v.p_cap); - p_len = v.p_len; - copy_contents(v); - } - - Vector(Vector const &v, A const &a): p_len(0), p_cap(0), p_buf(nullptr, a) { - reserve(v.p_cap); - p_len = v.p_len; - copy_contents(v); - } - - Vector(Vector &&v): - p_len(v.p_len), p_cap(v.p_cap), p_buf( - v.p_buf.first(), move(v.p_buf.second()) - ) - { - v.p_buf.first() = nullptr; - v.p_len = v.p_cap = 0; - } - - Vector(Vector &&v, A const &a): p_len(0), p_cap(0), p_buf(nullptr, a) { - if (a != v.p_buf.second()) { - reserve(v.p_cap); - p_len = v.p_len; - if (IsPod) { - memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); - } else { - Pointer cur = p_buf.first(), last = p_buf.first() + p_len; - Pointer vbuf = v.p_buf.first(); - while (cur != last) { - allocator_construct(p_buf.second(), cur++, move(*vbuf++)); - } - } - return; - } - p_buf.first() = v.p_buf.first(); - p_len = v.p_len; - p_cap = v.p_cap; - v.p_buf.first() = nullptr; - v.p_len = v.p_cap = 0; - } - - Vector(ConstRange r, A const &a = A()): Vector(a) { - reserve(r.size()); - if (IsPod) { - memcpy(p_buf.first(), &r[0], r.size() * sizeof(T)); - } else { - for (Size i = 0; i < r.size(); ++i) { - allocator_construct(p_buf.second(), &p_buf.first()[i], r[i]); - } - } - p_len = r.size(); - } - - Vector(std::initializer_list v, A const &a = A()): - Vector(ConstRange(v.begin(), v.size()), a) - {} - - template && IsConvertible, Value> - >> - Vector(R range, A const &a = A()): Vector(a) { - ctor_from_range(range); - } - - ~Vector() { - clear(); - allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); - } - - void clear() { - if (p_len > 0 && !IsPod) { - Pointer cur = p_buf.first(), last = p_buf.first() + p_len; - while (cur != last) { - allocator_destroy(p_buf.second(), cur++); - } - } - p_len = 0; - } - - Vector &operator=(Vector const &v) { - if (this == &v) { - return *this; - } - clear(); - if (AllocatorPropagateOnContainerCopyAssignment) { - if (p_buf.second() != v.p_buf.second() && p_cap) { - allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); - p_cap = 0; - } - p_buf.second() = v.p_buf.second(); - } - reserve(v.p_cap); - p_len = v.p_len; - copy_contents(v); - return *this; - } - - Vector &operator=(Vector &&v) { - clear(); - if (p_buf.first()) { - allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); - } - if (AllocatorPropagateOnContainerMoveAssignment) { - p_buf.second() = v.p_buf.second(); - } - p_len = v.p_len; - p_cap = v.p_cap; - p_buf.~VecPair(); - new (&p_buf) VecPair(v.release(), move(v.p_buf.second())); - return *this; - } - - Vector &operator=(std::initializer_list il) { - clear(); - Size ilen = il.end() - il.begin(); - reserve(ilen); - if (IsPod) { - memcpy(p_buf.first(), il.begin(), ilen); - } else { - Pointer tbuf = p_buf.first(), ibuf = il.begin(), - last = il.end(); - while (ibuf != last) { - allocator_construct(p_buf.second(), - tbuf++, *ibuf++); - } - } - p_len = ilen; - return *this; - } - - template && IsConvertible, Value> - >> - Vector &operator=(R range) { - clear(); - ctor_from_range(range); - return *this; - } - - void resize(Size n, T const &v = T()) { - if (!n) { - clear(); - return; - } - Size l = p_len; - reserve(n); - p_len = n; - if (IsPod) { - for (Size i = l; i < p_len; ++i) { - p_buf.first()[i] = T(v); - } - } else { - Pointer first = p_buf.first() + l; - Pointer last = p_buf.first() + p_len; - while (first != last) { - allocator_construct(p_buf.second(), first++, v); - } - } - } - - void reserve(Size n) { - if (n <= p_cap) { - return; - } - Size oc = p_cap; - if (!oc) { - p_cap = max(n, Size(8)); - } else { - while (p_cap < n) p_cap *= 2; - } - Pointer tmp = allocator_allocate(p_buf.second(), p_cap); - if (oc > 0) { - if (IsPod) { - memcpy(tmp, p_buf.first(), p_len * sizeof(T)); - } else { - Pointer cur = p_buf.first(), tcur = tmp, - last = tmp + p_len; - while (tcur != last) { - allocator_construct(p_buf.second(), tcur++, move(*cur)); - allocator_destroy(p_buf.second(), cur); - ++cur; - } - } - allocator_deallocate(p_buf.second(), p_buf.first(), oc); - } - p_buf.first() = tmp; - } - - T &operator[](Size i) { return p_buf.first()[i]; } - T const &operator[](Size i) const { return p_buf.first()[i]; } - - T *at(Size i) { - if (!in_range(i)) { - return nullptr; - } - return &p_buf.first()[i]; - } - T const *at(Size i) const { - if (!in_range(i)) { - return nullptr; - } - return &p_buf.first()[i]; - } - - T &push(T const &v) { - if (p_len == p_cap) { - reserve(p_len + 1); - } - allocator_construct(p_buf.second(), &p_buf.first()[p_len], v); - return p_buf.first()[p_len++]; - } - - T &push(T &&v) { - if (p_len == p_cap) { - reserve(p_len + 1); - } - allocator_construct(p_buf.second(), &p_buf.first()[p_len], move(v)); - return p_buf.first()[p_len++]; - } - - T &push() { - if (p_len == p_cap) { - reserve(p_len + 1); - } - allocator_construct(p_buf.second(), &p_buf.first()[p_len]); - return p_buf.first()[p_len++]; - } - - Range push_n(T const *v, Size n) { - reserve(p_len + n); - if (IsPod) { - memcpy(p_buf.first() + p_len, v, n * sizeof(T)); - } else { - for (Size i = 0; i < n; ++i) { - allocator_construct( - p_buf.second(), &p_buf.first()[p_len + i], v[i] - ); - } - } - p_len += n; - return Range(&p_buf.first()[p_len - n], &p_buf.first()[p_len]); - } - - template - T &emplace_back(U &&...args) { - if (p_len == p_cap) { - reserve(p_len + 1); - } - allocator_construct( - p_buf.second(), &p_buf.first()[p_len], forward(args)... - ); - return p_buf.first()[p_len++]; - } - - void pop() { - if (!IsPod) { - allocator_destroy(p_buf.second(), &p_buf.first()[--p_len]); - } else { - --p_len; - } - } - - T &front() { return p_buf.first()[0]; } - T const &front() const { return p_buf.first()[0]; } - - T &back() { return p_buf.first()[p_len - 1]; } - T const &back() const { return p_buf.first()[p_len - 1]; } - - Value *data() { return reinterpret_cast(p_buf.first()); } - Value const *data() const { - return reinterpret_cast(p_buf.first()); - } - - Size size() const { return p_len; } - Size capacity() const { return p_cap; } - - void advance(Size s) { p_len += s; } - - Size max_size() const { return Size(~0) / sizeof(T); } - - bool empty() const { return (p_len == 0); } - - bool in_range(Size idx) { return idx < p_len; } - bool in_range(int idx) { return idx >= 0 && Size(idx) < p_len; } - bool in_range(Value const *ptr) { - return ptr >= p_buf.first() && ptr < &p_buf.first()[p_len]; - } - - Value *release() { - Pointer r = p_buf.first(); - p_buf.first() = nullptr; - p_len = p_cap = 0; - return reinterpret_cast(r); - } - - Range insert(Size idx, T &&v) { - insert_base(idx, 1); - p_buf.first()[idx] = move(v); - return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); - } - - Range insert(Size idx, T const &v) { - insert_base(idx, 1); - p_buf.first()[idx] = v; - return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); - } - - Range insert(Size idx, Size n, T const &v) { - insert_base(idx, n); - for (Size i = 0; i < n; ++i) { - p_buf.first()[idx + i] = v; - } - return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); - } - - template - Range insert_range(Size idx, U range) { - Size l = range.size(); - insert_base(idx, l); - for (Size i = 0; i < l; ++i) { - p_buf.first()[idx + i] = range.front(); - range.pop_front(); - } - return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); - } - - Range insert(Size idx, std::initializer_list il) { - return insert_range(idx, ostd::iter(il)); - } - - Range iter() { - return Range(p_buf.first(), p_buf.first() + p_len); - } - ConstRange iter() const { - return ConstRange(p_buf.first(), p_buf.first() + p_len); - } - ConstRange citer() const { - return ConstRange(p_buf.first(), p_buf.first() + p_len); - } - - Range iter_cap() { - return Range(p_buf.first(), p_buf.first() + p_cap); - } - - void swap(Vector &v) { - detail::swap_adl(p_len, v.p_len); - detail::swap_adl(p_cap, v.p_cap); - detail::swap_adl(p_buf.first(), v.p_buf.first()); - if (AllocatorPropagateOnContainerSwap) { - detail::swap_adl(p_buf.second(), v.p_buf.second()); - } - } - - A get_allocator() const { - return p_buf.second(); - } -}; - -template -inline bool operator==(Vector const &x, Vector const &y) { - return equal(x.iter(), y.iter()); +template +inline PointerRange iter(std::vector &v) { + return PointerRange{v.data(), v.size()}; } -template -inline bool operator!=(Vector const &x, Vector const &y) { - return !(x == y); +template +inline PointerRange iter(std::vector const &v) { + return PointerRange{v.data(), v.size()}; } -template -inline bool operator<(Vector const &x, Vector const &y) { - using Range = typename Vector::Range; - Range range1 = x.iter(), range2 = y.iter(); - while (!range1.empty() && !range2.empty()) { - if (range1.front() < range2.front()) return true; - if (range2.front() < range1.front()) return false; - range1.pop_front(); - range2.pop_front(); +template +inline PointerRange citer(std::vector const &v) { + return PointerRange{v.data(), v.size()}; +} + +template +inline std::vector make_vector(R range) { + /* TODO: specialize for contiguous ranges and matching value types */ + std::vector ret; + for (; !range.empty(); range.pop_front()) { + ret.push_back(range.front()); } - return (range1.empty() && !range2.empty()); + return ret; } -template -inline bool operator>(Vector const &x, Vector const &y) { - return (y < x); -} - -template -inline bool operator<=(Vector const &x, Vector const &y) { - return !(y < x); -} - -template -inline bool operator>=(Vector const &x, Vector const &y) { - return !(x < y); +template +inline std::vector> make_vector(R range) { + return make_vector>(std::move(range)); } } /* namespace ostd */