diff --git a/examples/format.cc b/examples/format.cc index 4222497..98ade79 100644 --- a/examples/format.cc +++ b/examples/format.cc @@ -12,7 +12,7 @@ struct Foo { /* implementing formatting for custom objects - external function */ template -bool to_format(const Foo &, R &writer, const FormatSpec &fs) { +bool to_format(Foo const &, R &writer, FormatSpec const &fs) { switch (fs.spec()) { case 'i': writer.put_string("Foo1"); @@ -27,7 +27,7 @@ bool to_format(const Foo &, R &writer, const FormatSpec &fs) { struct Bar { /* implementing formatting for custom objects - method */ template - bool to_format(R &writer, const FormatSpec &fs) const { + bool to_format(R &writer, FormatSpec const &fs) const { switch (fs.spec()) { case 'i': writer.put_string("Bar1"); @@ -64,7 +64,7 @@ int main() { writefln("{ %-#(%s: %d, %) }", m); /* tuple format test */ - Tuple xt[] = { + Tuple xt[] = { make_tuple(5, 3.14f, "foo"), make_tuple(3, 1.23f, "bar"), make_tuple(9, 8.66f, "baz") diff --git a/examples/signal.cc b/examples/signal.cc index d196e0b..4db7f91 100644 --- a/examples/signal.cc +++ b/examples/signal.cc @@ -9,8 +9,8 @@ struct SignalTest { * can actually emit (in that case, the reference passed to each * callback will always be const to make sure nothing changes) */ - Signal on_simple = this; - Signal< SignalTest, float > on_param = this; + Signal on_simple = this; + Signal on_param = this; SignalTest(): p_param(3.14f) { /* we can connect methods */ @@ -48,7 +48,7 @@ int main() { /* we can connect lambdas, including closures * this callback can access "test" easily and it will still work */ - auto idx = st.on_simple.connect([&](const SignalTest &, int v, + auto idx = st.on_simple.connect([&](SignalTest const &, int v, ConstCharRange str) { writefln("and lambda test: %d, %s (%d)", v, str, test); }); diff --git a/ostd/algorithm.hh b/ostd/algorithm.hh index 2f062c1..34c0743 100644 --- a/ostd/algorithm.hh +++ b/ostd/algorithm.hh @@ -156,20 +156,20 @@ inline auto sort() { /* min/max(_element) */ template -inline const T &min(const T &a, const T &b) { +inline T const &min(T const &a, T const &b) { return (a < b) ? a : b; } template -inline const T &min_cmp(const T &a, const T &b, C compare) { +inline T const &min_cmp(T const &a, T const &b, C compare) { return compare(a, b) ? a : b; } template -inline const T &max(const T &a, const T &b) { +inline T const &max(T const &a, T const &b) { return (a < b) ? b : a; } template -inline const T &max_cmp(const T &a, const T &b, C compare) { +inline T const &max_cmp(T const &a, T const &b, C compare) { return compare(a, b) ? b : a; } @@ -247,12 +247,12 @@ inline T max_cmp(std::initializer_list il, C compare) { /* clamp */ template -inline T clamp(const T &v, const U &lo, const U &hi) { +inline T clamp(T const &v, U const &lo, U const &hi) { return ostd::max(T(lo), ostd::min(v, T(hi))); } template -inline T clamp(const T &v, const U &lo, const U &hi, C compare) { +inline T clamp(T const &v, U const &lo, U const &hi, C compare) { return ostd::max_cmp(T(lo), ostd::min_cmp(v, T(hi), compare), compare); } @@ -352,7 +352,7 @@ inline auto none_of(F &&func) { } template -inline R find(R range, const T &v) { +inline R find(R range, T const &v) { for (; !range.empty(); range.pop_front()) if (range.front() == v) break; @@ -367,7 +367,7 @@ inline auto find(T &&v) { } template -inline R find_last(R range, const T &v) { +inline R find_last(R range, T const &v) { range = find(range, v); if (!range.empty()) for (;;) { R prev = range; @@ -449,7 +449,7 @@ inline auto find_one_of(R &&values) { } template -inline RangeSize count(R range, const T &v) { +inline RangeSize count(R range, T const &v) { RangeSize ret = 0; for (; !range.empty(); range.pop_front()) if (range.front() == v) @@ -574,7 +574,7 @@ inline R2 reverse_copy(R1 irange, R2 orange) { } template -inline void fill(R range, const T &v) { +inline void fill(R range, T const &v) { for (; !range.empty(); range.pop_front()) range.front() = v; } @@ -666,14 +666,14 @@ private: public: MapRange() = delete; template - MapRange(const T &range, FF &&func): + MapRange(T const &range, FF &&func): p_range(range), p_func(forward(func)) {} - MapRange(const MapRange &it): + 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)) {} - MapRange &operator=(const MapRange &v) { + MapRange &operator=(MapRange const &v) { p_range = v.p_range; p_func = v.p_func; return *this; @@ -687,17 +687,17 @@ public: bool empty() const { return p_range.empty(); } RangeSize size() const { return p_range.size(); } - bool equals_front(const MapRange &r) const { + bool equals_front(MapRange const &r) const { return p_range.equals_front(r.p_range); } - bool equals_back(const MapRange &r) const { + bool equals_back(MapRange const &r) const { return p_range.equals_front(r.p_range); } - RangeDifference distance_front(const MapRange &r) const { + RangeDifference distance_front(MapRange const &r) const { return p_range.distance_front(r.p_range); } - RangeDifference distance_back(const MapRange &r) const { + RangeDifference distance_back(MapRange const &r) const { return p_range.distance_back(r.p_range); } @@ -766,11 +766,11 @@ private: public: FilterRange() = delete; template - FilterRange(const T &range, P &&pred): p_range(range), + FilterRange(T const &range, P &&pred): p_range(range), p_pred(forward

(pred)) { advance_valid(); } - FilterRange(const FilterRange &it): p_range(it.p_range), + FilterRange(FilterRange const &it): p_range(it.p_range), p_pred(it.p_pred) { advance_valid(); } @@ -779,7 +779,7 @@ public: advance_valid(); } - FilterRange &operator=(const FilterRange &v) { + FilterRange &operator=(FilterRange const &v) { p_range = v.p_range; p_pred = v.p_pred; advance_valid(); @@ -794,7 +794,7 @@ public: bool empty() const { return p_range.empty(); } - bool equals_front(const FilterRange &r) const { + bool equals_front(FilterRange const &r) const { return p_range.equals_front(r.p_range); } diff --git a/ostd/array.hh b/ostd/array.hh index 6fa2ac3..e7d7ea1 100644 --- a/ostd/array.hh +++ b/ostd/array.hh @@ -21,29 +21,29 @@ struct Array { using Difference = Ptrdiff; using Value = T; using Reference = T &; - using ConstReference = const T &; + using ConstReference = T const &; using Pointer = T *; - using ConstPointer = const T *; + using ConstPointer = T const *; using Range = PointerRange; - using ConstRange = PointerRange; + using ConstRange = PointerRange; T &operator[](Size i) { return p_buf[i]; } - const T &operator[](Size i) const { return p_buf[i]; } + T const &operator[](Size i) const { return p_buf[i]; } T *at(Size i) { if (!in_range(i)) return nullptr; return &p_buf[i]; } - const T *at(Size i) const { + T const *at(Size i) const { if (!in_range(i)) return nullptr; return &p_buf[i]; } T &front() { return p_buf[0]; } - const T &front() const { return p_buf[0]; } + T const &front() const { return p_buf[0]; } T &back() { return p_buf[(N > 0) ? (N - 1) : 0]; } - const T &back() const { return p_buf[(N > 0) ? (N - 1) : 0]; } + T const &back() const { return p_buf[(N > 0) ? (N - 1) : 0]; } Size size() const { return N; } Size max_size() const { return Size(~0) / sizeof(T); } @@ -90,7 +90,7 @@ inline TupleElement> &get(Array &a) { } template -inline const TupleElement> &get(const Array &a) { +inline TupleElement> const &get(Array const &a) { return a[I]; } @@ -100,37 +100,37 @@ inline TupleElement> &&get(Array &&a) { } template -inline const TupleElement> &&get(const Array &&a) { +inline TupleElement> const &&get(Array const &&a) { return move(a.p_buf[I]); } template -inline bool operator==(const Array &x, const Array &y) { +inline bool operator==(Array const &x, Array const &y) { return equal(x.iter(), y.iter()); } template -inline bool operator!=(const Array &x, const Array &y) { +inline bool operator!=(Array const &x, Array const &y) { return !(x == y); } template -inline bool operator<(const Array &x, const Array &y) { +inline bool operator<(Array const &x, Array const &y) { return lexicographical_compare(x.iter(), y.iter()); } template -inline bool operator>(const Array &x, const Array &y) { +inline bool operator>(Array const &x, Array const &y) { return (y < x); } template -inline bool operator<=(const Array &x, const Array &y) { +inline bool operator<=(Array const &x, Array const &y) { return !(y < x); } template -inline bool operator>=(const Array &x, const Array &y) { +inline bool operator>=(Array const &x, Array const &y) { return !(x < y); } diff --git a/ostd/atomic.hh b/ostd/atomic.hh index 385acbb..65c3fdd 100644 --- a/ostd/atomic.hh +++ b/ostd/atomic.hh @@ -46,18 +46,18 @@ namespace detail { template static inline EnableIf< - CanAtomicAssign *, T> - > atomic_init(volatile AtomicBase *a, T v) { + CanAtomicAssign volatile *, T> + > atomic_init(AtomicBase volatile *a, T v) { a->p_value = v; } template static inline EnableIf< - !CanAtomicAssign *, T> && - CanAtomicAssign< AtomicBase *, T> - > atomic_init(volatile AtomicBase *a, T v) { - volatile char *to = (volatile char *)(&a->p_value); - volatile char *end = to + sizeof(T); + !CanAtomicAssign volatile *, T> && + CanAtomicAssign *, T> + > atomic_init(AtomicBase volatile *a, T v) { + char volatile *to = (char volatile *)(&a->p_value); + char volatile *end = to + sizeof(T); char *from = (char *)(&v); while (to != end) *to++ =*from++; } @@ -119,44 +119,40 @@ namespace detail { } template - static inline void atomic_store(volatile AtomicBase *a, - T v, MemoryOrder ord) { + static inline void atomic_store(AtomicBase volatile *a, + T v, MemoryOrder ord) { __atomic_store(&a->p_value, &v, to_gcc_order(ord)); } template - static inline void atomic_store(AtomicBase *a, - T v, MemoryOrder ord) { + static inline void atomic_store(AtomicBase *a,T v, MemoryOrder ord) { __atomic_store(&a->p_value, &v, to_gcc_order(ord)); } template - static inline T atomic_load(volatile AtomicBase *a, - MemoryOrder ord) { + static inline T atomic_load(AtomicBase volatile *a, MemoryOrder ord) { T r; __atomic_load(&a->p_value, &r, to_gcc_order(ord)); return r; } template - static inline T atomic_load(AtomicBase *a, - MemoryOrder ord) { + static inline T atomic_load(AtomicBase *a, MemoryOrder ord) { T r; __atomic_load(&a->p_value, &r, to_gcc_order(ord)); return r; } template - static inline T atomic_exchange(volatile AtomicBase *a, - T v, MemoryOrder ord) { + static inline T atomic_exchange(AtomicBase volatile *a, + T v, MemoryOrder ord) { T r; __atomic_exchange(&a->p_value, &v, &r, to_gcc_order(ord)); return r; } template - static inline T atomic_exchange(AtomicBase *a, - T v, MemoryOrder ord) { + static inline T atomic_exchange(AtomicBase *a, T v, MemoryOrder ord) { T r; __atomic_exchange(&a->p_value, &v, &r, to_gcc_order(ord)); return r; @@ -164,7 +160,7 @@ namespace detail { template static inline bool atomic_compare_exchange_strong( - volatile AtomicBase *a, T *expected, T v, + AtomicBase volatile *a, T *expected, T v, MemoryOrder success, MemoryOrder failure ) { return __atomic_compare_exchange(&a->p_value, expected, &v, false, @@ -182,7 +178,7 @@ namespace detail { template static inline bool atomic_compare_exchange_weak( - volatile AtomicBase *a, T *expected, T v, + AtomicBase volatile *a, T *expected, T v, MemoryOrder success, MemoryOrder failure ) { return __atomic_compare_exchange(&a->p_value, expected, &v, true, @@ -208,71 +204,71 @@ namespace detail { template struct SkipAmt {}; template - static inline T atomic_fetch_add(volatile AtomicBase *a, - U d, MemoryOrder ord) { + static inline T atomic_fetch_add(AtomicBase volatile *a, + U d, MemoryOrder ord) { return __atomic_fetch_add(&a->p_value, d * SkipAmt::value, to_gcc_order(ord)); } template static inline T atomic_fetch_add(AtomicBase *a, - U d, MemoryOrder ord) { + U d, MemoryOrder ord) { return __atomic_fetch_add(&a->p_value, d * SkipAmt::value, to_gcc_order(ord)); } template - static inline T atomic_fetch_sub(volatile AtomicBase *a, - U d, MemoryOrder ord) { + static inline T atomic_fetch_sub(AtomicBase volatile *a, + U d, MemoryOrder ord) { return __atomic_fetch_sub(&a->p_value, d * SkipAmt::value, to_gcc_order(ord)); } template static inline T atomic_fetch_sub(AtomicBase *a, - U d, MemoryOrder ord) { + U d, MemoryOrder ord) { return __atomic_fetch_sub(&a->p_value, d * SkipAmt::value, to_gcc_order(ord)); } template - static inline T atomic_fetch_and(volatile AtomicBase *a, - T pattern, MemoryOrder ord) { + static inline T atomic_fetch_and(AtomicBase volatile *a, + T pattern, MemoryOrder ord) { return __atomic_fetch_and(&a->p_value, pattern, to_gcc_order(ord)); } template static inline T atomic_fetch_and(AtomicBase *a, - T pattern, MemoryOrder ord) { + T pattern, MemoryOrder ord) { return __atomic_fetch_and(&a->p_value, pattern, to_gcc_order(ord)); } template - static inline T atomic_fetch_or(volatile AtomicBase *a, - T pattern, MemoryOrder ord) { + static inline T atomic_fetch_or(AtomicBase volatile *a, + T pattern, MemoryOrder ord) { return __atomic_fetch_or(&a->p_value, pattern, to_gcc_order(ord)); } template static inline T atomic_fetch_or(AtomicBase *a, - T pattern, MemoryOrder ord) { + T pattern, MemoryOrder ord) { return __atomic_fetch_or(&a->p_value, pattern, to_gcc_order(ord)); } template - static inline T atomic_fetch_xor(volatile AtomicBase *a, - T pattern, MemoryOrder ord) { + static inline T atomic_fetch_xor(AtomicBase volatile *a, + T pattern, MemoryOrder ord) { return __atomic_fetch_xor(&a->p_value, pattern, to_gcc_order(ord)); } template static inline T atomic_fetch_xor(AtomicBase *a, - T pattern, MemoryOrder ord) { + T pattern, MemoryOrder ord) { return __atomic_fetch_xor(&a->p_value, pattern, to_gcc_order(ord)); } @@ -294,10 +290,10 @@ namespace detail { constexpr Atomic(T v): p_a(v) {} - Atomic(const Atomic &) = delete; + Atomic(Atomic const &) = delete; - Atomic &operator=(const Atomic &) = delete; - Atomic &operator=(const Atomic &) volatile = delete; + Atomic &operator=(Atomic const &) = delete; + Atomic &operator=(Atomic const &) volatile = delete; bool is_lock_free() const volatile { return atomic_is_lock_free(sizeof(T)); @@ -515,17 +511,17 @@ struct Atomic: detail::Atomic { }; template -inline bool atomic_is_lock_free(const volatile Atomic *a) { +inline bool atomic_is_lock_free(Atomic const volatile *a) { return a->is_lock_free(); } template -inline bool atomic_is_lock_free(const Atomic *a) { +inline bool atomic_is_lock_free(Atomic const *a) { return a->is_lock_free(); } template -inline void atomic_init(volatile Atomic *a, T v) { +inline void atomic_init(Atomic volatile *a, T v) { detail::atomic_init(&a->p_a, v); } @@ -535,7 +531,7 @@ inline void atomic_init(Atomic *a, T v) { } template -inline void atomic_store(volatile Atomic *a, T v) { +inline void atomic_store(Atomic volatile *a, T v) { a->store(v); } @@ -545,40 +541,37 @@ inline void atomic_store(Atomic *a, T v) { } template -inline void atomic_store_explicit(volatile Atomic *a, T v, - MemoryOrder ord) { +inline void atomic_store_explicit(Atomic volatile *a, T v, MemoryOrder ord) { a->store(v, ord); } template -inline void atomic_store_explicit(Atomic *a, T v, - MemoryOrder ord) { +inline void atomic_store_explicit(Atomic *a, T v, MemoryOrder ord) { a->store(v, ord); } template -inline T atomic_load(const volatile Atomic *a) { +inline T atomic_load(Atomic const volatile *a) { return a->load(); } template -inline T atomic_load(const Atomic *a) { +inline T atomic_load(Atomic const *a) { return a->load(); } template -inline T atomic_load_explicit(const volatile Atomic *a, - MemoryOrder ord) { +inline T atomic_load_explicit(Atomic const volatile *a, MemoryOrder ord) { return a->load(ord); } template -inline T atomic_load_explicit(const Atomic *a, MemoryOrder ord) { +inline T atomic_load_explicit(Atomic const *a, MemoryOrder ord) { return a->load(ord); } template -inline T atomic_exchange(volatile Atomic *a, T v) { +inline T atomic_exchange(Atomic volatile *a, T v) { return a->exchange(v); } @@ -588,7 +581,7 @@ inline T atomic_exchange(Atomic *a, T v) { } template -inline T atomic_exchange_explicit(volatile Atomic *a, T v, +inline T atomic_exchange_explicit(Atomic volatile *a, T v, MemoryOrder ord) { return a->exchange(v, ord); } @@ -600,7 +593,7 @@ inline T atomic_exchange_explicit(Atomic *a, T v, } template -inline bool atomic_compare_exchange_weak(volatile Atomic *a, +inline bool atomic_compare_exchange_weak(Atomic volatile *a, T *e, T v) { return a->compare_exchange_weak(*e, v); } @@ -611,7 +604,7 @@ inline bool atomic_compare_exchange_weak(Atomic *a, T *e, T v) { } template -inline bool atomic_compare_exchange_strong(volatile Atomic *a, +inline bool atomic_compare_exchange_strong(Atomic volatile *a, T *e, T v) { return a->compare_exchange_strong(*e, v); } @@ -622,7 +615,7 @@ inline bool atomic_compare_exchange_strong(Atomic *a, T *e, T v) { } template -inline bool atomic_compare_exchange_weak_explicit(volatile Atomic *a, +inline bool atomic_compare_exchange_weak_explicit(Atomic volatile *a, T *e, T v, MemoryOrder s, MemoryOrder f) { @@ -638,7 +631,7 @@ inline bool atomic_compare_exchange_weak_explicit(Atomic *a, T *e, } template -inline bool atomic_compare_exchange_strong_explicit(volatile Atomic *a, +inline bool atomic_compare_exchange_strong_explicit(Atomic volatile *a, T *e, T v, MemoryOrder s, MemoryOrder f) { @@ -655,7 +648,7 @@ inline bool atomic_compare_exchange_strong_explicit(Atomic *a, T *e, template inline EnableIf && !IsSame, T> -atomic_fetch_add(volatile Atomic *a, T op) { +atomic_fetch_add(Atomic volatile *a, T op) { return a->fetch_add(op); } @@ -666,7 +659,7 @@ atomic_fetch_add(Atomic *a, T op) { } template -inline T *atomic_fetch_add(volatile Atomic *a, Ptrdiff op) { +inline T *atomic_fetch_add(Atomic volatile *a, Ptrdiff op) { return a->fetch_add(op); } @@ -677,7 +670,7 @@ inline T *atomic_fetch_add(Atomic *a, Ptrdiff op) { template inline EnableIf && !IsSame, T> -atomic_fetch_add_explicit(volatile Atomic *a, T op, +atomic_fetch_add_explicit(Atomic volatile *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } @@ -689,7 +682,7 @@ atomic_fetch_add_explicit(Atomic *a, T op, MemoryOrder ord) { } template -inline T *atomic_fetch_add_explicit(volatile Atomic *a, +inline T *atomic_fetch_add_explicit(Atomic volatile *a, Ptrdiff op, MemoryOrder ord) { return a->fetch_add(op, ord); } @@ -702,7 +695,7 @@ inline T *atomic_fetch_add_explicit(Atomic *a, Ptrdiff op, template inline EnableIf && !IsSame, T> -atomic_fetch_sub(volatile Atomic *a, T op) { +atomic_fetch_sub(Atomic volatile *a, T op) { return a->fetch_sub(op); } @@ -713,7 +706,7 @@ atomic_fetch_sub(Atomic *a, T op) { } template -inline T *atomic_fetch_sub(volatile Atomic *a, Ptrdiff op) { +inline T *atomic_fetch_sub(Atomic volatile *a, Ptrdiff op) { return a->fetch_sub(op); } @@ -724,7 +717,7 @@ inline T *atomic_fetch_sub(Atomic *a, Ptrdiff op) { template inline EnableIf && !IsSame, T> -atomic_fetch_sub_explicit(volatile Atomic *a, T op, +atomic_fetch_sub_explicit(Atomic volatile *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } @@ -736,7 +729,7 @@ atomic_fetch_sub_explicit(Atomic *a, T op, MemoryOrder ord) { } template -inline T *atomic_fetch_sub_explicit(volatile Atomic *a, +inline T *atomic_fetch_sub_explicit(Atomic volatile *a, Ptrdiff op, MemoryOrder ord) { return a->fetch_sub(op, ord); } @@ -749,7 +742,7 @@ inline T *atomic_fetch_sub_explicit(Atomic *a, Ptrdiff op, template inline EnableIf && !IsSame, T> -atomic_fetch_and(volatile Atomic *a, T op) { +atomic_fetch_and(Atomic volatile *a, T op) { return a->fetch_and(op); } @@ -761,7 +754,7 @@ atomic_fetch_and(Atomic *a, T op) { template inline EnableIf && !IsSame, T> -atomic_fetch_and_explicit(volatile Atomic *a, T op, +atomic_fetch_and_explicit(Atomic volatile *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } @@ -774,7 +767,7 @@ atomic_fetch_and_explicit(Atomic *a, T op, MemoryOrder ord) { template inline EnableIf && !IsSame, T> -atomic_fetch_or(volatile Atomic *a, T op) { +atomic_fetch_or(Atomic volatile *a, T op) { return a->fetch_or(op); } @@ -786,7 +779,7 @@ atomic_fetch_or(Atomic *a, T op) { template inline EnableIf && !IsSame, T> -atomic_fetch_or_explicit(volatile Atomic *a, T op, +atomic_fetch_or_explicit(Atomic volatile *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } @@ -799,7 +792,7 @@ atomic_fetch_or_explicit(Atomic *a, T op, MemoryOrder ord) { template inline EnableIf && !IsSame, T> -atomic_fetch_xor(volatile Atomic *a, T op) { +atomic_fetch_xor(Atomic volatile *a, T op) { return a->fetch_xor(op); } @@ -811,7 +804,7 @@ atomic_fetch_xor(Atomic *a, T op) { template inline EnableIf && !IsSame, T> -atomic_fetch_xor_explicit(volatile Atomic *a, T op, +atomic_fetch_xor_explicit(Atomic volatile *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } @@ -829,10 +822,10 @@ struct AtomicFlag { AtomicFlag(bool b): p_a(b) {} - AtomicFlag(const AtomicFlag &) = delete; + AtomicFlag(AtomicFlag const &) = delete; - AtomicFlag &operator=(const AtomicFlag &) = delete; - AtomicFlag &operator=(const AtomicFlag &) volatile = delete; + AtomicFlag &operator=(AtomicFlag const &) = delete; + AtomicFlag &operator=(AtomicFlag const &) volatile = delete; bool test_and_set(MemoryOrder ord = MemoryOrder::seq_cst) volatile { return detail::atomic_exchange(&p_a, true, ord); @@ -851,7 +844,7 @@ struct AtomicFlag { } }; -inline bool atomic_flag_test_and_set(volatile AtomicFlag *a) { +inline bool atomic_flag_test_and_set(AtomicFlag volatile *a) { return a->test_and_set(); } @@ -859,7 +852,7 @@ inline bool atomic_flag_test_and_set(AtomicFlag *a) { return a->test_and_set(); } -inline bool atomic_flag_test_and_set_explicit(volatile AtomicFlag *a, +inline bool atomic_flag_test_and_set_explicit(AtomicFlag volatile *a, MemoryOrder ord) { return a->test_and_set(ord); } @@ -869,7 +862,7 @@ inline bool atomic_flag_test_and_set_explicit(AtomicFlag *a, return a->test_and_set(ord); } -inline void atomic_flag_clear(volatile AtomicFlag *a) { +inline void atomic_flag_clear(AtomicFlag volatile *a) { a->clear(); } @@ -877,7 +870,7 @@ inline void atomic_flag_clear(AtomicFlag *a) { a->clear(); } -inline void atomic_flag_clear_explicit(volatile AtomicFlag *a, +inline void atomic_flag_clear_explicit(AtomicFlag volatile *a, MemoryOrder ord) { a->clear(ord); } diff --git a/ostd/environ.hh b/ostd/environ.hh index a9b8a08..795b719 100644 --- a/ostd/environ.hh +++ b/ostd/environ.hh @@ -17,7 +17,7 @@ namespace environ { inline Maybe get(ConstCharRange name) { char buf[256]; - const char *ret = getenv(to_temp_cstr(name, buf, sizeof(buf)).get()); + char const *ret = getenv(to_temp_cstr(name, buf, sizeof(buf)).get()); if (!ret) return ostd::nothing; return ostd::move(ConstCharRange(ret)); } diff --git a/ostd/event.hh b/ostd/event.hh index d94a4af..41346ba 100644 --- a/ostd/event.hh +++ b/ostd/event.hh @@ -16,8 +16,8 @@ namespace detail { struct SignalBase { SignalBase(C *cl): p_class(cl), p_funcs(nullptr), p_nfuncs(0) {} - SignalBase(const SignalBase &ev): p_class(ev.p_class), - p_nfuncs(ev.p_nfuncs) { + SignalBase(SignalBase const &ev): p_class(ev.p_class), + p_nfuncs(ev.p_nfuncs) { using Func = Function; Func *nbuf = (Func *)new byte[sizeof(Func) * p_nfuncs]; for (Size i = 0; i < p_nfuncs; ++i) @@ -30,7 +30,7 @@ namespace detail { swap(ev); } - SignalBase &operator=(const SignalBase &ev) { + SignalBase &operator=(SignalBase const &ev) { using Func = Function; p_class = ev.p_class; p_nfuncs = ev.p_nfuncs; @@ -118,10 +118,10 @@ private: Base p_base; public: Signal(C *cl): p_base(cl) {} - Signal(const Signal &ev): p_base(ev.p_base) {} + Signal(Signal const &ev): p_base(ev.p_base) {} Signal(Signal &&ev): p_base(move(ev.p_base)) {} - Signal &operator=(const Signal &ev) { + Signal &operator=(Signal const &ev) { p_base = ev.p_base; return *this; } @@ -151,16 +151,16 @@ public: }; template -struct Signal { +struct Signal { private: - using Base = detail::SignalBase; + using Base = detail::SignalBase; Base p_base; public: Signal(C *cl): p_base(cl) {} - Signal(const Signal &ev): p_base(ev.p_base) {} + Signal(Signal const &ev): p_base(ev.p_base) {} Signal(Signal &&ev): p_base(move(ev.p_base)) {} - Signal &operator=(const Signal &ev) { + Signal &operator=(Signal const &ev) { p_base = ev.p_base; return *this; } diff --git a/ostd/filesystem.hh b/ostd/filesystem.hh index 821eeb2..18497c3 100644 --- a/ostd/filesystem.hh +++ b/ostd/filesystem.hh @@ -38,7 +38,7 @@ static constexpr char PathSeparator = '/'; #ifdef OSTD_PLATFORM_WIN32 namespace detail { - inline time_t filetime_to_time_t(const FILETIME &ft) { + inline time_t filetime_to_time_t(FILETIME const &ft) { ULARGE_INTEGER ul; ul.LowPart = ft.dwLowDateTime; ul.HighPart = ft.dwHighDateTime; @@ -54,7 +54,7 @@ inline void path_normalize(CharRange) { struct FileInfo { FileInfo() {} - FileInfo(const FileInfo &i): + FileInfo(FileInfo const &i): p_slash(i.p_slash), p_dot(i.p_dot), p_type(i.p_type), p_path(i.p_path), p_atime(i.p_atime), p_mtime(i.p_mtime), p_ctime(i.p_ctime) {} @@ -72,7 +72,7 @@ struct FileInfo { init_from_str(path); } - FileInfo &operator=(const FileInfo &i) { + FileInfo &operator=(FileInfo const &i) { p_slash = i.p_slash; p_dot = i.p_dot; p_type = i.p_type; @@ -215,7 +215,7 @@ struct DirectoryStream { friend struct DirectoryRange; DirectoryStream(): p_d(), p_de(), p_dev(), p_path() {} - DirectoryStream(const DirectoryStream &) = delete; + DirectoryStream(DirectoryStream const &) = delete; DirectoryStream(DirectoryStream &&s): p_d(s.p_d), p_de(s.p_de), p_dev(s.p_dev), p_path(move(s.p_path)) { @@ -230,7 +230,7 @@ struct DirectoryStream { ~DirectoryStream() { close(); } - DirectoryStream &operator=(const DirectoryStream &) = delete; + DirectoryStream &operator=(DirectoryStream const &) = delete; DirectoryStream &operator=(DirectoryStream &&s) { close(); swap(s); @@ -325,7 +325,7 @@ private: return FileInfo(); String ap = p_path; ap += PathSeparator; - ap += (const char *)p_de->d_name; + ap += (char const *)p_de->d_name; return FileInfo(ap); } @@ -341,7 +341,7 @@ struct DirectoryStream { friend struct DirectoryRange; DirectoryStream(): p_handle(INVALID_HANDLE_VALUE), p_data(), p_path() {} - DirectoryStream(const DirectoryStream &) = delete; + DirectoryStream(DirectoryStream const &) = delete; DirectoryStream(DirectoryStream &&s): p_handle(s.p_handle), p_data(s.p_data), p_path(move(s.p_path)) { @@ -355,7 +355,7 @@ struct DirectoryStream { ~DirectoryStream() { close(); } - DirectoryStream &operator=(const DirectoryStream &) = delete; + DirectoryStream &operator=(DirectoryStream const &) = delete; DirectoryStream &operator=(DirectoryStream &&s) { close(); swap(s); @@ -463,7 +463,7 @@ private: return FileInfo(); String ap = p_path; ap += PathSeparator; - ap += (const char *)p_data.cFileName; + ap += (char const *)p_data.cFileName; return FileInfo(ap); } @@ -478,9 +478,9 @@ struct DirectoryRange: InputRange< > { DirectoryRange() = delete; DirectoryRange(DirectoryStream &s): p_stream(&s) {} - DirectoryRange(const DirectoryRange &r): p_stream(r.p_stream) {} + DirectoryRange(DirectoryRange const &r): p_stream(r.p_stream) {} - DirectoryRange &operator=(const DirectoryRange &r) { + DirectoryRange &operator=(DirectoryRange const &r) { p_stream = r.p_stream; return *this; } @@ -497,7 +497,7 @@ struct DirectoryRange: InputRange< return p_stream->front(); } - bool equals_front(const DirectoryRange &s) const { + bool equals_front(DirectoryRange const &s) const { return p_stream == s.p_stream; } @@ -512,7 +512,7 @@ inline DirectoryRange DirectoryStream::iter() { namespace detail { template struct PathJoin { template - static void join(String &s, const T &a, const A &...b) { + static void join(String &s, T const &a, A const &...b) { s += a; s += PathSeparator; PathJoin::join(s, b...); @@ -521,14 +521,14 @@ namespace detail { template<> struct PathJoin<1> { template - static void join(String &s, const T &a) { + static void join(String &s, T const &a) { s += a; } }; } template -inline FileInfo path_join(const A &...args) { +inline FileInfo path_join(A const &...args) { String path; detail::PathJoin::join(path, args...); path_normalize(path.iter()); diff --git a/ostd/format.hh b/ostd/format.hh index 814bf0a..0e802ce 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -62,7 +62,7 @@ namespace detail { * 7 .. string * 8 .. custom object */ - static constexpr const byte fmt_specs[] = { + static constexpr byte const fmt_specs[] = { /* uppercase spec set */ 1, 3, 8, 8, /* A B C D */ 1, 1, 1, 8, /* E F G H */ @@ -88,11 +88,11 @@ namespace detail { 0, 0, 0, 0, 0 }; - static constexpr const int fmt_bases[] = { + static constexpr int const fmt_bases[] = { 0, 0, 0, 2, 8, 10, 16, 0 }; - static constexpr const char fmt_digits[2][16] = { + static constexpr char fmt_digits[2][16] = { { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' @@ -103,14 +103,14 @@ namespace detail { } }; - static constexpr const char *fmt_intpfx[2][4] = { + static constexpr char const *fmt_intpfx[2][4] = { { "0B", "0", "", "0X" }, { "0b", "0", "", "0x" } }; /* retrieve width/precision */ template - bool convert_arg_param(const T &val, int ¶m, EnableIf< + bool convert_arg_param(T const &val, int ¶m, EnableIf< IsIntegral, bool > = true) { param = int(val); @@ -118,7 +118,7 @@ namespace detail { } template - bool convert_arg_param(const T &, int &, EnableIf< + bool convert_arg_param(T const &, int &, EnableIf< !IsIntegral, bool > = true) { assert(false && "invalid argument for width/precision"); @@ -126,7 +126,7 @@ namespace detail { } template - bool get_arg_param(Size idx, int ¶m, const T &val) { + bool get_arg_param(Size idx, int ¶m, T const &val) { if (idx) { assert(false && "not enough format args"); return false; @@ -134,8 +134,7 @@ namespace detail { return convert_arg_param(val, param); } template - bool get_arg_param(Size idx, int ¶m, const T &val, - const A &...args) { + bool get_arg_param(Size idx, int ¶m, T const &val, A const &...args) { if (idx) return get_arg_param(idx - 1, param, args...); return convert_arg_param(val, param); } @@ -204,12 +203,12 @@ struct FormatSpec { bool arg_precision() const { return p_arg_precision; } template - bool set_width(Size idx, const A &...args) { + bool set_width(Size idx, A const &...args) { return detail::get_arg_param(idx, p_width, args...); } template - bool set_precision(Size idx, const A &...args) { + bool set_precision(Size idx, A const &...args) { return detail::get_arg_param(idx, p_precision, args...); } @@ -399,16 +398,16 @@ protected: /* for custom container formatting */ template() - .to_format(declval(), declval())), bool + IsSame() + .to_format(declval(), declval())), bool > ->> inline bool to_format(const T &v, R &writer, const FormatSpec &fs) { +>> inline bool to_format(T const &v, R &writer, FormatSpec const &fs) { return v.to_format(writer, fs); } namespace detail { template - inline Ptrdiff write_u(R &writer, const FormatSpec *fl, bool neg, T val) { + inline Ptrdiff write_u(R &writer, FormatSpec const *fl, bool neg, T val) { char buf[20]; Ptrdiff r = 0; Size n = 0; @@ -434,7 +433,7 @@ namespace detail { bool sign = neg + lsgn + lsp; r += sign; - const char *pfx = nullptr; + char const *pfx = nullptr; int pfxlen = 0; if (flags & FMT_FLAG_HASH && spec != 'd') { pfx = detail::fmt_intpfx[spec >= 'a'][specn - 3]; @@ -458,7 +457,7 @@ namespace detail { template static Ptrdiff format_impl(R &writer, Size &fmtn, bool escape, - ConstCharRange fmt, const A &...args); + ConstCharRange fmt, A const &...args); template> static True test_fmt_range(int); @@ -472,8 +471,8 @@ namespace detail { struct FmtTupleUnpacker { template static inline Ptrdiff unpack(R &writer, Size &fmtn, bool esc, - ConstCharRange fmt, const T &item, - const A &...args) { + ConstCharRange fmt, T const &item, + A const &...args) { return FmtTupleUnpacker::unpack(writer, fmtn, esc, fmt, item, get(item), args...); } @@ -483,15 +482,15 @@ namespace detail { struct FmtTupleUnpacker<0> { template static inline Ptrdiff unpack(R &writer, Size &fmtn, bool esc, - ConstCharRange fmt, const T &, - const A &...args) { + ConstCharRange fmt, T const &, + A const &...args) { return format_impl(writer, fmtn, esc, fmt, args...); } }; template inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc, bool, - ConstCharRange fmt, const T &item, + ConstCharRange fmt, T const &item, EnableIf, bool> = true) { return format_impl(writer, fmtn, esc, fmt, item); @@ -500,7 +499,7 @@ namespace detail { template inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc, bool expandval, ConstCharRange fmt, - const T &item, + T const &item, EnableIf, bool> = true) { if (expandval) { @@ -511,10 +510,10 @@ namespace detail { } template - inline Ptrdiff write_range(R &writer, const FormatSpec *fl, + inline Ptrdiff write_range(R &writer, FormatSpec const *fl, bool escape, bool expandval, ConstCharRange sep, - const T &val, + T const &val, EnableIf, bool> = true) { auto range = ostd::iter(val); @@ -542,8 +541,8 @@ namespace detail { } template - inline Ptrdiff write_range(R &, const FormatSpec *, bool, bool, - ConstCharRange, const T &, + inline Ptrdiff write_range(R &, FormatSpec const *, bool, bool, + ConstCharRange, T const &, EnableIf, bool> = true) { assert(false && "invalid value for ranged format"); @@ -558,7 +557,7 @@ namespace detail { constexpr bool FmtTostrTest = decltype(test_fmt_tostr(0))::value; /* non-printable escapes up to 0x20 (space) */ - static constexpr const char *fmt_escapes[] = { + static constexpr char const *fmt_escapes[] = { "\\0" , "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a" , "\\b" , "\\t" , "\\n" , "\\v" , "\\f" , "\\r" , "\\x0E", "\\x0F", "\\x10", "\\x11", @@ -570,7 +569,7 @@ namespace detail { nullptr, "\\\'" }; - inline const char *escape_fmt_char(char v, char quote) { + inline char const *escape_fmt_char(char v, char quote) { if ((v >= 0 && v < 0x20) || (v == quote)) { return fmt_escapes[Size(v)]; } else if (v == 0x7F) { @@ -583,7 +582,7 @@ namespace detail { String ret; ret.push('"'); while (!val.empty()) { - const char *esc = escape_fmt_char(val.front(), '"'); + char const *esc = escape_fmt_char(val.front(), '"'); if (esc) ret.append(esc); else @@ -595,9 +594,9 @@ namespace detail { } template - static True test_tofmt(decltype(to_format(declval(), + static True test_tofmt(decltype(to_format(declval(), declval(), - declval())) *); + declval())) *); template static False test_tofmt(...); @@ -626,8 +625,8 @@ namespace detail { /* any string value */ template - Ptrdiff write(R &writer, bool escape, const T &val, EnableIf< - IsConstructible, bool + Ptrdiff write(R &writer, bool escape, T const &val, EnableIf< + IsConstructible, bool > = true) { if (this->spec() != 's') { assert(false && "cannot print strings with the given spec"); @@ -644,14 +643,14 @@ namespace detail { return -1; } if (escape) { - const char *esc = escape_fmt_char(val, '\''); + char const *esc = escape_fmt_char(val, '\''); if (esc) { char buf[6]; buf[0] = '\''; Size elen = strlen(esc); memcpy(buf + 1, esc, elen); buf[elen + 1] = '\''; - return write(writer, false, (const char *)buf, elen + 2); + return write(writer, false, (char const *)buf, elen + 2); } } Ptrdiff r = 1 + escape * 2; @@ -738,9 +737,9 @@ namespace detail { /* generic value */ template - Ptrdiff write(R &writer, bool, const T &val, EnableIf< + Ptrdiff write(R &writer, bool, T const &val, EnableIf< !IsArithmetic && - !IsConstructible && + !IsConstructible && FmtTostrTest && !FmtTofmtTest>, bool > = true) { if (this->spec() != 's') { @@ -752,7 +751,7 @@ namespace detail { /* custom format case */ template - Ptrdiff write(R &writer, bool, const T &val, + Ptrdiff write(R &writer, bool, T const &val, EnableIf>, bool > = true) { TostrRange sink(writer); @@ -762,9 +761,9 @@ namespace detail { /* generic failure case */ template - Ptrdiff write(R &, bool, const T &, EnableIf< + Ptrdiff write(R &, bool, T const &, EnableIf< !IsArithmetic && - !IsConstructible && + !IsConstructible && !FmtTostrTest && !FmtTofmtTest>, bool > = true) { assert(false && "value cannot be formatted"); @@ -773,7 +772,7 @@ namespace detail { /* actual writer */ template - Ptrdiff write_arg(R &writer, Size idx, const T &val) { + Ptrdiff write_arg(R &writer, Size idx, T const &val) { if (idx) { assert(false && "not enough format args"); return -1; @@ -782,8 +781,8 @@ namespace detail { } template - Ptrdiff write_arg(R &writer, Size idx, const T &val, - const A &...args) { + Ptrdiff write_arg(R &writer, Size idx, T const &val, + A const &...args) { if (idx) return write_arg(writer, idx - 1, args...); return write(writer, this->p_nested_escape, val); } @@ -791,7 +790,7 @@ namespace detail { /* range writer */ template Ptrdiff write_range(R &writer, Size idx, bool expandval, - ConstCharRange sep, const T &val) { + ConstCharRange sep, T const &val) { if (idx) { assert(false && "not enough format args"); return -1; @@ -802,8 +801,8 @@ namespace detail { template Ptrdiff write_range(R &writer, Size idx, bool expandval, - ConstCharRange sep, const T &val, - const A &...args) { + ConstCharRange sep, T const &val, + A const &...args) { if (idx) { return write_range(writer, idx - 1, expandval, sep, args...); } @@ -814,7 +813,7 @@ namespace detail { template inline Ptrdiff format_impl(R &writer, Size &fmtn, bool escape, - ConstCharRange fmt, const A &...args) { + ConstCharRange fmt, A const &...args) { Size argidx = 1, retn = 0, twr = 0; Ptrdiff written = 0; detail::WriteSpec spec(fmt, escape); @@ -885,12 +884,12 @@ namespace detail { template inline Ptrdiff format(R &&writer, Size &fmtn, ConstCharRange fmt, - const A &...args) { + A const &...args) { return detail::format_impl(writer, fmtn, false, fmt, args...); } template -Ptrdiff format(R &&writer, ConstCharRange fmt, const A &...args) { +Ptrdiff format(R &&writer, ConstCharRange fmt, A const &...args) { Size fmtn = 0; return format(writer, fmtn, fmt, args...); } diff --git a/ostd/functional.hh b/ostd/functional.hh index cf134f6..5c503e4 100644 --- a/ostd/functional.hh +++ b/ostd/functional.hh @@ -20,7 +20,7 @@ namespace ostd { #define OSTD_DEFINE_BINARY_OP(name, op, RT) \ template struct name { \ - RT operator()(const T &x, const T &y) const { \ + RT operator()(T const &x, T const &y) const { \ return x op y; \ } \ using FirstArgument = T; \ @@ -71,7 +71,7 @@ namespace detail { template struct EqualWithCstr { using FirstArgument = T; using SecondArgument = T; - bool operator()(const T &x, const T &y) const { + bool operator()(T const &x, T const &y) const { return x == y; } }; @@ -79,13 +79,13 @@ template struct EqualWithCstr { template struct EqualWithCstr: detail::CharEqual {}; template struct LogicalNot { - bool operator()(const T &x) const { return !x; } + bool operator()(T const &x) const { return !x; } using Argument = T; using Result = bool; }; template struct Negate { - bool operator()(const T &x) const { return -x; } + bool operator()(T const &x) const { return -x; } using Argument = T; using Result = T; }; @@ -95,10 +95,10 @@ template struct BinaryNegate { using SecondArgument = typename T::SecondArgument; using Result = bool; - explicit BinaryNegate(const T &f): p_fn(f) {} + explicit BinaryNegate(T const &f): p_fn(f) {} - bool operator()(const FirstArgument &x, - const SecondArgument &y) { + bool operator()(FirstArgument const &x, + SecondArgument const &y) { return !p_fn(x, y); } private: @@ -109,19 +109,19 @@ template struct UnaryNegate { using Argument = typename T::Argument; using Result = bool; - explicit UnaryNegate(const T &f): p_fn(f) {} - bool operator()(const Argument &x) { + explicit UnaryNegate(T const &f): p_fn(f) {} + bool operator()(Argument const &x) { return !p_fn(x); } private: T p_fn; }; -template UnaryNegate not1(const T &fn) { +template UnaryNegate not1(T const &fn) { return UnaryNegate(fn); } -template BinaryNegate not2(const T &fn) { +template BinaryNegate not2(T const &fn) { return BinaryNegate(fn); } @@ -210,7 +210,7 @@ template struct ToHash { using Argument = T; using Result = Size; - Size operator()(const T &v) const { + Size operator()(T const &v) const { return v.to_hash(); } }; @@ -262,11 +262,11 @@ namespace detail { static constexpr Size offset = Size(14695981039346656037u); }; - inline Size mem_hash(const void *p, Size l) { + inline Size mem_hash(void const *p, Size l) { using Consts = FnvConstants; - const byte *d = (const byte *)p; + byte const *d = (byte const *)p; Size h = Consts::offset; - for (const byte *it = d, *end = d + l; it != end; ++it) { + for (byte const *it = d, *end = d + l; it != end; ++it) { h ^= *it; h *= Consts::prime; } @@ -306,7 +306,7 @@ namespace detail { Size operator()(T v) const { union { T v; struct { Size h1, h2; }; } u; u.v = v; - return mem_hash((const void *)&u, sizeof(u)); + return mem_hash((void const *)&u, sizeof(u)); } }; @@ -317,7 +317,7 @@ namespace detail { Size operator()(T v) const { union { T v; struct { Size h1, h2, h3; }; } u; u.v = v; - return mem_hash((const void *)&u, sizeof(u)); + return mem_hash((void const *)&u, sizeof(u)); } }; @@ -328,7 +328,7 @@ namespace detail { Size operator()(T v) const { union { T v; struct { Size h1, h2, h3, h4; }; } u; u.v = v; - return mem_hash((const void *)&u, sizeof(u)); + return mem_hash((void const *)&u, sizeof(u)); } }; } /* namespace detail */ @@ -379,7 +379,7 @@ namespace detail { Size operator()(T *v) const { union { T *v; Size h; } u; u.v = v; - return detail::mem_hash((const void *)&u, sizeof(u)); + return detail::mem_hash((void const *)&u, sizeof(u)); } }; @@ -395,7 +395,7 @@ namespace detail { template struct ToHash: detail::ToHashPtr {}; template -typename ToHash::Result to_hash(const T &v) { +typename ToHash::Result to_hash(T const &v) { return ToHash()(v); } @@ -406,10 +406,10 @@ struct ReferenceWrapper { using Type = T; ReferenceWrapper(T &v): p_ptr(address_of(v)) {} - ReferenceWrapper(const ReferenceWrapper &) = default; + ReferenceWrapper(ReferenceWrapper const &) = default; ReferenceWrapper(T &&) = delete; - ReferenceWrapper &operator=(const ReferenceWrapper &) = default; + ReferenceWrapper &operator=(ReferenceWrapper const &) = default; operator T &() const { return *p_ptr; } T &get() const { return *p_ptr; } @@ -426,17 +426,17 @@ template ReferenceWrapper ref(ReferenceWrapper v) { return ReferenceWrapper(v); } -template void ref(const T &&) = delete; +template void ref(T const &&) = delete; template -ReferenceWrapper cref(const T &v) { +ReferenceWrapper cref(T const &v) { return ReferenceWrapper(v); } template -ReferenceWrapper cref(ReferenceWrapper v) { +ReferenceWrapper cref(ReferenceWrapper v) { return ReferenceWrapper(v); } -template void cref(const T &&) = delete; +template void cref(T const &&) = delete; /* mem_fn */ @@ -456,12 +456,12 @@ namespace detail { template struct MemTypes { using Result = R; - using Argument = const T; + using Argument = T const; }; template struct MemTypes { using Result = R; - using FirstArgument = const T; + using FirstArgument = T const; using SecondArgument = A; }; @@ -476,7 +476,7 @@ namespace detail { return ((obj).*(p_ptr))(forward(args)...); } template - auto operator()(const T &obj, A &&...args) -> + auto operator()(T const &obj, A &&...args) -> decltype(((obj).*(p_ptr))(forward(args)...)) const { return ((obj).*(p_ptr))(forward(args)...); } @@ -486,7 +486,7 @@ namespace detail { return ((obj)->*(p_ptr))(forward(args)...); } template - auto operator()(const T *obj, A &&...args) -> + auto operator()(T const *obj, A &&...args) -> decltype(((obj)->*(p_ptr))(forward(args)...)) const { return ((obj)->*(p_ptr))(forward(args)...); } @@ -518,22 +518,22 @@ namespace detail { struct FmStorage { FunctorData data; - const FunctionManager *manager; + FunctionManager const *manager; template A &get_alloc() { union { - const FunctionManager **m; + FunctionManager const **m; A *alloc; } u; u.m = &manager; return *u.alloc; } template - const A &get_alloc() const { + A const &get_alloc() const { union { - const FunctionManager * const *m; - const A *alloc; + FunctionManager const * const *m; + A const *alloc; } u; u.m = &manager; return *u.alloc; @@ -543,7 +543,7 @@ namespace detail { template struct FunctorDataManager { template - static R call(const FunctorData &s, Args ...args) { + static R call(FunctorData const &s, Args ...args) { return ((T &)s)(forward(args)...); } @@ -559,9 +559,9 @@ namespace detail { get_ref(s).~T(); } - static T &get_ref(const FmStorage &s) { + static T &get_ref(FmStorage const &s) { union { - const FunctorData *data; + FunctorData const *data; T *ret; } u; u.data = &s.data; @@ -572,7 +572,7 @@ namespace detail { template struct FunctorDataManager>> { template - static R call(const FunctorData &s, Args ...args) { + static R call(FunctorData const &s, Args ...args) { return (*(AllocatorPointer &)s)(forward(args)...); } @@ -596,7 +596,7 @@ namespace detail { ptr = nullptr; } - static T &get_ref(const FmStorage &s) { + static T &get_ref(FmStorage const &s) { return *get_ptr_ref(s); } @@ -604,13 +604,13 @@ namespace detail { return (AllocatorPointer &)(s.data); } - static AllocatorPointer &get_ptr_ref(const FmStorage &s) { + static AllocatorPointer &get_ptr_ref(FmStorage const &s) { return (AllocatorPointer &)(s.data); } }; template - static const FunctionManager &get_default_fm(); + static FunctionManager const &get_default_fm(); template static void create_fm(FmStorage &s, A &&a) { @@ -632,14 +632,14 @@ namespace detail { void (* const call_move_and_destroyf)(FmStorage &lhs, FmStorage &&rhs); void (* const call_copyf)(FmStorage &lhs, - const FmStorage &rhs); + FmStorage const &rhs); void (* const call_copyf_fo)(FmStorage &lhs, - const FmStorage &rhs); + FmStorage const &rhs); void (* const call_destroyf)(FmStorage &s); template static void call_move_and_destroy(FmStorage &lhs, - FmStorage &&rhs) { + FmStorage &&rhs) { using Spec = FunctorDataManager; Spec::move_f(lhs, move(rhs)); Spec::destroy_f(rhs.get_alloc(), rhs); @@ -649,7 +649,7 @@ namespace detail { template static void call_copy(FmStorage &lhs, - const FmStorage &rhs) { + FmStorage const &rhs) { using Spec = FunctorDataManager; create_fm(lhs, A(rhs.get_alloc())); Spec::store_f(lhs, Spec::get_ref(rhs)); @@ -657,7 +657,7 @@ namespace detail { template static void call_copy_fo(FmStorage &lhs, - const FmStorage &rhs) { + FmStorage const &rhs) { using Spec = FunctorDataManager; Spec::store_f(lhs, Spec::get_ref(rhs)); } @@ -671,8 +671,8 @@ namespace detail { }; template - inline static const FunctionManager &get_default_fm() { - static const FunctionManager def_manager + inline static FunctionManager const &get_default_fm() { + static FunctionManager const def_manager = FunctionManager::create_default_manager(); return def_manager; } @@ -744,7 +744,7 @@ struct Function: detail::FunctionBase { swap(f); } - Function(const Function &f): p_call(f.p_call) { + Function(Function const &f): p_call(f.p_call) { f.p_stor.manager->call_copyf(p_stor, f.p_stor); } @@ -760,21 +760,21 @@ struct Function: detail::FunctionBase { } template - Function(AllocatorArg, const A &) { init_empty(); } + Function(AllocatorArg, A const &) { init_empty(); } template - Function(AllocatorArg, const A &, Nullptr) { init_empty(); } + Function(AllocatorArg, A const &, Nullptr) { init_empty(); } template - Function(AllocatorArg, const A &, Function &&f) { + Function(AllocatorArg, A const &, Function &&f) { init_empty(); swap(f); } template - Function(AllocatorArg, const A &a, const Function &f): + Function(AllocatorArg, A const &a, Function const &f): p_call(f.p_call) { - const detail::FunctionManager *mfa + detail::FunctionManager const *mfa = &detail::get_default_fm, A>(); if (f.p_stor.manager == mfa) { detail::create_fm, A>(p_stor, A(a)); @@ -783,7 +783,7 @@ struct Function: detail::FunctionBase { } using AA = AllocatorRebind; - const detail::FunctionManager *mff + detail::FunctionManager const *mff = &detail::get_default_fm(); if (f.p_stor.manager == mff) { detail::create_fm(p_stor, AA(a)); @@ -796,7 +796,7 @@ struct Function: detail::FunctionBase { template - >> Function(AllocatorArg, const A &a, T f) { + >> Function(AllocatorArg, A const &a, T f) { if (func_is_null(f)) { init_empty(); return; @@ -814,7 +814,7 @@ struct Function: detail::FunctionBase { return *this; } - Function &operator=(const Function &f) { + Function &operator=(Function const &f) { p_stor.manager->call_destroyf(p_stor); swap(Function(f)); return *this; @@ -825,7 +825,7 @@ struct Function: detail::FunctionBase { } template - void assign(F &&f, const A &a) { + void assign(F &&f, A const &a) { Function(allocator_arg, a, forward(f)).swap(*this); } @@ -841,7 +841,7 @@ struct Function: detail::FunctionBase { private: detail::FmStorage p_stor; - R (*p_call)(const detail::FunctorData &, Args...); + R (*p_call)(detail::FunctorData const &, Args...); template void initialize(T &&f, A &&a) { @@ -860,7 +860,7 @@ private: } template - static bool func_is_null(const T &) { return false; } + static bool func_is_null(T const &) { return false; } static bool func_is_null(R (* const &fptr)(Args...)) { return fptr == nullptr; @@ -878,16 +878,16 @@ private: }; template -bool operator==(Nullptr, const Function &rhs) { return !rhs; } +bool operator==(Nullptr, Function const &rhs) { return !rhs; } template -bool operator==(const Function &lhs, Nullptr) { return !lhs; } +bool operator==(Function const &lhs, Nullptr) { return !lhs; } template -bool operator!=(Nullptr, const Function &rhs) { return rhs; } +bool operator!=(Nullptr, Function const &rhs) { return rhs; } template -bool operator!=(const Function &lhs, Nullptr) { return lhs; } +bool operator!=(Function const &lhs, Nullptr) { return lhs; } namespace detail { template diff --git a/ostd/initializer_list.hh b/ostd/initializer_list.hh index acc7404..b6ec393 100644 --- a/ostd/initializer_list.hh +++ b/ostd/initializer_list.hh @@ -16,17 +16,17 @@ namespace std { template class initializer_list { - const T *p_buf; + T const *p_buf; ostd::Size p_len; - constexpr initializer_list(const T *v, ostd::Size n): p_buf(v), p_len(n) {} + constexpr initializer_list(T const *v, ostd::Size n): p_buf(v), p_len(n) {} public: constexpr initializer_list(): p_buf(nullptr), p_len(0) {} constexpr ostd::Size size() const { return p_len; } - constexpr const T *begin() const { return p_buf; } - constexpr const T *end() const { return p_buf + p_len; } + constexpr T const *begin() const { return p_buf; } + constexpr T const *end() const { return p_buf + p_len; } }; } @@ -39,13 +39,13 @@ namespace ostd { template using InitializerList = std::initializer_list; template -PointerRange iter(std::initializer_list init) { - return PointerRange(init.begin(), init.end()); +PointerRange iter(std::initializer_list init) { + return PointerRange(init.begin(), init.end()); } template -PointerRange citer(std::initializer_list init) { - return PointerRange(init.begin(), init.end()); +PointerRange citer(std::initializer_list init) { + return PointerRange(init.begin(), init.end()); } } diff --git a/ostd/io.hh b/ostd/io.hh index 1aac512..be32039 100644 --- a/ostd/io.hh +++ b/ostd/io.hh @@ -20,14 +20,14 @@ enum class StreamMode { }; namespace detail { - static const char *filemodes[] = { + static char const *filemodes[] = { "rb", "wb", "ab", "rb+", "wb+", "ab+" }; } struct FileStream: Stream { FileStream(): p_f(), p_owned(false) {} - FileStream(const FileStream &) = delete; + FileStream(FileStream const &) = delete; FileStream(FileStream &&s): p_f(s.p_f), p_owned(s.p_owned) { s.p_f = nullptr; s.p_owned = false; @@ -41,7 +41,7 @@ struct FileStream: Stream { ~FileStream() { close(); } - FileStream &operator=(const FileStream &) = delete; + FileStream &operator=(FileStream const &) = delete; FileStream &operator=(FileStream &&s) { close(); swap(s); @@ -100,7 +100,7 @@ struct FileStream: Stream { return fread(buf, 1, count, p_f); } - Size write_bytes(const void *buf, Size count) { + Size write_bytes(void const *buf, Size count) { return fwrite(buf, 1, count, p_f); } @@ -138,39 +138,39 @@ namespace detail { } template - inline void write_impl(const T &v, EnableIf< - !IsConstructible, IoNat + inline void write_impl(T const &v, EnableIf< + !IsConstructible, IoNat > = IoNat()) { write(ostd::to_string(v)); } } template -inline void write(const T &v) { +inline void write(T const &v) { detail::write_impl(v); } template -inline void write(const T &v, const A &...args) { +inline void write(T const &v, A const &...args) { write(v); write(args...); } template -inline void writeln(const T &v) { +inline void writeln(T const &v) { write(v); putc('\n', ::stdout); } template -inline void writeln(const T &v, const A &...args) { +inline void writeln(T const &v, A const &...args) { write(v); write(args...); putc('\n', ::stdout); } template -inline void writef(ConstCharRange fmt, const A &...args) { +inline void writef(ConstCharRange fmt, A const &...args) { char buf[512]; Ptrdiff need = format(detail::FormatOutRange(buf), fmt, args...); @@ -186,7 +186,7 @@ inline void writef(ConstCharRange fmt, const A &...args) { } template -inline void writefln(ConstCharRange fmt, const A &...args) { +inline void writefln(ConstCharRange fmt, A const &...args) { writef(fmt, args...); putc('\n', ::stdout); } diff --git a/ostd/keyset.hh b/ostd/keyset.hh index 4bf8f2a..f7e5051 100644 --- a/ostd/keyset.hh +++ b/ostd/keyset.hh @@ -19,22 +19,22 @@ namespace ostd { namespace detail { template - using KeysetKeyRet = decltype(declval().get_key()); + using KeysetKeyRet = decltype(declval().get_key()); template - using KeysetKey = const Decay>; + using KeysetKey = Decay> const; template struct KeysetBase { using Key = KeysetKey; using RetKey = Conditional>, Key &, Key>; - static inline RetKey get_key(const T &e) { + static inline RetKey get_key(T const &e) { return e.get_key(); } static inline T &get_data(T &e) { return e; } template - static inline void set_key(T &, const U &, A &) {} + static inline void set_key(T &, U const &, A &) {} static inline void swap_elem(T &a, T &b) { swap_adl(a, b); } }; @@ -60,35 +60,35 @@ namespace detail { using Pointer = AllocatorPointer; using ConstPointer = AllocatorConstPointer; using Range = HashRange; - using ConstRange = HashRange; + using ConstRange = HashRange; using LocalRange = BucketRange; - using ConstLocalRange = BucketRange; + using ConstLocalRange = BucketRange; using Allocator = A; - explicit KeysetImpl(Size size, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + explicit KeysetImpl(Size size, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size, hf, eqf, alloc) {} KeysetImpl(): KeysetImpl(0) {} - explicit KeysetImpl(const A &alloc): KeysetImpl(0, H(), C(), alloc) {} + explicit KeysetImpl(A const &alloc): KeysetImpl(0, H(), C(), alloc) {} - KeysetImpl(Size size, const A &alloc): + KeysetImpl(Size size, A const &alloc): KeysetImpl(size, H(), C(), alloc) {} - KeysetImpl(Size size, const H &hf, const A &alloc): + KeysetImpl(Size size, H const &hf, A const &alloc): KeysetImpl(size, hf, C(), alloc) {} - KeysetImpl(const KeysetImpl &m): Base(m, + KeysetImpl(KeysetImpl const &m): Base(m, allocator_container_copy(m.get_alloc())) {} - KeysetImpl(const KeysetImpl &m, const A &alloc): Base(m, alloc) {} + KeysetImpl(KeysetImpl const &m, A const &alloc): Base(m, alloc) {} KeysetImpl(KeysetImpl &&m): Base(move(m)) {} - KeysetImpl(KeysetImpl &&m, const A &alloc): Base(move(m), alloc) {} + KeysetImpl(KeysetImpl &&m, A const &alloc): Base(move(m), alloc) {} template && IsConvertible, Value> - >> KeysetImpl(R range, Size size = 0, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + >> KeysetImpl(R range, Size size = 0, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size ? size : detail::estimate_hrsize(range), hf, eqf, alloc) { for (; !range.empty(); range.pop_front()) @@ -97,25 +97,25 @@ namespace detail { } template - KeysetImpl(R range, Size size, const A &alloc) + KeysetImpl(R range, Size size, A const &alloc) : KeysetImpl(range, size, H(), C(), alloc) {} template - KeysetImpl(R range, Size size, const H &hf, const A &alloc) + KeysetImpl(R range, Size size, H const &hf, A const &alloc) : KeysetImpl(range, size, hf, C(), alloc) {} KeysetImpl(InitializerList init, Size size = 0, - const H &hf = H(), const C &eqf = C(), const A &alloc = A() + H const &hf = H(), C const &eqf = C(), A const &alloc = A() ): KeysetImpl(iter(init), size, hf, eqf, alloc) {} - KeysetImpl(InitializerList init, Size size, const A &alloc) + KeysetImpl(InitializerList init, Size size, A const &alloc) : KeysetImpl(iter(init), size, H(), C(), alloc) {} - KeysetImpl(InitializerList init, Size size, const H &hf, - const A &alloc + KeysetImpl(InitializerList init, Size size, H const &hf, + A const &alloc ): KeysetImpl(iter(init), size, hf, C(), alloc) {} - KeysetImpl &operator=(const KeysetImpl &m) { + KeysetImpl &operator=(KeysetImpl const &m) { Base::operator=(m); return *this; } @@ -137,16 +137,16 @@ namespace detail { return *this; } - T *at(const Key &key) { + T *at(Key const &key) { static_assert(!IsMultihash, "at() only allowed on regular keysets"); return Base::access(key); } - const T *at(const Key &key) const { + T const *at(Key const &key) const { static_assert(!IsMultihash, "at() only allowed on regular keysets"); return Base::access(key); } - T &operator[](const Key &key) { + T &operator[](Key const &key) { static_assert(!IsMultihash, "operator[] only allowed on regular keysets"); return Base::access_or_insert(key); } diff --git a/ostd/map.hh b/ostd/map.hh index bba29c7..0aee52e 100644 --- a/ostd/map.hh +++ b/ostd/map.hh @@ -18,9 +18,9 @@ namespace ostd { namespace detail { template struct MapBase { - using Element = Pair; + using Element = Pair; - static inline const K &get_key(Element &e) { + static inline K const &get_key(Element &e) { return e.first; } static inline T &get_data(Element &e) { @@ -41,11 +41,11 @@ namespace detail { typename K, typename T, typename H, typename C, typename A, bool IsMultihash > struct MapImpl: detail::Hashtable, - Pair, K, T, H, C, A, IsMultihash + Pair, K, T, H, C, A, IsMultihash > { private: using Base = detail::Hashtable, - Pair, K, T, H, C, A, IsMultihash + Pair, K, T, H, C, A, IsMultihash >; public: @@ -55,40 +55,40 @@ namespace detail { using Difference = Ptrdiff; using Hasher = H; using KeyEqual = C; - using Value = Pair; + using Value = Pair; using Reference = Value &; using Pointer = AllocatorPointer; using ConstPointer = AllocatorConstPointer; - using Range = HashRange>; - using ConstRange = HashRange>; - using LocalRange = BucketRange>; - using ConstLocalRange = BucketRange>; + using Range = HashRange>; + using ConstRange = HashRange const>; + using LocalRange = BucketRange>; + using ConstLocalRange = BucketRange const>; using Allocator = A; - explicit MapImpl(Size size, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + explicit MapImpl(Size size, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size, hf, eqf, alloc) {} MapImpl(): MapImpl(0) {} - explicit MapImpl(const A &alloc): MapImpl(0, H(), C(), alloc) {} + explicit MapImpl(A const &alloc): MapImpl(0, H(), C(), alloc) {} - MapImpl(Size size, const A &alloc): + MapImpl(Size size, A const &alloc): MapImpl(size, H(), C(), alloc) {} - MapImpl(Size size, const H &hf, const A &alloc): + MapImpl(Size size, H const &hf, A const &alloc): MapImpl(size, hf, C(), alloc) {} - MapImpl(const MapImpl &m): Base(m, + MapImpl(MapImpl const &m): Base(m, allocator_container_copy(m.get_alloc())) {} - MapImpl(const MapImpl &m, const A &alloc): Base(m, alloc) {} + MapImpl(MapImpl const &m, A const &alloc): Base(m, alloc) {} MapImpl(MapImpl &&m): Base(move(m)) {} - MapImpl(MapImpl &&m, const A &alloc): Base(move(m), alloc) {} + MapImpl(MapImpl &&m, A const &alloc): Base(move(m), alloc) {} template && IsConvertible, Value> - >> MapImpl(R range, Size size = 0, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + >> MapImpl(R range, Size size = 0, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size ? size : detail::estimate_hrsize(range), hf, eqf, alloc) { for (; !range.empty(); range.pop_front()) @@ -97,25 +97,25 @@ namespace detail { } template - MapImpl(R range, Size size, const A &alloc) + MapImpl(R range, Size size, A const &alloc) : MapImpl(range, size, H(), C(), alloc) {} template - MapImpl(R range, Size size, const H &hf, const A &alloc) + MapImpl(R range, Size size, H const &hf, A const &alloc) : MapImpl(range, size, hf, C(), alloc) {} MapImpl(InitializerList init, Size size = 0, - const H &hf = H(), const C &eqf = C(), const A &alloc = A() + H const &hf = H(), C const &eqf = C(), A const &alloc = A() ): MapImpl(iter(init), size, hf, eqf, alloc) {} - MapImpl(InitializerList init, Size size, const A &alloc) + MapImpl(InitializerList init, Size size, A const &alloc) : MapImpl(iter(init), size, H(), C(), alloc) {} - MapImpl(InitializerList init, Size size, const H &hf, - const A &alloc + MapImpl(InitializerList init, Size size, H const &hf, + A const &alloc ): MapImpl(iter(init), size, hf, C(), alloc) {} - MapImpl &operator=(const MapImpl &m) { + MapImpl &operator=(MapImpl const &m) { Base::operator=(m); return *this; } @@ -137,16 +137,16 @@ namespace detail { return *this; } - T *at(const K &key) { + T *at(K const &key) { static_assert(!IsMultihash, "at() only allowed on regular maps"); return Base::access(key); } - const T *at(const K &key) const { + T const *at(K const &key) const { static_assert(!IsMultihash, "at() only allowed on regular maps"); return Base::access(key); } - T &operator[](const K &key) { + T &operator[](K const &key) { static_assert(!IsMultihash, "operator[] only allowed on regular maps"); return Base::access_or_insert(key); } @@ -165,14 +165,14 @@ template< typename K, typename T, typename H = ToHash, typename C = EqualWithCstr, - typename A = Allocator> + typename A = Allocator> > using Map = detail::MapImpl; template< typename K, typename T, typename H = ToHash, typename C = EqualWithCstr, - typename A = Allocator> + typename A = Allocator> > using Multimap = detail::MapImpl; } /* namespace ostd */ diff --git a/ostd/maybe.hh b/ostd/maybe.hh index 9bb4a63..ae137f3 100644 --- a/ostd/maybe.hh +++ b/ostd/maybe.hh @@ -36,7 +36,7 @@ namespace detail { constexpr MaybeStorage(): p_null_state('\0') {} - MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) { + MaybeStorage(MaybeStorage const &v): p_engaged(v.p_engaged) { if (p_engaged) ::new(address_of(p_value)) Value(v.p_value); } @@ -45,7 +45,7 @@ namespace detail { ::new(address_of(p_value)) Value(move(v.p_value)); } - constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {} + constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {} constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {} template constexpr MaybeStorage(InPlace, A &&...args): @@ -68,7 +68,7 @@ namespace detail { constexpr MaybeStorage(): p_null_state('\0') {} - MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) { + MaybeStorage(MaybeStorage const &v): p_engaged(v.p_engaged) { if (p_engaged) ::new(address_of(p_value)) Value(v.p_value); } @@ -77,7 +77,7 @@ namespace detail { ::new(address_of(p_value)) Value(move(v.p_value)); } - constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {} + constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {} constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {} @@ -105,10 +105,10 @@ public: "Initialization of Maybe with a non-destructible object is not allowed."); constexpr Maybe() {} - Maybe(const Maybe &) = default; + Maybe(Maybe const &) = default; Maybe(Maybe &&) = default; constexpr Maybe(Nothing) {} - constexpr Maybe(const Value &v): Base(v) {} + constexpr Maybe(Value const &v): Base(v) {} constexpr Maybe(Value &&v): Base(move(v)) {} template>> @@ -131,7 +131,7 @@ public: return *this; } - Maybe &operator=(const Maybe &v) { + Maybe &operator=(Maybe const &v) { if (this->p_engaged == v.p_engaged) { if (this->p_engaged) this->p_value = v.p_value; } else { @@ -189,7 +189,7 @@ public: this->p_engaged = true; } - constexpr const Value *operator->() const { + constexpr Value const *operator->() const { return address_of(this->p_value); } @@ -197,7 +197,7 @@ public: return address_of(this->p_value); } - constexpr const Value &operator*() const { + constexpr Value const &operator*() const { return this->p_value; } @@ -207,7 +207,7 @@ public: constexpr explicit operator bool() const { return this->p_engaged; } - constexpr const Value &value() const { + constexpr Value const &value() const { return this->p_value; } @@ -257,156 +257,156 @@ public: /* maybe vs maybe */ template -inline constexpr bool operator==(const Maybe &a, const Maybe &b) { +inline constexpr bool operator==(Maybe const &a, Maybe const &b) { return (bool(a) != bool(b)) ? false : (!bool(a) ? true : (*a == *b)); } template -inline constexpr bool operator!=(const Maybe &a, const Maybe &b) { +inline constexpr bool operator!=(Maybe const &a, Maybe const &b) { return !(a == b); } template -inline constexpr bool operator<(const Maybe &a, const Maybe &b) { +inline constexpr bool operator<(Maybe const &a, Maybe const &b) { return !bool(b) ? false : (!bool(a) ? true : (*a < *b)); } template -inline constexpr bool operator>(const Maybe &a, const Maybe &b) { +inline constexpr bool operator>(Maybe const &a, Maybe const &b) { return b < a; } template -inline constexpr bool operator<=(const Maybe &a, const Maybe &b) { +inline constexpr bool operator<=(Maybe const &a, Maybe const &b) { return !(b < a); } template -inline constexpr bool operator>=(const Maybe &a, const Maybe &b) { +inline constexpr bool operator>=(Maybe const &a, Maybe const &b) { return !(a < b); } /* maybe vs nothing */ template -inline constexpr bool operator==(const Maybe &v, Nothing) { +inline constexpr bool operator==(Maybe const &v, Nothing) { return !bool(v); } template -inline constexpr bool operator==(Nothing, const Maybe &v) { +inline constexpr bool operator==(Nothing, Maybe const &v) { return !bool(v); } template -inline constexpr bool operator!=(const Maybe &v, Nothing) { +inline constexpr bool operator!=(Maybe const &v, Nothing) { return bool(v); } template -inline constexpr bool operator!=(Nothing, const Maybe &v) { +inline constexpr bool operator!=(Nothing, Maybe const &v) { return bool(v); } template -inline constexpr bool operator<(const Maybe &, Nothing) { +inline constexpr bool operator<(Maybe const &, Nothing) { return false; } template -inline constexpr bool operator<(Nothing, const Maybe &v) { +inline constexpr bool operator<(Nothing, Maybe const &v) { return bool(v); } template -inline constexpr bool operator<=(const Maybe &v, Nothing) { +inline constexpr bool operator<=(Maybe const &v, Nothing) { return !bool(v); } template -inline constexpr bool operator<=(Nothing, const Maybe &) { +inline constexpr bool operator<=(Nothing, Maybe const &) { return true; } template -inline constexpr bool operator>(const Maybe &v, Nothing) { +inline constexpr bool operator>(Maybe const &v, Nothing) { return bool(v); } template -inline constexpr bool operator>(Nothing, const Maybe &) { +inline constexpr bool operator>(Nothing, Maybe const &) { return false; } template -inline constexpr bool operator>=(const Maybe &, Nothing) { +inline constexpr bool operator>=(Maybe const &, Nothing) { return true; } template -inline constexpr bool operator>=(Nothing, const Maybe &v) { +inline constexpr bool operator>=(Nothing, Maybe const &v) { return !bool(v); } /* maybe vs T */ template -inline constexpr bool operator==(const Maybe &a, const T &b) { +inline constexpr bool operator==(Maybe const &a, T const &b) { return bool(a) ? (*a == b) : false; } template -inline constexpr bool operator==(const T &b, const Maybe &a) { +inline constexpr bool operator==(T const &b, Maybe const &a) { return bool(a) ? (*a == b) : false; } template -inline constexpr bool operator!=(const Maybe &a, const T &b) { +inline constexpr bool operator!=(Maybe const &a, T const &b) { return bool(a) ? !(*a == b) : true; } template -inline constexpr bool operator!=(const T &b, const Maybe &a) { +inline constexpr bool operator!=(T const &b, Maybe const &a) { return bool(a) ? !(*a == b) : true; } template -inline constexpr bool operator<(const Maybe &a, const T &b) { +inline constexpr bool operator<(Maybe const &a, T const &b) { return bool(a) ? Less()(*a, b) : true; } template -inline constexpr bool operator<(const T &b, const Maybe &a) { +inline constexpr bool operator<(T const &b, Maybe const &a) { return bool(a) ? Less()(b, *a) : false; } template -inline constexpr bool operator<=(const Maybe &a, const T &b) { +inline constexpr bool operator<=(Maybe const &a, T const &b) { return !(a > b); } template -inline constexpr bool operator<=(const T &b, const Maybe &a) { +inline constexpr bool operator<=(T const &b, Maybe const &a) { return !(b > a); } template -inline constexpr bool operator>(const Maybe &a, const T &b) { +inline constexpr bool operator>(Maybe const &a, T const &b) { return bool(a) ? (b < a) : true; } template -inline constexpr bool operator>(const T &b, const Maybe &a) { +inline constexpr bool operator>(T const &b, Maybe const &a) { return bool(a) ? (a < b) : true; } template -inline constexpr bool operator>=(const Maybe &a, const T &b) { +inline constexpr bool operator>=(Maybe const &a, T const &b) { return !(a < b); } template -inline constexpr bool operator>=(const T &b, const Maybe &a) { +inline constexpr bool operator>=(T const &b, Maybe const &a) { return !(b < a); } diff --git a/ostd/memory.hh b/ostd/memory.hh index 452d60c..292f07f 100644 --- a/ostd/memory.hh +++ b/ostd/memory.hh @@ -17,7 +17,7 @@ namespace ostd { template constexpr T *address_of(T &v) { return reinterpret_cast(&const_cast - (reinterpret_cast(v))); + (reinterpret_cast(v))); } /* pointer traits */ @@ -181,7 +181,7 @@ template struct DefaultDelete { constexpr DefaultDelete() = default; - template DefaultDelete(const DefaultDelete &) {}; + template DefaultDelete(DefaultDelete const &) {}; void operator()(T *p) const { delete p; @@ -192,7 +192,7 @@ template struct DefaultDelete { constexpr DefaultDelete() = default; - template DefaultDelete(const DefaultDelete &) {}; + template DefaultDelete(DefaultDelete const &) {}; void operator()(T *p) const { delete[] p; @@ -234,7 +234,7 @@ private: struct Nat { int x; }; using Dref = RemoveReference &; - using Dcref = const RemoveReference &; + using Dcref = RemoveReference const &; public: constexpr Box(): p_stor(nullptr, D()) { @@ -248,7 +248,7 @@ public: static_assert(!IsPointer, "Box constructed with null fptr deleter"); } - Box(Pointer p, Conditional, D, AddLvalueReference> d): + Box(Pointer p, Conditional, D, AddLvalueReference> d): p_stor(p, d) {} Box(Pointer p, RemoveReference &&d): @@ -347,7 +347,7 @@ private: struct Nat { int x; }; using Dref = RemoveReference &; - using Dcref = const RemoveReference &; + using Dcref = RemoveReference const &; public: constexpr Box(): p_stor(nullptr, D()) { @@ -364,11 +364,11 @@ public: } template Box(U p, Conditional< - IsReference, D, AddLvalueReference + IsReference, D, AddLvalueReference > d, EnableIf, Nat> = Nat()): p_stor(p, d) {} - Box(Nullptr, Conditional, D, AddLvalueReference> d): + Box(Nullptr, Conditional, D, AddLvalueReference> d): p_stor(nullptr, d) {} template Box(U p, RemoveReference &&d, @@ -495,15 +495,15 @@ template struct Allocator; template<> struct Allocator { using Value = void; using Pointer = void *; - using ConstPointer = const void *; + using ConstPointer = void const *; template using Rebind = Allocator; }; -template<> struct Allocator { - using Value = const void; - using Pointer = const void *; - using ConstPointer = const void *; +template<> struct Allocator { + using Value = void const; + using Pointer = void const *; + using ConstPointer = void const *; template using Rebind = Allocator; }; @@ -513,14 +513,14 @@ template struct Allocator { using Difference = Ptrdiff; using Value = T; using Reference = T &; - using ConstReference = const T &; + using ConstReference = T const &; using Pointer = T *; - using ConstPointer = const T *; + using ConstPointer = T const *; template using Rebind = Allocator; Allocator() {} - template Allocator(const Allocator &) {} + template Allocator(Allocator const &) {} Pointer address(Reference v) const { return address_of(v); @@ -545,19 +545,19 @@ template struct Allocator { void destroy(Pointer p) { p->~T(); } }; -template struct Allocator { +template struct Allocator { using Size = ostd::Size; using Difference = Ptrdiff; - using Value = const T; - using Reference = const T &; - using ConstReference = const T &; - using Pointer = const T *; - using ConstPointer = const T *; + using Value = T const; + using Reference = T const &; + using ConstReference = T const &; + using Pointer = T const *; + using ConstPointer = T const *; template using Rebind = Allocator; Allocator() {} - template Allocator(const Allocator &) {} + template Allocator(Allocator const &) {} ConstPointer address(ConstReference v) const { return address_of(v); @@ -580,12 +580,12 @@ template struct Allocator { }; template -bool operator==(const Allocator &, const Allocator &) { +bool operator==(Allocator const &, Allocator const &) { return true; } template -bool operator!=(const Allocator &, const Allocator &) { +bool operator!=(Allocator const &, Allocator const &) { return false; } @@ -608,7 +608,7 @@ namespace detail { template struct ConstPointer { - using Type = PointerRebind; + using Type = PointerRebind; }; template @@ -644,7 +644,7 @@ namespace detail { template struct ConstVoidPointer { - using Type = PointerRebind; + using Type = PointerRebind; }; template @@ -859,7 +859,7 @@ namespace detail { -> decltype(a.allocate(sz, p), True()); template - auto allocate_hint_test(const A &, S &&, CVP &&) + auto allocate_hint_test(A const &, S &&, CVP &&) -> False; template @@ -910,7 +910,7 @@ namespace detail { True()); template - auto construct_test(const A &, T *, Args &&...) + auto construct_test(A const &, T *, Args &&...) -> False; template @@ -944,7 +944,7 @@ namespace detail { auto destroy_test(A &&a, P &&p) -> decltype(a.destroy(p), True()); template - auto destroy_test(const A &, P &&) -> False; + auto destroy_test(A const &, P &&) -> False; template constexpr bool DestroyTest @@ -973,27 +973,27 @@ namespace detail { auto alloc_max_size_test(A &&a) -> decltype(a.max_size(), True()); template - auto alloc_max_size_test(const A &) -> False; + auto alloc_max_size_test(A const &) -> False; template constexpr bool AllocMaxSizeTest = IsSame())), True>; template - inline AllocatorSize alloc_max_size(True, const A &a) { + inline AllocatorSize alloc_max_size(True, A const &a) { return a.max_size(); } template - inline AllocatorSize alloc_max_size(False, const A &) { + inline AllocatorSize alloc_max_size(False, A const &) { return AllocatorSize(~0); } } /* namespace detail */ template -inline AllocatorSize allocator_max_size(const A &a) { +inline AllocatorSize allocator_max_size(A const &a) { return detail::alloc_max_size(BoolConstant< - detail::AllocMaxSizeTest + detail::AllocMaxSizeTest >(), a); } @@ -1004,27 +1004,27 @@ namespace detail { auto alloc_copy_test(A &&a) -> decltype(a.container_copy(), True()); template - auto alloc_copy_test(const A &) -> False; + auto alloc_copy_test(A const &) -> False; template constexpr bool AllocCopyTest = IsSame())), True>; template - inline AllocatorType alloc_container_copy(True, const A &a) { + inline AllocatorType alloc_container_copy(True, A const &a) { return a.container_copy(); } template - inline AllocatorType alloc_container_copy(False, const A &a) { + inline AllocatorType alloc_container_copy(False, A const &a) { return a; } } /* namespace detail */ template -inline AllocatorType allocator_container_copy(const A &a) { +inline AllocatorType allocator_container_copy(A const &a) { return detail::alloc_container_copy(BoolConstant< - detail::AllocCopyTest + detail::AllocCopyTest >(), a); } diff --git a/ostd/range.hh b/ostd/range.hh index 09a3af6..134c654 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -186,9 +186,9 @@ namespace detail { template constexpr bool IsOutputRangeCore = IsConvertible, OutputRangeTag> || (IsInputRange && - (detail::OutputRangeTest &>::value || - detail::OutputRangeTest &&>::value || - detail::OutputRangeTest >::value)); + (detail::OutputRangeTest const &>::value || + detail::OutputRangeTest &&>::value || + detail::OutputRangeTest >::value)); template> constexpr bool IsOutputRangeBase = false; @@ -205,7 +205,7 @@ namespace detail { template struct RangeIterator { RangeIterator(): p_range() {} - explicit RangeIterator(const T &range) { + explicit RangeIterator(T const &range) { ::new(&get_ref()) T(range); } explicit RangeIterator(T &&range) { @@ -221,7 +221,7 @@ namespace detail { bool operator!=(RangeIterator) const { return !get_ref().empty(); } private: T &get_ref() { return *((T *)&p_range); } - const T &get_ref() const { return *((T *)&p_range); } + T const &get_ref() const { return *((T *)&p_range); } AlignedStorage p_range; }; } @@ -271,15 +271,15 @@ public: using Range = T; RangeHalf() = delete; - RangeHalf(const T &range): p_range(range) {} + RangeHalf(T const &range): p_range(range) {} template>> - RangeHalf(const RangeHalf &half): p_range(half.p_range) {} + RangeHalf(RangeHalf const &half): p_range(half.p_range) {} - RangeHalf(const RangeHalf &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 &operator=(const RangeHalf &half) { + RangeHalf &operator=(RangeHalf const &half) { p_range = half.p_range; return *this; } @@ -310,18 +310,18 @@ public: return p_range.front(); } - RangeDifference distance(const RangeHalf &half) const { + RangeDifference distance(RangeHalf const &half) const { return p_range.distance_front(half.p_range); } - bool equals(const RangeHalf &half) const { + bool equals(RangeHalf const &half) const { return p_range.equals_front(half.p_range); } - bool operator==(const RangeHalf &half) const { + bool operator==(RangeHalf const &half) const { return equals(half); } - bool operator!=(const RangeHalf &half) const { + bool operator!=(RangeHalf const &half) const { return !equals(half); } @@ -377,16 +377,16 @@ public: T iter() const { return p_range; } - HalfRange iter(const RangeHalf &other) const { + HalfRange iter(RangeHalf const &other) const { return HalfRange(*this, other); } RangeValue *data() { return p_range.data(); } - const RangeValue *data() const { return p_range.data(); } + RangeValue const *data() const { return p_range.data(); } }; template -inline RangeDifference operator-(const R &lhs, const R &rhs) { +inline RangeDifference operator-(R const &lhs, R const &rhs) { return rhs.distance(lhs); } @@ -438,7 +438,7 @@ template begin() const { - return detail::RangeIterator((const B &)*this); + return detail::RangeIterator((B const &)*this); } detail::RangeIterator end() const { return detail::RangeIterator(); @@ -498,7 +498,7 @@ template(iter()); } - Size put_n(const Value *p, Size n) { + Size put_n(Value const *p, Size n) { B &r = *((B *)this); Size on = n; for (; n && r.put(*p++); --n); @@ -539,7 +539,7 @@ templatepop_front(); return tmp; } @@ -549,18 +549,18 @@ templatepush_front(); return tmp; } B operator+(Difference n) const { - B tmp(*((const B *)this)); + B tmp(*((B const *)this)); tmp.pop_front_n(n); return tmp; } B operator-(Difference n) const { - B tmp(*((const B *)this)); + B tmp(*((B const *)this)); tmp.push_front_n(n); return tmp; } @@ -658,12 +658,12 @@ inline auto iter(T &r) -> decltype(r.iter()) { } template -inline auto iter(const T &r) -> decltype(r.iter()) { +inline auto iter(T const &r) -> decltype(r.iter()) { return r.iter(); } template -inline auto citer(const T &r) -> decltype(r.iter()) { +inline auto citer(T const &r) -> decltype(r.iter()) { return r.iter(); } @@ -676,7 +676,7 @@ template front() const { return *p_beg; } RangeReference back() const { return *(p_end - 1); } - bool equals_front(const HalfRange &range) const { + bool equals_front(HalfRange const &range) const { return p_beg == range.p_beg; } - bool equals_back(const HalfRange &range) const { + bool equals_back(HalfRange const &range) const { return p_end == range.p_end; } - RangeDifference distance_front(const HalfRange &range) const { + RangeDifference distance_front(HalfRange const &range) const { return range.p_beg - p_beg; } - RangeDifference distance_back(const HalfRange &range) const { + RangeDifference distance_back(HalfRange const &range) const { return range.p_end - p_end; } @@ -764,7 +764,7 @@ public: return p_beg[idx]; } - bool put(const RangeValue &v) { + bool put(RangeValue const &v) { return p_beg.range().put(v); } bool put(RangeValue &&v) { @@ -772,7 +772,7 @@ public: } RangeValue *data() { return p_beg.data(); } - const RangeValue *data() const { return p_beg.data(); } + RangeValue const *data() const { return p_beg.data(); } }; template @@ -788,11 +788,11 @@ private: public: ReverseRange() = delete; - ReverseRange(const T &range): p_range(range) {} - ReverseRange(const ReverseRange &it): p_range(it.p_range) {} + 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 &operator=(const ReverseRange &v) { + ReverseRange &operator=(ReverseRange const &v) { p_range = v.p_range; return *this; } @@ -800,7 +800,7 @@ public: p_range = move(v.p_range); return *this; } - ReverseRange &operator=(const T &v) { + ReverseRange &operator=(T const &v) { p_range = v; return *this; } @@ -812,17 +812,17 @@ public: bool empty() const { return p_range.empty(); } Rsize size() const { return p_range.size(); } - bool equals_front(const ReverseRange &r) const { + bool equals_front(ReverseRange const &r) const { return p_range.equals_back(r.p_range); } - bool equals_back(const ReverseRange &r) const { + bool equals_back(ReverseRange const &r) const { return p_range.equals_front(r.p_range); } - RangeDifference distance_front(const ReverseRange &r) const { + RangeDifference distance_front(ReverseRange const &r) const { return -p_range.distance_back(r.p_range); } - RangeDifference distance_back(const ReverseRange &r) const { + RangeDifference distance_back(ReverseRange const &r) const { return -p_range.distance_front(r.p_range); } @@ -863,11 +863,11 @@ private: public: MoveRange() = delete; - MoveRange(const T &range): p_range(range) {} - MoveRange(const MoveRange &it): p_range(it.p_range) {} + 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 &operator=(const MoveRange &v) { + MoveRange &operator=(MoveRange const &v) { p_range = v.p_range; return *this; } @@ -875,7 +875,7 @@ public: p_range = move(v.p_range); return *this; } - MoveRange &operator=(const T &v) { + MoveRange &operator=(T const &v) { p_range = v; return *this; } @@ -887,17 +887,17 @@ public: bool empty() const { return p_range.empty(); } Rsize size() const { return p_range.size(); } - bool equals_front(const MoveRange &r) const { + bool equals_front(MoveRange const &r) const { return p_range.equals_front(r.p_range); } - bool equals_back(const MoveRange &r) const { + bool equals_back(MoveRange const &r) const { return p_range.equals_back(r.p_range); } - RangeDifference distance_front(const MoveRange &r) const { + RangeDifference distance_front(MoveRange const &r) const { return p_range.distance_front(r.p_range); } - RangeDifference distance_back(const MoveRange &r) const { + RangeDifference distance_back(MoveRange const &r) const { return p_range.distance_back(r.p_range); } @@ -922,14 +922,14 @@ public: return MoveRange(p_range.slice(start, end)); } - bool put(const Rval &v) { return p_range.put(v); } + bool put(Rval const &v) { return p_range.put(v); } bool put(Rval &&v) { return p_range.put(move(v)); } }; template struct NumberRange: InputRange, ForwardRangeTag, T, T> { NumberRange() = delete; - NumberRange(const NumberRange &it): p_a(it.p_a), p_b(it.p_b), + NumberRange(NumberRange const &it): p_a(it.p_a), p_b(it.p_b), p_step(it.p_step) {} NumberRange(T a, T b, T step = T(1)): p_a(a), p_b(b), p_step(step) {} @@ -937,7 +937,7 @@ struct NumberRange: InputRange, ForwardRangeTag, T, T> { bool empty() const { return p_a * p_step >= p_b * p_step; } - bool equals_front(const NumberRange &range) const { + bool equals_front(NumberRange const &range) const { return p_a == range.p_a; } @@ -974,9 +974,9 @@ public: PointerRange(T *beg, Size n): p_beg(beg), p_end(beg + n) {} template>> - PointerRange(const PointerRange &v): p_beg(&v[0]), p_end(&v[v.size()]) {} + PointerRange(PointerRange const &v): p_beg(&v[0]), p_end(&v[v.size()]) {} - PointerRange &operator=(const PointerRange &v) { + PointerRange &operator=(PointerRange const &v) { p_beg = v.p_beg; p_end = v.p_end; return *this; @@ -1010,11 +1010,11 @@ public: T &front() const { return *p_beg; } - bool equals_front(const PointerRange &range) const { + bool equals_front(PointerRange const &range) const { return p_beg == range.p_beg; } - Ptrdiff distance_front(const PointerRange &range) const { + Ptrdiff distance_front(PointerRange const &range) const { return range.p_beg - p_beg; } @@ -1044,11 +1044,11 @@ public: T &back() const { return *(p_end - 1); } - bool equals_back(const PointerRange &range) const { + bool equals_back(PointerRange const &range) const { return p_end == range.p_end; } - Ptrdiff distance_back(const PointerRange &range) const { + Ptrdiff distance_back(PointerRange const &range) const { return range.p_end - p_end; } @@ -1062,7 +1062,7 @@ public: T &operator[](Size i) const { return p_beg[i]; } /* satisfy OutputRange */ - bool put(const T &v) { + bool put(T const &v) { if (empty()) return false; *(p_beg++) = v; return true; @@ -1073,7 +1073,7 @@ public: return true; } - Size put_n(const T *p, Size n) { + Size put_n(T const *p, Size n) { Size ret = size(); if (n < ret) ret = n; if (IsPod) { @@ -1104,7 +1104,7 @@ public: } T *data() { return p_beg; } - const T *data() const { return p_beg; } + T const *data() const { return p_beg; } private: T *p_beg, *p_end; @@ -1116,8 +1116,8 @@ inline PointerRange iter(T (&array)[N]) { } template -inline PointerRange iter(const T (&array)[N]) { - return PointerRange(array, N); +inline PointerRange iter(T const (&array)[N]) { + return PointerRange(array, N); } namespace detail { @@ -1158,15 +1158,15 @@ private: public: EnumeratedRange() = delete; - EnumeratedRange(const T &range): p_range(range), p_index(0) {} + EnumeratedRange(T const &range): p_range(range), p_index(0) {} - EnumeratedRange(const EnumeratedRange &it): + EnumeratedRange(EnumeratedRange const &it): p_range(it.p_range), p_index(it.p_index) {} EnumeratedRange(EnumeratedRange &&it): p_range(move(it.p_range)), p_index(it.p_index) {} - EnumeratedRange &operator=(const EnumeratedRange &v) { + EnumeratedRange &operator=(EnumeratedRange const &v) { p_range = v.p_range; p_index = v.p_index; return *this; @@ -1176,7 +1176,7 @@ public: p_index = v.p_index; return *this; } - EnumeratedRange &operator=(const T &v) { + EnumeratedRange &operator=(T const &v) { p_range = v; p_index = 0; return *this; @@ -1189,7 +1189,7 @@ public: bool empty() const { return p_range.empty(); } - bool equals_front(const EnumeratedRange &r) const { + bool equals_front(EnumeratedRange const &r) const { return p_range.equals_front(r.p_range); } @@ -1222,14 +1222,14 @@ private: RangeSize p_remaining; public: TakeRange() = delete; - TakeRange(const T &range, RangeSize rem): p_range(range), + TakeRange(T const &range, RangeSize rem): p_range(range), p_remaining(rem) {} - TakeRange(const TakeRange &it): p_range(it.p_range), + TakeRange(TakeRange const &it): p_range(it.p_range), p_remaining(it.p_remaining) {} TakeRange(TakeRange &&it): p_range(move(it.p_range)), p_remaining(it.p_remaining) {} - TakeRange &operator=(const TakeRange &v) { + TakeRange &operator=(TakeRange const &v) { p_range = v.p_range; p_remaining = v.p_remaining; return *this; } TakeRange &operator=(TakeRange &&v) { @@ -1256,7 +1256,7 @@ public: RangeReference front() const { return p_range.front(); } - bool equals_front(const TakeRange &r) const { + bool equals_front(TakeRange const &r) const { return p_range.equals_front(r.p_range); } }; @@ -1271,14 +1271,14 @@ private: RangeSize p_chunksize; public: ChunksRange() = delete; - ChunksRange(const T &range, RangeSize chs): p_range(range), + ChunksRange(T const &range, RangeSize chs): p_range(range), p_chunksize(chs) {} - ChunksRange(const ChunksRange &it): p_range(it.p_range), + ChunksRange(ChunksRange const &it): p_range(it.p_range), p_chunksize(it.p_chunksize) {} ChunksRange(ChunksRange &&it): p_range(move(it.p_range)), p_chunksize(it.p_chunksize) {} - ChunksRange &operator=(const ChunksRange &v) { + ChunksRange &operator=(ChunksRange const &v) { p_range = v.p_range; p_chunksize = v.p_chunksize; return *this; } ChunksRange &operator=(ChunksRange &&v) { @@ -1289,7 +1289,7 @@ public: bool empty() const { return p_range.empty(); } - bool equals_front(const ChunksRange &r) const { + bool equals_front(ChunksRange const &r) const { return p_range.equals_front(r.p_range); } @@ -1305,7 +1305,7 @@ namespace detail { template struct JoinRangeEmpty { template - static bool empty(const T &tup) { + static bool empty(T const &tup) { if (!ostd::get(tup).empty()) return false; return JoinRangeEmpty::empty(tup); @@ -1315,7 +1315,7 @@ namespace detail { template struct JoinRangeEmpty { template - static bool empty(const T &) { + static bool empty(T const &) { return true; } }; @@ -1323,7 +1323,7 @@ namespace detail { template struct TupleRangeEqual { template - static bool equal(const T &tup1, const T &tup2) { + static bool equal(T const &tup1, T const &tup2) { if (!ostd::get(tup1).equals_front(ostd::get(tup2))) return false; return TupleRangeEqual::equal(tup1, tup2); @@ -1333,7 +1333,7 @@ namespace detail { template struct TupleRangeEqual { template - static bool equal(const T &, const T &) { + static bool equal(T const &, T const &) { return true; } }; @@ -1360,7 +1360,7 @@ namespace detail { template struct JoinRangeFront { template - static T front(const U &tup) { + static T front(U const &tup) { if (!ostd::get(tup).empty()) { return ostd::get(tup).front(); } @@ -1371,7 +1371,7 @@ namespace detail { template struct JoinRangeFront { template - static T front(const U &tup) { + static T front(U const &tup) { return ostd::get<0>(tup).front(); } }; @@ -1386,12 +1386,12 @@ private: Tuple p_ranges; public: JoinRange() = delete; - JoinRange(const R &...ranges): p_ranges(ranges...) {} + JoinRange(R const &...ranges): p_ranges(ranges...) {} JoinRange(R &&...ranges): p_ranges(forward(ranges)...) {} - JoinRange(const JoinRange &v): p_ranges(v.p_ranges) {} + JoinRange(JoinRange const &v): p_ranges(v.p_ranges) {} JoinRange(JoinRange &&v): p_ranges(move(v.p_ranges)) {} - JoinRange &operator=(const JoinRange &v) { + JoinRange &operator=(JoinRange const &v) { p_ranges = v.p_ranges; return *this; } @@ -1405,7 +1405,7 @@ public: return detail::JoinRangeEmpty<0, sizeof...(R)>::empty(p_ranges); } - bool equals_front(const JoinRange &r) const { + bool equals_front(JoinRange const &r) const { return detail::TupleRangeEqual<0, sizeof...(R)>::equal(p_ranges, r.p_ranges); } @@ -1437,7 +1437,7 @@ namespace detail { template struct ZipRangeEmpty { template - static bool empty(const T &tup) { + static bool empty(T const &tup) { if (ostd::get(tup).empty()) return true; return ZipRangeEmpty::empty(tup); @@ -1447,7 +1447,7 @@ namespace detail { template struct ZipRangeEmpty { template - static bool empty(const T &) { + static bool empty(T const &) { return false; } }; @@ -1472,12 +1472,12 @@ namespace detail { template struct ZipRangeFront { template - static ZipValue tup_get(const U &tup, detail::TupleIndices) { + static ZipValue tup_get(U const &tup, detail::TupleIndices) { return ZipValue(ostd::get(tup).front()...); } template - static ZipValue front(const U &tup) { + static ZipValue front(U const &tup) { using Index = detail::MakeTupleIndices; return ZipRangeFront::tup_get(tup, Index()); } @@ -1494,12 +1494,12 @@ private: Tuple p_ranges; public: ZipRange() = delete; - ZipRange(const R &...ranges): p_ranges(ranges...) {} + ZipRange(R const &...ranges): p_ranges(ranges...) {} ZipRange(R &&...ranges): p_ranges(forward(ranges)...) {} - ZipRange(const ZipRange &v): p_ranges(v.p_ranges) {} + ZipRange(ZipRange const &v): p_ranges(v.p_ranges) {} ZipRange(ZipRange &&v): p_ranges(move(v.p_ranges)) {} - ZipRange &operator=(const ZipRange &v) { + ZipRange &operator=(ZipRange const &v) { p_ranges = v.p_ranges; return *this; } @@ -1513,7 +1513,7 @@ public: return detail::ZipRangeEmpty<0, sizeof...(R)>::empty(p_ranges); } - bool equals_front(const ZipRange &r) const { + bool equals_front(ZipRange const &r) const { return detail::TupleRangeEqual<0, sizeof...(R)>::equal(p_ranges, r.p_ranges); } @@ -1531,12 +1531,12 @@ template struct AppenderRange: OutputRange, typename T::Value, typename T::Reference, typename T::Size, typename T::Difference> { AppenderRange(): p_data() {} - AppenderRange(const T &v): p_data(v) {} + AppenderRange(T const &v): p_data(v) {} AppenderRange(T &&v): p_data(move(v)) {} - AppenderRange(const AppenderRange &v): p_data(v.p_data) {} + AppenderRange(AppenderRange const &v): p_data(v.p_data) {} AppenderRange(AppenderRange &&v): p_data(move(v.p_data)) {} - AppenderRange &operator=(const AppenderRange &v) { + AppenderRange &operator=(AppenderRange const &v) { p_data = v.p_data; return *this; } @@ -1546,7 +1546,7 @@ struct AppenderRange: OutputRange, typename T::Value, return *this; } - AppenderRange &operator=(const T &v) { + AppenderRange &operator=(T const &v) { p_data = v; return *this; } diff --git a/ostd/set.hh b/ostd/set.hh index 72d3f55..55f74f1 100644 --- a/ostd/set.hh +++ b/ostd/set.hh @@ -18,14 +18,14 @@ namespace ostd { namespace detail { template struct SetBase { - static inline const T &get_key(const T &e) { + static inline T const &get_key(T const &e) { return e; } static inline T &get_data(T &e) { return e; } template - static inline void set_key(T &, const U &, A &) {} + static inline void set_key(T &, U const &, A &) {} static inline void swap_elem(T &a, T &b) { swap_adl(a, b); } }; @@ -49,35 +49,35 @@ namespace detail { using Pointer = AllocatorPointer; using ConstPointer = AllocatorConstPointer; using Range = HashRange; - using ConstRange = HashRange; + using ConstRange = HashRange; using LocalRange = BucketRange; - using ConstLocalRange = BucketRange; + using ConstLocalRange = BucketRange; using Allocator = A; - explicit SetImpl(Size size, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + explicit SetImpl(Size size, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size, hf, eqf, alloc) {} SetImpl(): SetImpl(0) {} - explicit SetImpl(const A &alloc): SetImpl(0, H(), C(), alloc) {} + explicit SetImpl(A const &alloc): SetImpl(0, H(), C(), alloc) {} - SetImpl(Size size, const A &alloc): + SetImpl(Size size, A const &alloc): SetImpl(size, H(), C(), alloc) {} - SetImpl(Size size, const H &hf, const A &alloc): + SetImpl(Size size, H const &hf, A const &alloc): SetImpl(size, hf, C(), alloc) {} - SetImpl(const SetImpl &m): Base(m, + SetImpl(SetImpl const &m): Base(m, allocator_container_copy(m.get_alloc())) {} - SetImpl(const SetImpl &m, const A &alloc): Base(m, alloc) {} + SetImpl(SetImpl const &m, A const &alloc): Base(m, alloc) {} SetImpl(SetImpl &&m): Base(move(m)) {} - SetImpl(SetImpl &&m, const A &alloc): Base(move(m), alloc) {} + SetImpl(SetImpl &&m, A const &alloc): Base(move(m), alloc) {} template && IsConvertible, Value> - >> SetImpl(R range, Size size = 0, const H &hf = H(), - const C &eqf = C(), const A &alloc = A() + >> SetImpl(R range, Size size = 0, H const &hf = H(), + C const &eqf = C(), A const &alloc = A() ): Base(size ? size : detail::estimate_hrsize(range), hf, eqf, alloc) { for (; !range.empty(); range.pop_front()) @@ -86,25 +86,25 @@ namespace detail { } template - SetImpl(R range, Size size, const A &alloc) + SetImpl(R range, Size size, A const &alloc) : SetImpl(range, size, H(), C(), alloc) {} template - SetImpl(R range, Size size, const H &hf, const A &alloc) + SetImpl(R range, Size size, H const &hf, A const &alloc) : SetImpl(range, size, hf, C(), alloc) {} SetImpl(InitializerList init, Size size = 0, - const H &hf = H(), const C &eqf = C(), const A &alloc = A() + H const &hf = H(), C const &eqf = C(), A const &alloc = A() ): SetImpl(iter(init), size, hf, eqf, alloc) {} - SetImpl(InitializerList init, Size size, const A &alloc) + SetImpl(InitializerList init, Size size, A const &alloc) : SetImpl(iter(init), size, H(), C(), alloc) {} - SetImpl(InitializerList init, Size size, const H &hf, - const A &alloc + SetImpl(InitializerList init, Size size, H const &hf, + A const &alloc ): SetImpl(iter(init), size, hf, C(), alloc) {} - SetImpl &operator=(const SetImpl &m) { + SetImpl &operator=(SetImpl const &m) { Base::operator=(m); return *this; } diff --git a/ostd/stream.hh b/ostd/stream.hh index ef87a09..5f73f7e 100644 --- a/ostd/stream.hh +++ b/ostd/stream.hh @@ -37,7 +37,7 @@ namespace detail { template struct FormatOutRange: OutputRange, char> { FormatOutRange(char *ibuf): buf(ibuf), idx(0) {} - FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {} + FormatOutRange(FormatOutRange const &r): buf(r.buf), idx(r.idx) {} char *buf; Size idx; bool put(char v) { @@ -68,8 +68,8 @@ private: } template - inline bool write_impl(const T &v, EnableIf< - !IsConstructible, StNat + inline bool write_impl(T const &v, EnableIf< + !IsConstructible, StNat > = StNat()) { return write(ostd::to_string(v)); } @@ -99,7 +99,7 @@ public: virtual bool flush() { return true; } virtual Size read_bytes(void *, Size) { return 0; } - virtual Size write_bytes(const void *, Size) { return 0; } + virtual Size write_bytes(void const *, Size) { return 0; } virtual int getchar() { byte c; @@ -112,27 +112,27 @@ public: } template - bool write(const T &v) { + bool write(T const &v) { return write_impl(v); } template - bool write(const T &v, const A &...args) { + bool write(T const &v, A const &...args) { return write(v) && write(args...); } template - bool writeln(const T &v) { + bool writeln(T const &v) { return write(v) && putchar('\n'); } template - bool writeln(const T &v, const A &...args) { + bool writeln(T const &v, A const &...args) { return write(v) && write(args...) && putchar('\n'); } template - bool writef(ConstCharRange fmt, const A &...args) { + bool writef(ConstCharRange fmt, A const &...args) { char buf[512]; Ptrdiff need = format(detail::FormatOutRange(buf), fmt, args...); @@ -147,14 +147,14 @@ public: } template - bool writefln(ConstCharRange fmt, const A &...args) { + bool writefln(ConstCharRange fmt, A const &...args) { return writef(fmt, args...) && putchar('\n'); } template StreamRange iter(); - template Size put(const T *v, Size count) { + template Size put(T const *v, Size count) { return write_bytes(v, count * sizeof(T)) / sizeof(T); } @@ -182,7 +182,7 @@ struct StreamRange: InputRange< > { StreamRange() = delete; StreamRange(Stream &s): p_stream(&s), p_size(s.size()) {} - StreamRange(const StreamRange &r): p_stream(r.p_stream), p_size(r.p_size) {} + StreamRange(StreamRange const &r): p_stream(r.p_stream), p_size(r.p_size) {} bool empty() const { return (p_size - p_stream->tell()) < StreamOffset(sizeof(T)); @@ -200,7 +200,7 @@ struct StreamRange: InputRange< return val; } - bool equals_front(const StreamRange &s) const { + bool equals_front(StreamRange const &s) const { return p_stream->tell() == s.p_stream->tell(); } @@ -210,7 +210,7 @@ struct StreamRange: InputRange< return (v == sizeof(T)); } - Size put_n(const T *p, Size n) { + Size put_n(T const *p, Size n) { return p_stream->put(p, n); } diff --git a/ostd/string.hh b/ostd/string.hh index 76fe14d..7cd4284 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -49,21 +49,21 @@ public: p_beg(beg), p_end(beg + N - (beg[N - 1] == '\0')) {} template - CharRangeBase(const StringBase &s, EnableIf< + CharRangeBase(StringBase const &s, EnableIf< IsConvertible, Nat > = Nat()): p_beg(s.data()), p_end(s.data() + s.size()) {} template>> - CharRangeBase(const CharRangeBase &v): + CharRangeBase(CharRangeBase const &v): p_beg(&v[0]), p_end(&v[v.size()]) {} - CharRangeBase &operator=(const CharRangeBase &v) { + CharRangeBase &operator=(CharRangeBase const &v) { p_beg = v.p_beg; p_end = v.p_end; return *this; } template - CharRangeBase &operator=(const StringBase &s) { + CharRangeBase &operator=(StringBase const &s) { p_beg = s.data(); p_end = s.data() + s.size(); return *this; } /* TODO: traits for utf-16/utf-32 string lengths, for now assume char */ @@ -94,11 +94,11 @@ public: T &front() const { return *p_beg; } - bool equals_front(const CharRangeBase &range) const { + bool equals_front(CharRangeBase const &range) const { return p_beg == range.p_beg; } - Ptrdiff distance_front(const CharRangeBase &range) const { + Ptrdiff distance_front(CharRangeBase const &range) const { return range.p_beg - p_beg; } @@ -123,11 +123,11 @@ public: T &back() const { return *(p_end - 1); } - bool equals_back(const CharRangeBase &range) const { + bool equals_back(CharRangeBase const &range) const { return p_end == range.p_end; } - Ptrdiff distance_back(const CharRangeBase &range) const { + Ptrdiff distance_back(CharRangeBase const &range) const { return range.p_end - p_end; } @@ -145,7 +145,7 @@ public: return true; } - Size put_n(const T *p, Size n) { + Size put_n(T const *p, Size n) { Size an = ostd::min(n, size()); memcpy(p_beg, p, an * sizeof(T)); p_beg += an; @@ -153,14 +153,14 @@ public: } T *data() { return p_beg; } - const T *data() const { return p_beg; } + T const *data() const { return p_beg; } Size to_hash() const { return detail::mem_hash(data(), size()); } /* non-range */ - int compare(CharRangeBase s) const { + int compare(CharRangeBase s) const { int ret = memcmp(data(), s.data(), ostd::min(size(), s.size())); return ret ? ret : (size() - s.size()); } @@ -181,7 +181,7 @@ private: }; using CharRange = CharRangeBase; -using ConstCharRange = CharRangeBase; +using ConstCharRange = CharRangeBase; inline bool operator==(ConstCharRange lhs, ConstCharRange rhs) { return !lhs.compare(rhs); @@ -254,17 +254,17 @@ public: using Difference = Ptrdiff; using Value = T; using Reference = T &; - using ConstReference = const T &; + using ConstReference = T const &; using Pointer = AllocatorPointer; using ConstPointer = AllocatorConstPointer; using Range = CharRangeBase; - using ConstRange = CharRangeBase; + using ConstRange = CharRangeBase; using Allocator = A; - StringBase(const A &a = A()): p_len(0), p_cap(0), + StringBase(A const &a = A()): p_len(0), p_cap(0), p_buf((Pointer)&p_len, a) {} - explicit StringBase(Size n, T val = T(), const A &al = A()): + explicit StringBase(Size n, T val = T(), A const &al = A()): StringBase(al) { if (!n) return; p_buf.first() = allocator_allocate(p_buf.second(), n + 1); @@ -274,14 +274,14 @@ public: *cur = '\0'; } - StringBase(const StringBase &s): p_len(0), p_cap(0), + StringBase(StringBase const &s): p_len(0), p_cap(0), p_buf((Pointer)&p_len, allocator_container_copy(s.p_buf.second())) { if (!s.p_len) return; reserve(s.p_len); p_len = s.p_len; memcpy(p_buf.first(), s.p_buf.first(), (p_len + 1) * sizeof(T)); } - StringBase(const StringBase &s, const A &a): p_len(0), p_cap(0), + StringBase(StringBase const &s, A const &a): p_len(0), p_cap(0), p_buf((Pointer)&p_len, a) { if (!s.p_len) return; reserve(s.p_len); @@ -293,7 +293,7 @@ public: s.p_len = s.p_cap = 0; s.p_buf.first() = (Pointer)&s.p_len; } - StringBase(StringBase &&s, const A &a): p_len(0), p_cap(0), + StringBase(StringBase &&s, A const &a): p_len(0), p_cap(0), p_buf((Pointer)&p_len, a) { if (!s.p_len) return; if (a != s.p_buf.second()) { @@ -309,8 +309,8 @@ public: s.p_buf.first() = &s.p_cap; } - StringBase(const StringBase &s, Size pos, Size len = npos, - const A &a = A()): StringBase(a) { + StringBase(StringBase const &s, Size pos, Size len = npos, + A const &a = A()): StringBase(a) { Size end = (len == npos) ? s.size() : (pos + len); Size nch = (end - pos); reserve(nch); @@ -320,7 +320,7 @@ public: } /* TODO: traits for utf-16/utf-32 string lengths, for now assume char */ - StringBase(ConstRange v, const A &a = A()): StringBase(a) { + StringBase(ConstRange v, A const &a = A()): StringBase(a) { if (!v.size()) return; reserve(v.size()); memcpy(p_buf.first(), &v[0], v.size()); @@ -329,18 +329,18 @@ public: } template - StringBase(U v, const EnableIf< - IsConvertible && !IsArray, A - > &a = A()): StringBase(ConstRange(v), a) {} + StringBase(U v, EnableIf< + IsConvertible && !IsArray, A + > const &a = A()): StringBase(ConstRange(v), a) {} template - StringBase(U (&v)[N], const EnableIf< - IsConvertible, A - > &a = A()): StringBase(ConstRange(v), a) {} + StringBase(U (&v)[N], EnableIf< + IsConvertible, A + > const &a = A()): StringBase(ConstRange(v), a) {} template && IsConvertible, Value> - >> StringBase(R range, const A &a = A()): StringBase(a) { + >> StringBase(R range, A const &a = A()): StringBase(a) { ctor_from_range(range); } @@ -355,7 +355,7 @@ public: *p_buf.first() = '\0'; } - StringBase &operator=(const StringBase &v) { + StringBase &operator=(StringBase const &v) { if (this == &v) return *this; clear(); if (AllocatorPropagateOnContainerCopyAssignment) { @@ -397,20 +397,20 @@ public: } template - EnableIf && !IsArray, StringBase &> + EnableIf && !IsArray, StringBase &> operator=(U v) { return operator=(ConstRange(v)); } template - EnableIf, StringBase &> + EnableIf, StringBase &> operator=(U (&v)[N]) { return operator=(ConstRange(v)); } template && IsConvertible, Value> - >> StringBase &operator=(const R &r) { + >> StringBase &operator=(R const &r) { clear(); ctor_from_range(r); return *this; @@ -448,19 +448,19 @@ public: } T &operator[](Size i) { return p_buf.first()[i]; } - const T &operator[](Size i) const { return p_buf.first()[i]; } + T const &operator[](Size i) const { return p_buf.first()[i]; } T &at(Size i) { return p_buf.first()[i]; } - const T &at(Size i) const { return p_buf.first()[i]; } + T const &at(Size i) const { return p_buf.first()[i]; } T &front() { return p_buf.first()[0]; } - const T &front() const { return p_buf.first()[0]; }; + T const &front() const { return p_buf.first()[0]; }; T &back() { return p_buf.first()[size() - 1]; } - const T &back() const { return p_buf.first()[size() - 1]; } + T const &back() const { return p_buf.first()[size() - 1]; } Value *data() { return p_buf.first(); } - const Value *data() const { return p_buf.first(); } + Value const *data() const { return p_buf.first(); } Size size() const { return p_len; @@ -531,7 +531,7 @@ public: return append(1, c); } template - StringBase &operator+=(const R &v) { + StringBase &operator+=(R const &v) { return append(v); } @@ -575,11 +575,11 @@ using String = StringBase; /* string literals */ inline namespace literals { inline namespace string_literals { - inline String operator "" _s(const char *str, Size len) { + inline String operator "" _s(char const *str, Size len) { return String(ConstCharRange(str, len)); } - inline ConstCharRange operator "" _S(const char *str, Size len) { + inline ConstCharRange operator "" _S(char const *str, Size len) { return ConstCharRange(str, len); } } } @@ -607,7 +607,7 @@ namespace detail { } template -bool concat(R &&sink, const T &v, ConstCharRange sep, F func) { +bool concat(R &&sink, T const &v, ConstCharRange sep, F func) { auto range = ostd::iter(v); if (range.empty()) return true; for (;;) { @@ -623,7 +623,7 @@ bool concat(R &&sink, const T &v, ConstCharRange sep, F func) { } template -bool concat(R &&sink, const T &v, ConstCharRange sep = " ") { +bool concat(R &&sink, T const &v, ConstCharRange sep = " ") { auto range = ostd::iter(v); if (range.empty()) return true; for (;;) { @@ -657,7 +657,7 @@ namespace detail { p_written += ret; return ret; } - Size put_n(const char *v, Size n) { + Size put_n(char const *v, Size n) { Size ret = p_out.put_n(v, n); p_written += ret; return ret; @@ -676,7 +676,7 @@ namespace detail { BoolConstant().stringify()), String>>; template - static True test_stringify(decltype(declval().to_string + static True test_stringify(decltype(declval().to_string (declval())) *); template @@ -701,7 +701,7 @@ struct ToString>> { using Argument = RemoveCv>; using Result = String; - String operator()(const T &v) const { + String operator()(T const &v) const { String ret("{"); auto x = appender(); if (concat(x, ostd::iter(v), ", ", ToString< @@ -721,7 +721,7 @@ struct ToString>; using Result = String; - String operator()(const T &v) const { + String operator()(T const &v) const { auto app = appender(); detail::TostrRange> sink(app); if (!v.to_string(sink)) return String(); @@ -731,7 +731,7 @@ struct ToString - void str_printf(String &s, const char *fmt, T v) { + void str_printf(String &s, char const *fmt, T v) { char buf[256]; int n = snprintf(buf, sizeof(buf), fmt, v); s.clear(); @@ -802,10 +802,10 @@ template struct ToString { } }; -template<> struct ToString { - using Argument = const char *; +template<> struct ToString { + using Argument = char const *; using Result = String; - String operator()(const char *s) { + String operator()(char const *s) { return String(s); } }; @@ -821,7 +821,7 @@ template<> struct ToString { template<> struct ToString { using Argument = String; using Result = String; - String operator()(const Argument &s) { + String operator()(Argument const &s) { return s; } }; @@ -829,7 +829,7 @@ template<> struct ToString { template<> struct ToString { using Argument = CharRange; using Result = String; - String operator()(const Argument &s) { + String operator()(Argument const &s) { return String(s); } }; @@ -837,7 +837,7 @@ template<> struct ToString { template<> struct ToString { using Argument = ConstCharRange; using Result = String; - String operator()(const Argument &s) { + String operator()(Argument const &s) { return String(s); } }; @@ -845,7 +845,7 @@ template<> struct ToString { template struct ToString> { using Argument = Pair; using Result = String; - String operator()(const Argument &v) { + String operator()(Argument const &v) { String ret("{"); ret += ToString>>()(v.first); ret += ", "; @@ -859,7 +859,7 @@ namespace detail { template struct TupleToString { template - static void append(String &ret, const T &tup) { + static void append(String &ret, T const &tup) { ret += ", "; ret += ToString(tup))>>>()(ostd::get(tup)); @@ -870,13 +870,13 @@ namespace detail { template struct TupleToString { template - static void append(String &, const T &) {} + static void append(String &, T const &) {} }; template struct TupleToString<0, N> { template - static void append(String &ret, const T &tup) { + static void append(String &ret, T const &tup) { ret += ToString(tup))>>>()(ostd::get<0>(tup)); TupleToString<1, N>::append(ret, tup); @@ -887,7 +887,7 @@ namespace detail { template struct ToString> { using Argument = Tuple; using Result = String; - String operator()(const Argument &v) { + String operator()(Argument const &v) { String ret("{"); detail::TupleToString<0, sizeof...(T)>::append(ret, v); ret += "}"; @@ -896,7 +896,7 @@ template struct ToString> { }; template -typename ToString::Result to_string(const T &v) { +typename ToString::Result to_string(T const &v) { return ToString>>()(v); } @@ -907,19 +907,19 @@ String to_string(std::initializer_list init) { /* TODO: rvalue ref versions for rhs when we have efficient prepend */ -inline String operator+(const String &lhs, ConstCharRange rhs) { +inline String operator+(String const &lhs, ConstCharRange rhs) { String ret(lhs); ret += rhs; return ret; } -inline String operator+(ConstCharRange lhs, const String &rhs) { +inline String operator+(ConstCharRange lhs, String const &rhs) { String ret(lhs); ret += rhs; return ret; } -inline String operator+(const String &lhs, char rhs) { +inline String operator+(String const &lhs, char rhs) { String ret(lhs); ret += rhs; return ret; } -inline String operator+(char lhs, const String &rhs) { +inline String operator+(char lhs, String const &rhs) { String ret(lhs); ret += rhs; return ret; } @@ -939,7 +939,7 @@ private: public: TempCString() = delete; - TempCString(const TempCString &) = delete; + TempCString(TempCString const &) = delete; TempCString(TempCString &&s): p_buf(s.p_buf), p_allocated(s.p_allocated) { s.p_buf = nullptr; s.p_allocated = false; @@ -957,14 +957,14 @@ public: if (p_allocated) delete[] p_buf; } - TempCString &operator=(const TempCString &) = delete; + TempCString &operator=(TempCString const &) = delete; TempCString &operator=(TempCString &&s) { swap(s); return *this; } - operator const RemoveCv> *() const { return p_buf; } - const RemoveCv> *get() const { return p_buf; } + operator RemoveCv> const *() const { return p_buf; } + RemoveCv> const *get() const { return p_buf; } void swap(TempCString &s) { detail::swap_adl(p_buf, s.p_buf); diff --git a/ostd/tuple.hh b/ostd/tuple.hh index 1146946..f300496 100644 --- a/ostd/tuple.hh +++ b/ostd/tuple.hh @@ -37,17 +37,17 @@ namespace detail { } template - TupleLeaf(Constant, const A &): p_value() { + TupleLeaf(Constant, A const &): p_value() { static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } template - TupleLeaf(Constant, const A &a): p_value(allocator_arg, a) { + TupleLeaf(Constant, A const &a): p_value(allocator_arg, a) { static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } template - TupleLeaf(Constant, const A &a): p_value(a) { + TupleLeaf(Constant, A const &a): p_value(a) { static_assert(!IsReference, "attempt to default construct a reference element in a tuple"); } @@ -67,7 +67,7 @@ namespace detail { } template - explicit TupleLeaf(Constant, const A &, T &&t): + explicit TupleLeaf(Constant, A const &, T &&t): p_value(forward(t)) { static_assert(!IsLvalueReference || (IsLvalueReference && @@ -78,7 +78,7 @@ namespace detail { } template - explicit TupleLeaf(Constant, const A &a, T &&t): + explicit TupleLeaf(Constant, A const &a, T &&t): p_value(allocator_arg, a, forward(t)) { static_assert(!IsLvalueReference || (IsLvalueReference && @@ -89,7 +89,7 @@ namespace detail { } template - explicit TupleLeaf(Constant, const A &a, T &&t): + explicit TupleLeaf(Constant, A const &a, T &&t): p_value(forward(t), a) { static_assert(!IsLvalueReference || (IsLvalueReference && @@ -99,7 +99,7 @@ namespace detail { "attempt to construct a reference element in a tuple with an rvalue"); } - TupleLeaf(const TupleLeaf &) = default; + TupleLeaf(TupleLeaf const &) = default; TupleLeaf(TupleLeaf &&) = default; template @@ -113,10 +113,10 @@ namespace detail { } H &get() { return p_value; } - const H &get() const { return p_value; } + H const &get() const { return p_value; } private: - TupleLeaf &operator=(const TupleLeaf &); + TupleLeaf &operator=(TupleLeaf const &); H p_value; }; @@ -125,32 +125,32 @@ namespace detail { constexpr TupleLeaf() {} template - TupleLeaf(Constant, const A &) {} + TupleLeaf(Constant, A const &) {} template - TupleLeaf(Constant, const A &a): + TupleLeaf(Constant, A const &a): H(allocator_arg, a) {} template - TupleLeaf(Constant, const A &a): H(a) {} + TupleLeaf(Constant, A const &a): H(a) {} template, TupleLeaf> && IsConstructible >> explicit TupleLeaf(T &&t): H(forward(t)) {} template - explicit TupleLeaf(Constant, const A &, T &&t): + explicit TupleLeaf(Constant, A const &, T &&t): H(forward(t)) {} template - explicit TupleLeaf(Constant, const A &a, T &&t): + explicit TupleLeaf(Constant, A const &a, T &&t): H(allocator_arg, a, forward(t)) {} template - explicit TupleLeaf(Constant, const A &a, T &&t): + explicit TupleLeaf(Constant, A const &a, T &&t): H(forward(t), a) {} - TupleLeaf(const TupleLeaf &) = default; + TupleLeaf(TupleLeaf const &) = default; TupleLeaf(TupleLeaf &&) = default; template @@ -164,10 +164,10 @@ namespace detail { } H &get() { return (H &)*this; } - const H &get() const { return (const H &)*this; } + H const &get() const { return (H const &)*this; } private: - TupleLeaf &operator=(const TupleLeaf &); + TupleLeaf &operator=(TupleLeaf const &); }; } /* namespace detail */ @@ -210,7 +210,7 @@ namespace detail { template - explicit TupleBase(AllocatorArg, const Alloc &a, + explicit TupleBase(AllocatorArg, Alloc const &a, TupleIndices, TupleTypes, TupleIndices, TupleTypes, T &&...t): @@ -227,7 +227,7 @@ namespace detail { template> - >> TupleBase(AllocatorArg, const Alloc &a, T &&t): + >> TupleBase(AllocatorArg, Alloc const &a, T &&t): TupleLeaf(UsesAllocatorConstructor< A, Alloc, TupleElement> >, a, forward>>(get(t)))... @@ -242,18 +242,18 @@ namespace detail { return *this; } - TupleBase(const TupleBase &) = default; + TupleBase(TupleBase const &) = default; TupleBase(TupleBase &&) = default; - TupleBase &operator=(const TupleBase &t) { - tuple_swallow(TupleLeaf::operator=(((const TupleLeaf &)t).get())...); + TupleBase &operator=(TupleBase const &t) { + tuple_swallow(TupleLeaf::operator=(((TupleLeaf + const &)t).get())...); return *this; } TupleBase &operator=(TupleBase &&t) { tuple_swallow(TupleLeaf::operator=(forward - (((const TupleLeaf &)t).get()))...); + (((TupleLeaf const &)t).get()))...); return *this; } @@ -272,27 +272,27 @@ class Tuple { friend TupleElement> &get(Tuple &); template - friend const TupleElement> &get(const Tuple &); + friend TupleElement> const &get(Tuple const &); template friend TupleElement> &&get(Tuple &&); template - friend const TupleElement> &&get(const Tuple &&); + friend TupleElement> const &&get(Tuple const &&); public: template)...> >> Tuple() {} - explicit Tuple(const A &...t): + explicit Tuple(A const &...t): p_base(detail::MakeTupleIndices(), detail::MakeTupleTypes(), detail::MakeTupleIndices<0>(), detail::MakeTupleTypes(), t...) {} template - Tuple(AllocatorArg, const Alloc &a, const A &...t): + Tuple(AllocatorArg, Alloc const &a, A const &...t): p_base(allocator_arg, a, detail::MakeTupleIndices(), detail::MakeTupleTypes(), @@ -367,7 +367,7 @@ public: : sizeof...(A) > > - >> Tuple(AllocatorArg, const Alloc &a, T &&...t): + >> Tuple(AllocatorArg, Alloc const &a, T &&...t): p_base(allocator_arg, a, detail::MakeTupleIndices(), detail::MakeTupleTypes(), detail::MakeTupleIndices(), @@ -385,7 +385,7 @@ public: template - >> Tuple(AllocatorArg, const Alloc &a, T &&t): + >> Tuple(AllocatorArg, Alloc const &a, T &&t): p_base(allocator_arg, a, forward(t)) {} template>> @@ -402,8 +402,8 @@ public: template<> class Tuple<> { public: constexpr Tuple() {} - template Tuple(AllocatorArg, const A &) {} - template Tuple(AllocatorArg, const A &, const Tuple &) {} + template Tuple(AllocatorArg, A const &) {} + template Tuple(AllocatorArg, A const &, Tuple const &) {} void swap(Tuple &) {} }; @@ -416,9 +416,9 @@ inline TupleElement> &get(Tuple &t) { } template -inline const TupleElement> &get(const Tuple &t) { +inline TupleElement> const &get(Tuple const &t) { using Type = TupleElement>; - return ((const detail::TupleLeaf &)t.p_base).get(); + return ((detail::TupleLeaf const &)t.p_base).get(); } template @@ -428,9 +428,9 @@ inline TupleElement> &&get(Tuple &&t) { } template -inline const TupleElement> &&get(const Tuple &&t) { +inline TupleElement> const &&get(Tuple const &&t) { using Type = TupleElement>; - return (const Type &&)(((const detail::TupleLeaf &&)t.p_base).get()); + return (Type const &&)(((detail::TupleLeaf const &&)t.p_base).get()); } /* tie */ @@ -445,11 +445,11 @@ inline Tuple tie(T &...t) { namespace detail { struct Ignore { template - const Ignore &operator=(T &&) const { return *this; } + Ignore const &operator=(T &&) const { return *this; } }; } -static const detail::Ignore ignore = detail::Ignore(); +static detail::Ignore const ignore = detail::Ignore(); /* make tuple */ @@ -489,7 +489,7 @@ namespace detail { template struct TupleEqual { template - bool operator()(const T &x, const U &y) { + bool operator()(T const &x, U const &y) { return TupleEqual()(x, y) && (get(x) == get(y)); } }; @@ -497,19 +497,19 @@ namespace detail { template<> struct TupleEqual<0> { template - bool operator()(const T &, const U &) { + bool operator()(T const &, U const &) { return true; } }; } template -inline bool operator==(const Tuple &x, const Tuple &y) { +inline bool operator==(Tuple const &x, Tuple const &y) { return detail::TupleEqual(x, y); } template -inline bool operator!=(const Tuple &x, const Tuple &y) { +inline bool operator!=(Tuple const &x, Tuple const &y) { return !(x == y); } @@ -517,7 +517,7 @@ namespace detail { template struct TupleLess { template - bool operator()(const T &x, const U &y) { + bool operator()(T const &x, U const &y) { constexpr Size J = TupleSize - I; if (get(x) < get(y)) return true; if (get(y) < get(x)) return false; @@ -528,29 +528,29 @@ namespace detail { template<> struct TupleLess<0> { template - bool operator()(const T &, const U &) { + bool operator()(T const &, U const &) { return true; } }; } template -inline bool operator<(const Tuple &x, const Tuple &y) { +inline bool operator<(Tuple const &x, Tuple const &y) { return detail::TupleLess(x, y); } template -inline bool operator>(const Tuple &x, const Tuple &y) { +inline bool operator>(Tuple const &x, Tuple const &y) { return y < x; } template -inline bool operator<=(const Tuple &x, const Tuple &y) { +inline bool operator<=(Tuple const &x, Tuple const &y) { return !(y < x); } template -inline bool operator>=(const Tuple &x, const Tuple &y) { +inline bool operator>=(Tuple const &x, Tuple const &y) { return !(x < y); } diff --git a/ostd/type_traits.hh b/ostd/type_traits.hh index 49aaecb..47403f4 100644 --- a/ostd/type_traits.hh +++ b/ostd/type_traits.hh @@ -261,12 +261,12 @@ template constexpr bool IsAbstract = __is_abstract(T); /* is const */ template -constexpr bool IsConst = IsSame; +constexpr bool IsConst = IsSame; /* is volatile */ template -constexpr bool IsVolatile = IsSame; +constexpr bool IsVolatile = IsSame; /* is empty */ @@ -473,7 +473,7 @@ constexpr bool IsCopyAssignable = IsAssignable< template constexpr bool IsMoveAssignable = IsAssignable< AddLvalueReference, - const AddRvalueReference + AddRvalueReference const >; /* is destructible */ @@ -532,7 +532,7 @@ namespace detail { = __has_trivial_copy(T); template - constexpr bool IsTriviallyConstructibleBase + constexpr bool IsTriviallyConstructibleBase = __has_trivial_copy(T); template @@ -552,7 +552,7 @@ template constexpr bool IsTriviallyDefaultConstructible /* is trivially copy constructible */ template constexpr bool IsTriviallyCopyConstructible - = IsTriviallyConstructible>; + = IsTriviallyConstructible>; /* is trivially move constructible */ @@ -574,7 +574,7 @@ namespace detail { = __has_trivial_copy(T); template - constexpr bool IsTriviallyAssignableBase + constexpr bool IsTriviallyAssignableBase = __has_trivial_copy(T); template @@ -589,7 +589,7 @@ constexpr bool IsTriviallyAssignable /* is trivially copy assignable */ template constexpr bool IsTriviallyCopyAssignable - = IsTriviallyAssignable>; + = IsTriviallyAssignable>; /* is trivially move assignable */ @@ -673,12 +673,12 @@ namespace detail { template struct RemoveConstBase { using Type = T; }; template - struct RemoveConstBase { using Type = T; }; + struct RemoveConstBase { using Type = T; }; template struct RemoveVolatileBase { using Type = T; }; template - struct RemoveVolatileBase { using Type = T; }; + struct RemoveVolatileBase { using Type = T; }; } template @@ -700,7 +700,7 @@ namespace detail { struct AddConstCore { using Type = T; }; template struct AddConstCore { - using Type = const T; + using Type = T const; }; template struct AddConstBase { @@ -711,7 +711,7 @@ namespace detail { struct AddVolatileCore { using Type = T; }; template struct AddVolatileCore { - using Type = volatile T; + using Type = T volatile; }; template struct AddVolatileBase { @@ -780,14 +780,14 @@ namespace detail { template<> struct AddLr { using Type = void; }; - template<> struct AddLr { - using Type = const void; + template<> struct AddLr { + using Type = void const; }; - template<> struct AddLr { - using Type = volatile void; + template<> struct AddLr { + using Type = void volatile; }; - template<> struct AddLr { - using Type = const volatile void; + template<> struct AddLr { + using Type = void const volatile; }; } @@ -798,14 +798,14 @@ namespace detail { template<> struct AddRr { using Type = void; }; - template<> struct AddRr { - using Type = const void; + template<> struct AddRr { + using Type = void const; }; - template<> struct AddRr { - using Type = volatile void; + template<> struct AddRr { + using Type = void volatile; }; - template<> struct AddRr { - using Type = const volatile void; + template<> struct AddRr { + using Type = void const volatile; }; } @@ -852,8 +852,8 @@ namespace detail { /* not a type */ struct TlNat { TlNat() = delete; - TlNat(const TlNat &) = delete; - TlNat &operator=(const TlNat &) = delete; + TlNat(TlNat const &) = delete; + TlNat &operator=(TlNat const &) = delete; ~TlNat() = delete; }; @@ -891,32 +891,32 @@ namespace detail { template struct ApplyCv { /* const */ - using Type = const U; + using Type = U const; }; template struct ApplyCv { /* volatile */ - using Type = volatile U; + using Type = U volatile; }; template struct ApplyCv { /* const volatile */ - using Type = const volatile U; + using Type = U const volatile; }; template struct ApplyCv { /* const */ - using Type = const U &; + using Type = U const &; }; template struct ApplyCv { /* volatile */ - using Type = volatile U &; + using Type = U volatile &; }; template struct ApplyCv { /* const volatile */ - using Type = const volatile U &; + using Type = U const volatile &; }; template || IsEnum> diff --git a/ostd/utility.hh b/ostd/utility.hh index facf292..a46f6a9 100644 --- a/ostd/utility.hh +++ b/ostd/utility.hh @@ -96,30 +96,30 @@ struct Pair { Pair() = default; ~Pair() = default; - Pair(const Pair &) = default; + Pair(Pair const &) = default; Pair(Pair &&) = default; - Pair(const T &x, const U &y): first(x), second(y) {} + Pair(T const &x, U const &y): first(x), second(y) {} template Pair(TT &&x, UU &&y): first(forward(x)), second(forward(y)) {} template - Pair(const Pair &v): first(v.first), second(v.second) {} + Pair(Pair const &v): first(v.first), second(v.second) {} template Pair(Pair &&v): first(move(v.first)), second(move(v.second)) {} - Pair &operator=(const Pair &v) { + Pair &operator=(Pair const &v) { first = v.first; second = v.second; return *this; } template - Pair &operator=(const Pair &v) { + Pair &operator=(Pair const &v) { first = v.first; second = v.second; return *this; @@ -173,17 +173,17 @@ inline Pair::Type, } template -inline constexpr bool operator==(const Pair &x, const Pair &y) { +inline constexpr bool operator==(Pair const &x, Pair const &y) { return (x.first == y.first) && (x.second == y.second); } template -inline constexpr bool operator!=(const Pair &x, const Pair &y) { +inline constexpr bool operator!=(Pair const &x, Pair const &y) { return (x.first != y.first) || (x.second != y.second); } template -inline constexpr bool operator<(const Pair &x, const Pair &y) { +inline constexpr bool operator<(Pair const &x, Pair const &y) { return (x.first < y.first) ? true : ((y.first < x.first) @@ -194,17 +194,17 @@ inline constexpr bool operator<(const Pair &x, const Pair &y) { } template -inline constexpr bool operator>(const Pair &x, const Pair &y) { +inline constexpr bool operator>(Pair const &x, Pair const &y) { return (y < x); } template -inline constexpr bool operator<=(const Pair &x, const Pair &y) { +inline constexpr bool operator<=(Pair const &x, Pair const &y) { return !(y < x); } template -inline constexpr bool operator>=(const Pair &x, const Pair &y) { +inline constexpr bool operator>=(Pair const &x, Pair const &y) { return !(x < y); } @@ -228,12 +228,12 @@ namespace detail { template static T &get(Pair &p) { return p.first; } template - static const T &get(const Pair &p) { return p.first; } + static T const &get(Pair const &p) { return p.first; } template static T &&get(Pair &&p) { return forward(p.first); } template - static const T &&get(const Pair &&p) { - return forward(p.first); + static T const &&get(Pair const &&p) { + return forward(p.first); } }; @@ -241,12 +241,12 @@ namespace detail { template static U &get(Pair &p) { return p.second; } template - static const U &get(const Pair &p) { return p.second; } + static U const &get(Pair const &p) { return p.second; } template static U &&get(Pair &&p) { return forward(p.second); } template - static const T &&get(const Pair &&p) { - return forward(p.second); + static T const &&get(Pair const &&p) { + return forward(p.second); } }; } @@ -257,7 +257,7 @@ inline TupleElement> &get(Pair &p) { } template -inline const TupleElement> &get(const Pair &p) { +inline TupleElement> const &get(Pair const &p) { return detail::GetPair::get(p); } @@ -267,7 +267,7 @@ inline TupleElement> &&get(Pair &&p) { } template -inline const TupleElement> &&get(const Pair &&p) { +inline TupleElement> const &&get(Pair const &&p) { return detail::GetPair::get(move(p)); } @@ -310,10 +310,10 @@ namespace detail { p_second(forward(b)) {} T &first() { return p_first; } - const T &first() const { return p_first; } + T const &first() const { return p_first; } U &second() { return p_second; } - const U &second() const { return p_second; } + U const &second() const { return p_second; } void swap(CompressedPairBase &v) { swap_adl(p_first, v.p_first); @@ -330,10 +330,10 @@ namespace detail { p_second(forward(b)) {} T &first() { return *this; } - const T &first() const { return *this; } + T const &first() const { return *this; } U &second() { return p_second; } - const U &second() const { return p_second; } + U const &second() const { return p_second; } void swap(CompressedPairBase &v) { swap_adl(p_second, v.p_second); @@ -349,10 +349,10 @@ namespace detail { p_first(forward(a)) {} T &first() { return p_first; } - const T &first() const { return p_first; } + T const &first() const { return p_first; } U &second() { return *this; } - const U &second() const { return *this; } + U const &second() const { return *this; } void swap(CompressedPairBase &v) { swap_adl(p_first, v.p_first); @@ -366,10 +366,10 @@ namespace detail { U(forward(b)) {} T &first() { return *this; } - const T &first() const { return *this; } + T const &first() const { return *this; } U &second() { return *this; } - const U &second() const { return *this; } + U const &second() const { return *this; } void swap(CompressedPairBase &) {} }; @@ -383,10 +383,10 @@ namespace detail { forward(b)) {} T &first() { return Base::first(); } - const T &first() const { return Base::first(); } + T const &first() const { return Base::first(); } U &second() { return Base::second(); } - const U &second() const { return Base::second(); } + U const &second() const { return Base::second(); } void swap(CompressedPair &v) { Base::swap(v); diff --git a/ostd/vecmath.hh b/ostd/vecmath.hh index 8ae341d..e135371 100644 --- a/ostd/vecmath.hh +++ b/ostd/vecmath.hh @@ -18,7 +18,7 @@ struct Vec2 { }; Vec2(): x(0), y(0) {} - Vec2(const Vec2 &v): x(v.x), y(v.y) {} + Vec2(Vec2 const &v): x(v.x), y(v.y) {} Vec2(T v): x(v), y(v) {} Vec2(T x, T y): x(x), y(y) {} @@ -29,7 +29,7 @@ struct Vec2 { x += v; y += v; return *this; } - Vec2 &add(const Vec2 &o) { + Vec2 &add(Vec2 const &o) { x += o.x; y += o.y; return *this; } @@ -38,7 +38,7 @@ struct Vec2 { x -= v; y -= v; return *this; } - Vec2 &sub(const Vec2 &o) { + Vec2 &sub(Vec2 const &o) { x -= o.x; y -= o.y; return *this; } @@ -47,7 +47,7 @@ struct Vec2 { x *= v; y *= v; return *this; } - Vec2 &mul(const Vec2 &o) { + Vec2 &mul(Vec2 const &o) { x *= o.x; y *= o.y; return *this; } @@ -56,7 +56,7 @@ struct Vec2 { x /= v; y /= v; return *this; } - Vec2 &div(const Vec2 &o) { + Vec2 &div(Vec2 const &o) { x /= o.x; y /= o.y; return *this; } @@ -70,63 +70,63 @@ struct Vec2 { return (x == 0) && (y == 0); } - T dot(const Vec2 &o) const { + T dot(Vec2 const &o) const { return (x * o.x) + (y * o.y); } }; template -inline bool operator==(const Vec2 &a, const Vec2 &b) { +inline bool operator==(Vec2 const &a, Vec2 const &b) { return (a.x == b.x) && (a.y == b.y); } template -inline bool operator!=(const Vec2 &a, const Vec2 &b) { +inline bool operator!=(Vec2 const &a, Vec2 const &b) { return (a.x != b.x) || (a.y != b.y); } template -inline Vec2 operator+(const Vec2 &a, const Vec2 &b) { +inline Vec2 operator+(Vec2 const &a, Vec2 const &b) { return Vec2(a).add(b); } template -inline Vec2 operator+(const Vec2 &a, T b) { +inline Vec2 operator+(Vec2 const &a, T b) { return Vec2(a).add(b); } template -inline Vec2 operator-(const Vec2 &a, const Vec2 &b) { +inline Vec2 operator-(Vec2 const &a, Vec2 const &b) { return Vec2(a).sub(b); } template -inline Vec2 operator-(const Vec2 &a, T b) { +inline Vec2 operator-(Vec2 const &a, T b) { return Vec2(a).sub(b); } template -inline Vec2 operator*(const Vec2 &a, const Vec2 &b) { +inline Vec2 operator*(Vec2 const &a, Vec2 const &b) { return Vec2(a).mul(b); } template -inline Vec2 operator*(const Vec2 &a, T b) { +inline Vec2 operator*(Vec2 const &a, T b) { return Vec2(a).mul(b); } template -inline Vec2 operator/(const Vec2 &a, const Vec2 &b) { +inline Vec2 operator/(Vec2 const &a, Vec2 const &b) { return Vec2(a).div(b); } template -inline Vec2 operator/(const Vec2 &a, T b) { +inline Vec2 operator/(Vec2 const &a, T b) { return Vec2(a).div(b); } template -inline Vec2 operator-(const Vec2 &a) { +inline Vec2 operator-(Vec2 const &a) { return Vec2(a).neg(); } @@ -144,7 +144,7 @@ struct Vec3 { }; Vec3(): x(0), y(0), z(0) {} - Vec3(const Vec3 &v): x(v.x), y(v.y), z(v.z) {} + Vec3(Vec3 const &v): x(v.x), y(v.y), z(v.z) {} Vec3(T v): x(v), y(v), z(v) {} Vec3(T x, T y, T z): x(x), y(y), z(z) {} @@ -155,7 +155,7 @@ struct Vec3 { x += v; y += v; z += v; return *this; } - Vec3 &add(const Vec3 &o) { + Vec3 &add(Vec3 const &o) { x += o.x; y += o.y; z += o.z; return *this; } @@ -164,7 +164,7 @@ struct Vec3 { x -= v; y -= v; z -= v; return *this; } - Vec3 &sub(const Vec3 &o) { + Vec3 &sub(Vec3 const &o) { x -= o.x; y -= o.y; z -= o.z; return *this; } @@ -173,7 +173,7 @@ struct Vec3 { x *= v; y *= v; z *= v; return *this; } - Vec3 &mul(const Vec3 &o) { + Vec3 &mul(Vec3 const &o) { x *= o.x; y *= o.y; z *= o.z; return *this; } @@ -182,7 +182,7 @@ struct Vec3 { x /= v; y /= v; z /= v; return *this; } - Vec3 &div(const Vec3 &o) { + Vec3 &div(Vec3 const &o) { x /= o.x; y /= o.y; z /= o.z; return *this; } @@ -196,63 +196,63 @@ struct Vec3 { return (x == 0) && (y == 0) && (z == 0); } - T dot(const Vec3 &o) const { + T dot(Vec3 const &o) const { return (x * o.x) + (y * o.y) + (z * o.z); } }; template -inline bool operator==(const Vec3 &a, const Vec3 &b) { +inline bool operator==(Vec3 const &a, Vec3 const &b) { return (a.x == b.x) && (a.y == b.y) && (a.z == b.z); } template -inline bool operator!=(const Vec3 &a, const Vec3 &b) { +inline bool operator!=(Vec3 const &a, Vec3 const &b) { return (a.x != b.x) || (a.y != b.y) || (a.z != b.z); } template -inline Vec3 operator+(const Vec3 &a, const Vec3 &b) { +inline Vec3 operator+(Vec3 const &a, Vec3 const &b) { return Vec3(a).add(b); } template -inline Vec3 operator+(const Vec3 &a, T b) { +inline Vec3 operator+(Vec3 const &a, T b) { return Vec3(a).add(b); } template -inline Vec3 operator-(const Vec3 &a, const Vec3 &b) { +inline Vec3 operator-(Vec3 const &a, Vec3 const &b) { return Vec3(a).sub(b); } template -inline Vec3 operator-(const Vec3 &a, T b) { +inline Vec3 operator-(Vec3 const &a, T b) { return Vec3(a).sub(b); } template -inline Vec3 operator*(const Vec3 &a, const Vec3 &b) { +inline Vec3 operator*(Vec3 const &a, Vec3 const &b) { return Vec3(a).mul(b); } template -inline Vec3 operator*(const Vec3 &a, T b) { +inline Vec3 operator*(Vec3 const &a, T b) { return Vec3(a).mul(b); } template -inline Vec3 operator/(const Vec3 &a, const Vec3 &b) { +inline Vec3 operator/(Vec3 const &a, Vec3 const &b) { return Vec3(a).div(b); } template -inline Vec3 operator/(const Vec3 &a, T b) { +inline Vec3 operator/(Vec3 const &a, T b) { return Vec3(a).div(b); } template -inline Vec3 operator-(const Vec3 &a) { +inline Vec3 operator-(Vec3 const &a) { return Vec3(a).neg(); } @@ -270,7 +270,7 @@ struct Vec4 { }; Vec4(): x(0), y(0), z(0), w(0) {} - Vec4(const Vec4 &v): x(v.x), y(v.y), z(v.z), w(v.w) {} + Vec4(Vec4 const &v): x(v.x), y(v.y), z(v.z), w(v.w) {} 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) {} @@ -281,7 +281,7 @@ struct Vec4 { x += v; y += v; z += v; w += v; return *this; } - Vec4 &add(const Vec4 &o) { + Vec4 &add(Vec4 const &o) { x += o.x; y += o.y; z += o.z; w += o.w; return *this; } @@ -290,7 +290,7 @@ struct Vec4 { x -= v; y -= v; z -= v; w -= v; return *this; } - Vec4 &sub(const Vec4 &o) { + Vec4 &sub(Vec4 const &o) { x -= o.x; y -= o.y; z -= o.z; w -= o.w; return *this; } @@ -299,7 +299,7 @@ struct Vec4 { x *= v; y *= v; z *= v; w *= v; return *this; } - Vec4 &mul(const Vec4 &o) { + Vec4 &mul(Vec4 const &o) { x *= o.x; y *= o.y; z *= o.z; w *= o.w; return *this; } @@ -308,7 +308,7 @@ struct Vec4 { x /= v; y /= v; z /= v; w /= v; return *this; } - Vec4 &div(const Vec4 &o) { + Vec4 &div(Vec4 const &o) { x /= o.x; y /= o.y; z /= o.z; w /= o.w; return *this; } @@ -322,63 +322,63 @@ struct Vec4 { return (x == 0) && (y == 0) && (z == 0) && (w == 0); } - T dot(const Vec4 &o) const { + T dot(Vec4 const &o) const { return (x * o.x) + (y * o.y) + (z * o.z) + (w * o.w); } }; template -inline bool operator==(const Vec4 &a, const Vec4 &b) { +inline bool operator==(Vec4 const &a, Vec4 const &b) { return (a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w); } template -inline bool operator!=(const Vec4 &a, const Vec4 &b) { +inline bool operator!=(Vec4 const &a, Vec4 const &b) { return (a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w); } template -inline Vec4 operator+(const Vec4 &a, const Vec4 &b) { +inline Vec4 operator+(Vec4 const &a, Vec4 const &b) { return Vec4(a).add(b); } template -inline Vec4 operator+(const Vec4 &a, T b) { +inline Vec4 operator+(Vec4 const &a, T b) { return Vec4(a).add(b); } template -inline Vec4 operator-(const Vec4 &a, const Vec4 &b) { +inline Vec4 operator-(Vec4 const &a, Vec4 const &b) { return Vec4(a).sub(b); } template -inline Vec4 operator-(const Vec4 &a, T b) { +inline Vec4 operator-(Vec4 const &a, T b) { return Vec4(a).sub(b); } template -inline Vec4 operator*(const Vec4 &a, const Vec4 &b) { +inline Vec4 operator*(Vec4 const &a, Vec4 const &b) { return Vec4(a).mul(b); } template -inline Vec4 operator*(const Vec4 &a, T b) { +inline Vec4 operator*(Vec4 const &a, T b) { return Vec4(a).mul(b); } template -inline Vec4 operator/(const Vec4 &a, const Vec4 &b) { +inline Vec4 operator/(Vec4 const &a, Vec4 const &b) { return Vec4(a).div(b); } template -inline Vec4 operator/(const Vec4 &a, T b) { +inline Vec4 operator/(Vec4 const &a, T b) { return Vec4(a).div(b); } template -inline Vec4 operator-(const Vec4 &a) { +inline Vec4 operator-(Vec4 const &a) { return Vec4(a).neg(); } diff --git a/ostd/vector.hh b/ostd/vector.hh index 05be648..3458814 100644 --- a/ostd/vector.hh +++ b/ostd/vector.hh @@ -59,7 +59,7 @@ class Vector { } } - void copy_contents(const Vector &v) { + void copy_contents(Vector const &v) { if (IsPod) { memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); } else { @@ -76,17 +76,16 @@ public: using Difference = Ptrdiff; using Value = T; using Reference = T &; - using ConstReference = const T &; + using ConstReference = T const &; using Pointer = AllocatorPointer; using ConstPointer = AllocatorConstPointer; using Range = PointerRange; - using ConstRange = PointerRange; + using ConstRange = PointerRange; using Allocator = A; - Vector(const A &a = A()): p_len(0), p_cap(0), p_buf(nullptr, a) {} + Vector(A const &a = A()): p_len(0), p_cap(0), p_buf(nullptr, a) {} - explicit Vector(Size n, const T &val = T(), - const A &al = A()): Vector(al) { + 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; @@ -95,14 +94,14 @@ public: allocator_construct(p_buf.second(), cur++, val); } - Vector(const Vector &v): p_len(0), p_cap(0), p_buf(nullptr, + 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(const Vector &v, const A &a): p_len(0), p_cap(0), p_buf(nullptr, a) { + 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); @@ -114,7 +113,7 @@ public: v.p_len = v.p_cap = 0; } - Vector(Vector &&v, const A &a): p_len(0), p_cap(0), p_buf(nullptr, a) { + 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; @@ -136,7 +135,7 @@ public: v.p_len = v.p_cap = 0; } - Vector(ConstRange r, const A &a = A()): Vector(a) { + Vector(ConstRange r, A const &a = A()): Vector(a) { reserve(r.size()); if (IsPod) { memcpy(p_buf.first(), &r[0], r.size() * sizeof(T)); @@ -147,12 +146,12 @@ public: p_len = r.size(); } - Vector(InitializerList v, const A &a = A()): + Vector(InitializerList v, A const &a = A()): Vector(ConstRange(v.begin(), v.size()), a) {} template && IsConvertible, Value> - >> Vector(R range, const A &a = A()): Vector(a) { + >> Vector(R range, A const &a = A()): Vector(a) { ctor_from_range(range); } @@ -170,7 +169,7 @@ public: p_len = 0; } - Vector &operator=(const Vector &v) { + Vector &operator=(Vector const &v) { if (this == &v) return *this; clear(); if (AllocatorPropagateOnContainerCopyAssignment) { @@ -225,7 +224,7 @@ public: return *this; } - void resize(Size n, const T &v = T()) { + void resize(Size n, T const &v = T()) { if (!n) { clear(); return; @@ -272,18 +271,18 @@ public: } T &operator[](Size i) { return p_buf.first()[i]; } - const T &operator[](Size i) const { 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]; } - const T *at(Size i) const { + T const *at(Size i) const { if (!in_range(i)) return nullptr; return &p_buf.first()[i]; } - T &push(const T &v) { + 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++]; @@ -301,7 +300,7 @@ public: return p_buf.first()[p_len++]; } - Range push_n(const T *v, Size n) { + Range push_n(T const *v, Size n) { reserve(p_len + n); if (IsPod) { memcpy(p_buf.first() + p_len, v, n * sizeof(T)); @@ -331,13 +330,13 @@ public: } T &front() { return p_buf.first()[0]; } - const T &front() const { return p_buf.first()[0]; } + T const &front() const { return p_buf.first()[0]; } T &back() { return p_buf.first()[p_len - 1]; } - const T &back() const { return p_buf.first()[p_len - 1]; } + T const &back() const { return p_buf.first()[p_len - 1]; } Value *data() { return (Value *)p_buf.first(); } - const Value *data() const { return (const Value *)p_buf.first(); } + Value const *data() const { return (Value const *)p_buf.first(); } Size size() const { return p_len; } Size capacity() const { return p_cap; } @@ -350,7 +349,7 @@ public: bool in_range(Size idx) { return idx < p_len; } bool in_range(int idx) { return idx >= 0 && Size(idx) < p_len; } - bool in_range(const Value *ptr) { + bool in_range(Value const *ptr) { return ptr >= p_buf.first() && ptr < &p_buf.first()[p_len]; } @@ -367,13 +366,13 @@ public: return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); } - Range insert(Size idx, const T &v) { + 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, const T &v) { + 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; @@ -424,17 +423,17 @@ public: }; template -inline bool operator==(const Vector &x, const Vector &y) { +inline bool operator==(Vector const &x, Vector const &y) { return equal(x.iter(), y.iter()); } template -inline bool operator!=(const Vector &x, const Vector &y) { +inline bool operator!=(Vector const &x, Vector const &y) { return !(x == y); } template -inline bool operator<(const Vector &x, const Vector &y) { +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()) { @@ -447,17 +446,17 @@ inline bool operator<(const Vector &x, const Vector &y) { } template -inline bool operator>(const Vector &x, const Vector &y) { +inline bool operator>(Vector const &x, Vector const &y) { return (y < x); } template -inline bool operator<=(const Vector &x, const Vector &y) { +inline bool operator<=(Vector const &x, Vector const &y) { return !(y < x); } template -inline bool operator>=(const Vector &x, const Vector &y) { +inline bool operator>=(Vector const &x, Vector const &y) { return !(x < y); }