diff --git a/octa/algorithm.hh b/octa/algorithm.hh index cd74410..b436f1f 100644 --- a/octa/algorithm.hh +++ b/octa/algorithm.hh @@ -42,25 +42,25 @@ bool is_partitioned(R range, P pred) { namespace detail { template void insort(R range, C compare) { - octa::RangeSize rlen = range.size(); - for (octa::RangeSize i = 1; i < rlen; ++i) { - octa::RangeSize j = i; - octa::RangeValue v(octa::move(range[i])); + RangeSize rlen = range.size(); + for (RangeSize i = 1; i < rlen; ++i) { + RangeSize j = i; + RangeValue v(move(range[i])); while (j > 0 && !compare(range[j - 1], v)) { range[j] = range[j - 1]; --j; } - range[j] = octa::move(v); + range[j] = move(v); } } template - void hs_sift_down(R range, octa::RangeSize s, - octa::RangeSize e, C compare) { - octa::RangeSize r = s; + void hs_sift_down(R range, RangeSize s, + RangeSize e, C compare) { + RangeSize r = s; while ((r * 2 + 1) <= e) { - octa::RangeSize ch = r * 2 + 1; - octa::RangeSize sw = r; + RangeSize ch = r * 2 + 1; + RangeSize sw = r; if (compare(range[sw], range[ch])) sw = ch; if (((ch + 1) <= e) && compare(range[sw], range[ch + 1])) @@ -74,32 +74,32 @@ namespace detail { template void heapsort(R range, C compare) { - octa::RangeSize len = range.size(); - octa::RangeSize st = (len - 2) / 2; + RangeSize len = range.size(); + RangeSize st = (len - 2) / 2; for (;;) { - octa::detail::hs_sift_down(range, st, len - 1, compare); + detail::hs_sift_down(range, st, len - 1, compare); if (st-- == 0) break; } - octa::RangeSize e = len - 1; + RangeSize e = len - 1; while (e > 0) { octa::swap(range[e], range[0]); --e; - octa::detail::hs_sift_down(range, 0, e, compare); + detail::hs_sift_down(range, 0, e, compare); } } template void introloop(R range, C compare, RangeSize depth) { if (range.size() <= 10) { - octa::detail::insort(range, compare); + detail::insort(range, compare); return; } if (depth == 0) { - octa::detail::heapsort(range, compare); + detail::heapsort(range, compare); return; } octa::swap(range[range.size() / 2], range.back()); - octa::RangeSize pi = 0; + RangeSize pi = 0; R pr = range; pr.pop_back(); for (; !pr.empty(); pr.pop_front()) { @@ -107,26 +107,26 @@ namespace detail { octa::swap(pr.front(), range[pi++]); } octa::swap(range[pi], range.back()); - octa::detail::introloop(range.slice(0, pi), compare, depth - 1); - octa::detail::introloop(range.slice(pi + 1, range.size()), compare, + detail::introloop(range.slice(0, pi), compare, depth - 1); + detail::introloop(range.slice(pi + 1, range.size()), compare, depth - 1); } template void introsort(R range, C compare) { - octa::detail::introloop(range, compare, octa::RangeSize(2 + detail::introloop(range, compare, RangeSize(2 * (log(range.size()) / log(2)))); } } /* namespace detail */ template void sort(R range, C compare) { - octa::detail::introsort(range, compare); + detail::introsort(range, compare); } template void sort(R range) { - sort(range, octa::Less>()); + sort(range, Less>()); } /* min/max(_element) */ @@ -220,7 +220,7 @@ template F for_each(R range, F func) { for (; !range.empty(); range.pop_front()) func(range.front()); - return octa::move(func); + return move(func); } template @@ -333,7 +333,7 @@ R2 copy_if_not(R1 irange, R2 orange, P pred) { template R2 move(R1 irange, R2 orange) { for (; !irange.empty(); irange.pop_front()) - orange.put(octa::move(irange.front())); + orange.put(move(irange.front())); return orange; } @@ -366,7 +366,7 @@ void generate(R range, F gen) { } template -octa::Pair swap_ranges(R1 range1, R2 range2) { +Pair swap_ranges(R1 range1, R2 range2) { while (!range1.empty() && !range2.empty()) { octa::swap(range1.front(), range2.front()); range1.pop_front(); @@ -411,11 +411,11 @@ T foldr(R range, T init, F func) { template struct MapRange: InputRange< - MapRange, octa::RangeCategory, R, R, octa::RangeSize + MapRange, RangeCategory, R, R, RangeSize > { private: T p_range; - octa::FunctionMakeDefaultConstructible p_func; + FunctionMakeDefaultConstructible p_func; public: MapRange() = delete; @@ -438,7 +438,7 @@ public: } bool empty() const { return p_range.empty(); } - octa::RangeSize size() const { return p_range.size(); } + RangeSize size() const { return p_range.size(); } bool equals_front(const MapRange &r) const { return p_range.equals_front(r.p_range); @@ -447,10 +447,10 @@ public: return p_range.equals_front(r.p_range); } - octa::RangeDifference distance_front(const MapRange &r) const { + RangeDifference distance_front(const MapRange &r) const { return p_range.distance_front(r.p_range); } - octa::RangeDifference distance_back(const MapRange &r) const { + RangeDifference distance_back(const MapRange &r) const { return p_range.distance_back(r.p_range); } @@ -460,54 +460,51 @@ public: bool push_front() { return p_range.pop_front(); } bool push_back() { return p_range.push_back(); } - octa::RangeSize pop_front_n(octa::RangeSize n) { + RangeSize pop_front_n(RangeSize n) { p_range.pop_front_n(n); } - octa::RangeSize pop_back_n(octa::RangeSize n) { + RangeSize pop_back_n(RangeSize n) { p_range.pop_back_n(n); } - octa::RangeSize push_front_n(octa::RangeSize n) { + RangeSize push_front_n(RangeSize n) { return p_range.push_front_n(n); } - octa::RangeSize push_back_n(octa::RangeSize n) { + RangeSize push_back_n(RangeSize n) { return p_range.push_back_n(n); } R front() const { return p_func(p_range.front()); } R back() const { return p_func(p_range.back()); } - R operator[](octa::RangeSize idx) const { + R operator[](RangeSize idx) const { return p_func(p_range[idx]); } - MapRange slice(octa::RangeSize start, - octa::RangeSize end) { + MapRange slice(RangeSize start, RangeSize end) { return MapRange(p_range.slice(start, end), p_func); } }; namespace detail { template using MapReturnType - = decltype(declval()(octa::declval>())); + = decltype(declval()(declval>())); } template -MapRange> map(R range, - F func) { - return octa::MapRange>(range, +MapRange> map(R range, F func) { + return MapRange>(range, func); } template struct FilterRange: InputRange< - FilterRange, octa::CommonType, - octa::ForwardRangeTag>, - octa::RangeValue, octa::RangeReference, octa::RangeSize + FilterRange, CommonType, ForwardRangeTag>, + RangeValue, RangeReference, RangeSize > { private: T p_range; - octa::FunctionMakeDefaultConstructible p_pred; + FunctionMakeDefaultConstructible p_pred; void advance_valid() { while (!p_range.empty() && !p_pred(front())) p_range.pop_front(); @@ -554,22 +551,19 @@ public: return ret; } - octa::RangeReference front() const { return p_range.front(); } + RangeReference front() const { return p_range.front(); } }; namespace detail { template using FilterPred - = octa::EnableIf()(octa::declval< - octa::RangeReference - >())), - bool + = EnableIf()(declval>())), bool >::value, P>; } template -FilterRange> filter(R range, P pred) { - return octa::FilterRange(range, pred); +FilterRange> filter(R range, P pred) { + return FilterRange(range, pred); } } /* namespace octa */ diff --git a/octa/array.hh b/octa/array.hh index a8508f1..a8869d9 100644 --- a/octa/array.hh +++ b/octa/array.hh @@ -14,17 +14,17 @@ namespace octa { -template +template struct Array { - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Value = T; using Reference = T &; using ConstReference = const T &; using Pointer = T *; using ConstPointer = const T *; - using Range = octa::PointerRange; - using ConstRange = octa::PointerRange; + using Range = PointerRange; + using ConstRange = PointerRange; T &operator[](Size i) { return p_buf[i]; } const T &operator[](Size i) const { return p_buf[i]; } diff --git a/octa/atomic.hh b/octa/atomic.hh index e81051d..a50d5b6 100644 --- a/octa/atomic.hh +++ b/octa/atomic.hh @@ -115,7 +115,7 @@ namespace detail { __atomic_signal_fence(to_gcc_order(ord)); } - static inline bool atomic_is_lock_free(octa::Size size) { + static inline bool atomic_is_lock_free(Size size) { /* return __atomic_is_lock_free(size, 0); cannot be used on some platforms */ return size <= sizeof(void *); } @@ -201,13 +201,13 @@ namespace detail { } template - struct SkipAmt { static constexpr octa::Size value = 1; }; + struct SkipAmt { static constexpr Size value = 1; }; template - struct SkipAmt { static constexpr octa::Size value = sizeof(T); }; + struct SkipAmt { static constexpr Size value = sizeof(T); }; template struct SkipAmt {}; - template struct SkipAmt {}; + template struct SkipAmt {}; template static inline T atomic_fetch_add(volatile AtomicBase *a, @@ -288,8 +288,7 @@ template inline T kill_dependency(T v) { } namespace detail { - template::value && - !octa::IsSame::value> + template::value && !IsSame::value> struct Atomic { mutable AtomicBase p_a; @@ -451,8 +450,8 @@ namespace detail { } template -struct Atomic: octa::detail::Atomic { - using Base = octa::detail::Atomic; +struct Atomic: detail::Atomic { + using Base = detail::Atomic; Atomic() = default; @@ -468,8 +467,8 @@ struct Atomic: octa::detail::Atomic { }; template -struct Atomic: octa::detail::Atomic { - using Base = octa::detail::Atomic; +struct Atomic: detail::Atomic { + using Base = detail::Atomic; Atomic() = default; @@ -483,22 +482,22 @@ struct Atomic: octa::detail::Atomic { Base::store(v); return v; } - T *fetch_add(octa::Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) + T *fetch_add(Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) volatile { - return octa::detail::atomic_fetch_add(&this->p_a, op, ord); + return detail::atomic_fetch_add(&this->p_a, op, ord); } - T *fetch_add(octa::Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) { - return octa::detail::atomic_fetch_add(&this->p_a, op, ord); + T *fetch_add(Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) { + return detail::atomic_fetch_add(&this->p_a, op, ord); } - T *fetch_sub(octa::Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) + T *fetch_sub(Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) volatile { - return octa::detail::atomic_fetch_sub(&this->p_a, op, ord); + return detail::atomic_fetch_sub(&this->p_a, op, ord); } - T *fetch_sub(octa::Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) { - return octa::detail::atomic_fetch_sub(&this->p_a, op, ord); + T *fetch_sub(Ptrdiff op, MemoryOrder ord = MemoryOrder::seq_cst) { + return detail::atomic_fetch_sub(&this->p_a, op, ord); } @@ -511,10 +510,10 @@ struct Atomic: octa::detail::Atomic { T *operator--( ) volatile { return fetch_sub(1) - 1; } T *operator--( ) { return fetch_sub(1) - 1; } - T *operator+=(octa::Ptrdiff op) volatile { return fetch_add(op) + op; } - T *operator+=(octa::Ptrdiff op) { return fetch_add(op) + op; } - T *operator-=(octa::Ptrdiff op) volatile { return fetch_sub(op) - op; } - T *operator-=(octa::Ptrdiff op) { return fetch_sub(op) - op; } + T *operator+=(Ptrdiff op) volatile { return fetch_add(op) + op; } + T *operator+=(Ptrdiff op) { return fetch_add(op) + op; } + T *operator-=(Ptrdiff op) volatile { return fetch_sub(op) - op; } + T *operator-=(Ptrdiff op) { return fetch_sub(op) - op; } }; template @@ -529,12 +528,12 @@ inline bool atomic_is_lock_free(const Atomic *a) { template inline void atomic_init(volatile Atomic *a, T v) { - octa::detail::atomic_init(&a->p_a, v); + detail::atomic_init(&a->p_a, v); } template inline void atomic_init(Atomic *a, T v) { - octa::detail::atomic_init(&a->p_a, v); + detail::atomic_init(&a->p_a, v); } template @@ -657,196 +656,176 @@ inline bool atomic_compare_exchange_strong_explicit(Atomic *a, T *e, } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_add(volatile Atomic *a, T op) { return a->fetch_add(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_add(Atomic *a, T op) { return a->fetch_add(op); } template -inline T *atomic_fetch_add(volatile Atomic *a, octa::Ptrdiff op) { +inline T *atomic_fetch_add(volatile Atomic *a, Ptrdiff op) { return a->fetch_add(op); } template -inline T *atomic_fetch_add(Atomic *a, octa::Ptrdiff op) { +inline T *atomic_fetch_add(Atomic *a, Ptrdiff op) { return a->fetch_add(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_add_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_add_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_add(op, ord); } template inline T *atomic_fetch_add_explicit(volatile Atomic *a, - octa::Ptrdiff op, MemoryOrder ord) { + Ptrdiff op, MemoryOrder ord) { return a->fetch_add(op, ord); } template -inline T *atomic_fetch_add_explicit(Atomic *a, octa::Ptrdiff op, +inline T *atomic_fetch_add_explicit(Atomic *a, Ptrdiff op, MemoryOrder ord) { return a->fetch_add(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_sub(volatile Atomic *a, T op) { return a->fetch_sub(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_sub(Atomic *a, T op) { return a->fetch_sub(op); } template -inline T *atomic_fetch_sub(volatile Atomic *a, octa::Ptrdiff op) { +inline T *atomic_fetch_sub(volatile Atomic *a, Ptrdiff op) { return a->fetch_sub(op); } template -inline T *atomic_fetch_sub(Atomic *a, octa::Ptrdiff op) { +inline T *atomic_fetch_sub(Atomic *a, Ptrdiff op) { return a->fetch_sub(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_sub_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_sub_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template inline T *atomic_fetch_sub_explicit(volatile Atomic *a, - octa::Ptrdiff op, MemoryOrder ord) { + Ptrdiff op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template -inline T *atomic_fetch_sub_explicit(Atomic *a, octa::Ptrdiff op, +inline T *atomic_fetch_sub_explicit(Atomic *a, Ptrdiff op, MemoryOrder ord) { return a->fetch_sub(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_and(volatile Atomic *a, T op) { return a->fetch_and(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_and(Atomic *a, T op) { return a->fetch_and(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_and_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_and_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_and(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_or(volatile Atomic *a, T op) { return a->fetch_or(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_or(Atomic *a, T op) { return a->fetch_or(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_or_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_or_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_or(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_xor(volatile Atomic *a, T op) { return a->fetch_xor(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_xor(Atomic *a, T op) { return a->fetch_xor(op); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_xor_explicit(volatile Atomic *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } template -inline octa::EnableIf::value && - !octa::IsSame::value, T> +inline EnableIf::value && !IsSame::value, T> atomic_fetch_xor_explicit(Atomic *a, T op, MemoryOrder ord) { return a->fetch_xor(op, ord); } struct AtomicFlag { - octa::detail::AtomicBase p_a; + detail::AtomicBase p_a; AtomicFlag() = default; @@ -858,19 +837,19 @@ struct AtomicFlag { AtomicFlag &operator=(const AtomicFlag &) volatile = delete; bool test_and_set(MemoryOrder ord = MemoryOrder::seq_cst) volatile { - return octa::detail::atomic_exchange(&p_a, true, ord); + return detail::atomic_exchange(&p_a, true, ord); } bool test_and_set(MemoryOrder ord = MemoryOrder::seq_cst) { - return octa::detail::atomic_exchange(&p_a, true, ord); + return detail::atomic_exchange(&p_a, true, ord); } void clear(MemoryOrder ord = MemoryOrder::seq_cst) volatile { - octa::detail::atomic_store(&p_a, false, ord); + detail::atomic_store(&p_a, false, ord); } void clear(MemoryOrder ord = MemoryOrder::seq_cst) { - octa::detail::atomic_store(&p_a, false, ord); + detail::atomic_store(&p_a, false, ord); } }; @@ -910,11 +889,11 @@ inline void atomic_flag_clear_explicit(AtomicFlag *a, MemoryOrder ord) { } inline void atomic_thread_fence(MemoryOrder ord) { - octa::detail::atomic_thread_fence(ord); + detail::atomic_thread_fence(ord); } inline void atomic_signal_fence(MemoryOrder ord) { - octa::detail::atomic_signal_fence(ord); + detail::atomic_signal_fence(ord); } using AtomicBool = Atomic; @@ -922,56 +901,56 @@ using AtomicChar = Atomic; using AtomicShort = Atomic; using AtomicInt = Atomic; using AtomicLong = Atomic; -using AtomicSbyte = Atomic; -using AtomicByte = Atomic; -using AtomicUshort = Atomic; -using AtomicUint = Atomic; -using AtomicUlong = Atomic; -using AtomicLlong = Atomic; -using AtomicUllong = Atomic; +using AtomicSbyte = Atomic; +using AtomicByte = Atomic; +using AtomicUshort = Atomic; +using AtomicUint = Atomic; +using AtomicUlong = Atomic; +using AtomicLlong = Atomic; +using AtomicUllong = Atomic; -using AtomicChar16 = Atomic; -using AtomicChar32 = Atomic; -using AtomicWchar = Atomic; +using AtomicChar16 = Atomic; +using AtomicChar32 = Atomic; +using AtomicWchar = Atomic; -using AtomicPtrdiff = Atomic; -using AtomicSize = Atomic; +using AtomicPtrdiff = Atomic; +using AtomicSize = Atomic; -using AtomicIntmax = Atomic; -using AtomicUintmax = Atomic; +using AtomicIntmax = Atomic; +using AtomicUintmax = Atomic; -using AtomicIntptr = Atomic; -using AtomicUintptr = Atomic; +using AtomicIntptr = Atomic; +using AtomicUintptr = Atomic; -using AtomicInt8 = Atomic; -using AtomicInt16 = Atomic; -using AtomicInt32 = Atomic; -using AtomicInt64 = Atomic; +using AtomicInt8 = Atomic; +using AtomicInt16 = Atomic; +using AtomicInt32 = Atomic; +using AtomicInt64 = Atomic; -using AtomicUint8 = Atomic; -using AtomicUint16 = Atomic; -using AtomicUint32 = Atomic; -using AtomicUint64 = Atomic; +using AtomicUint8 = Atomic; +using AtomicUint16 = Atomic; +using AtomicUint32 = Atomic; +using AtomicUint64 = Atomic; -using AtomicIntLeast8 = Atomic; -using AtomicIntLeast16 = Atomic; -using AtomicIntLeast32 = Atomic; -using AtomicIntLeast64 = Atomic; +using AtomicIntLeast8 = Atomic; +using AtomicIntLeast16 = Atomic; +using AtomicIntLeast32 = Atomic; +using AtomicIntLeast64 = Atomic; -using AtomicUintLeast8 = Atomic; -using AtomicUintLeast16 = Atomic; -using AtomicUintLeast32 = Atomic; -using AtomicUintLeast64 = Atomic; +using AtomicUintLeast8 = Atomic; +using AtomicUintLeast16 = Atomic; +using AtomicUintLeast32 = Atomic; +using AtomicUintLeast64 = Atomic; -using AtomicIntFast8 = Atomic; -using AtomicIntFast16 = Atomic; -using AtomicIntFast32 = Atomic; -using AtomicIntFast64 = Atomic; +using AtomicIntFast8 = Atomic; +using AtomicIntFast16 = Atomic; +using AtomicIntFast32 = Atomic; +using AtomicIntFast64 = Atomic; -using AtomicUintFast8 = Atomic; -using AtomicUintFast16 = Atomic; -using AtomicUintFast32 = Atomic; -using AtomicUintFast64 = Atomic; +using AtomicUintFast8 = Atomic; +using AtomicUintFast16 = Atomic; +using AtomicUintFast32 = Atomic; +using AtomicUintFast64 = Atomic; #define ATOMIC_FLAG_INIT {false} #define ATOMIC_VAR_INIT(v) {v} diff --git a/octa/format.hh b/octa/format.hh index 3e563b8..b0d41cc 100644 --- a/octa/format.hh +++ b/octa/format.hh @@ -41,8 +41,8 @@ namespace detail { return ret; } - static inline octa::Size read_digits(const char *&fmt, char *buf) { - octa::Size ret = 0; + static inline Size read_digits(const char *&fmt, char *buf) { + Size ret = 0; for (; isdigit(*fmt); ++ret) *buf++ = *fmt++; *buf = '\0'; @@ -59,7 +59,7 @@ namespace detail { * 7 .. string * 8 .. custom object */ - static constexpr const octa::byte fmt_specs[] = { + static constexpr const byte fmt_specs[] = { /* uppercase spec set */ 1, 3, 8, 8, /* A B C D */ 1, 1, 1, 8, /* E F G H */ @@ -107,23 +107,23 @@ namespace detail { /* retrieve width/precision */ template - bool convert_arg_param(const T &val, int ¶m, octa::EnableIf< - octa::IsIntegral::value, bool + bool convert_arg_param(const T &val, int ¶m, EnableIf< + IsIntegral::value, bool > = true) { param = int(val); return true; } template - bool convert_arg_param(const T &, int &, octa::EnableIf< - !octa::IsIntegral::value, bool + bool convert_arg_param(const T &, int &, EnableIf< + !IsIntegral::value, bool > = true) { assert(false && "invalid argument for width/precision"); return false; } template - bool get_arg_param(octa::Size idx, int ¶m, const T &val) { + bool get_arg_param(Size idx, int ¶m, const T &val) { if (idx) { assert(false && "not enough format args"); return false; @@ -131,7 +131,7 @@ namespace detail { return convert_arg_param(val, param); } template - bool get_arg_param(octa::Size idx, int ¶m, const T &val, + bool get_arg_param(Size idx, int ¶m, const T &val, const A &...args) { if (idx) return get_arg_param(idx - 1, param, args...); return convert_arg_param(val, param); @@ -144,8 +144,8 @@ struct FormatSpec { p_nested_escape(escape), p_fmt(fmt) {} template - bool read_until_spec(R &writer, octa::Size *wret) { - octa::Size written = 0; + bool read_until_spec(R &writer, Size *wret) { + Size written = 0; if (!p_fmt) return false; while (*p_fmt) { if (*p_fmt == '%') { @@ -164,8 +164,7 @@ struct FormatSpec { } template - octa::Size write_spaces(R &writer, octa::Size n, - bool left, char c = ' ') const { + Size write_spaces(R &writer, Size n, bool left, char c = ' ') const { if (left == bool(p_flags & FMT_FLAG_DASH)) return 0; int r = p_width - int(n); for (int w = p_width - int(n); --w >= 0; writer.put(c)); @@ -177,7 +176,7 @@ struct FormatSpec { return p_fmt; } - void build_spec(char *buf, const char *spec, octa::Size specn) { + void build_spec(char *buf, const char *spec, Size specn) { *buf++ = '%'; if (p_flags & FMT_FLAG_DASH ) *buf++ = '-'; if (p_flags & FMT_FLAG_ZERO ) *buf++ = '0'; @@ -199,36 +198,36 @@ struct FormatSpec { bool arg_precision() const { return p_arg_precision; } template - bool set_width(octa::Size idx, const A &...args) { - return octa::detail::get_arg_param(idx, p_width, args...); + bool set_width(Size idx, const A &...args) { + return detail::get_arg_param(idx, p_width, args...); } template - bool set_precision(octa::Size idx, const A &...args) { - return octa::detail::get_arg_param(idx, p_precision, args...); + bool set_precision(Size idx, const A &...args) { + return detail::get_arg_param(idx, p_precision, args...); } int flags() const { return p_flags; } char spec() const { return p_spec; } - octa::byte index() const { return p_index; } + byte index() const { return p_index; } const char *nested() const { return p_nested; } - octa::Size nested_len() const { return p_nested_len; } + Size nested_len() const { return p_nested_len; } const char *nested_sep() const { return p_nested_sep; } - octa::Size nested_sep_len() const { return p_nested_sep_len; } + Size nested_sep_len() const { return p_nested_sep_len; } bool is_nested() const { return p_is_nested; } bool nested_escape() const { return p_nested_escape; } protected: const char *p_nested = nullptr; - octa::Size p_nested_len = 0; + Size p_nested_len = 0; const char *p_nested_sep = nullptr; - octa::Size p_nested_sep_len = 0; + Size p_nested_sep_len = 0; int p_flags = 0; @@ -243,7 +242,7 @@ protected: char p_spec = '\0'; - octa::byte p_index = 0; + byte p_index = 0; bool p_is_nested = false; bool p_nested_escape = false; @@ -323,7 +322,7 @@ protected: if ((*p_fmt == '(') || ((*p_fmt == '-') && (*(p_fmt + 1) == '('))) { return read_spec_range(); } - octa::Size ndig = octa::detail::read_digits(p_fmt, p_buf); + Size ndig = detail::read_digits(p_fmt, p_buf); bool havepos = false; p_index = 0; @@ -332,7 +331,7 @@ protected: if (ndig <= 0) return false; /* no pos given */ int idx = atoi(p_buf); if (idx <= 0 || idx > 255) return false; /* bad index */ - p_index = octa::byte(idx); + p_index = byte(idx); ++p_fmt; havepos = true; } @@ -344,17 +343,17 @@ protected: /* parse flags */ p_flags = 0; - octa::Size skipd = 0; + Size skipd = 0; if (havepos || !ndig) { - p_flags = octa::detail::parse_fmt_flags(p_fmt, 0); + p_flags = detail::parse_fmt_flags(p_fmt, 0); } else { - for (octa::Size i = 0; i < ndig; ++i) { + for (Size i = 0; i < ndig; ++i) { if (p_buf[i] != '0') break; ++skipd; } if (skipd) p_flags = FMT_FLAG_ZERO; if (skipd == ndig) - p_flags = octa::detail::parse_fmt_flags(p_fmt, p_flags); + p_flags = detail::parse_fmt_flags(p_fmt, p_flags); } /* parse width */ @@ -364,7 +363,7 @@ protected: if (!havepos && ndig && (ndig - skipd)) { p_width = atoi(p_buf + skipd); p_has_width = true; - } else if (octa::detail::read_digits(p_fmt, p_buf)) { + } else if (detail::read_digits(p_fmt, p_buf)) { p_width = atoi(p_buf); p_has_width = true; } else if (*p_fmt == '*') { @@ -379,7 +378,7 @@ protected: if (*p_fmt != '.') goto fmtchar; ++p_fmt; - if (octa::detail::read_digits(p_fmt, p_buf)) { + if (detail::read_digits(p_fmt, p_buf)) { p_precision = atoi(p_buf); p_has_precision = true; } else if (*p_fmt == '*') { @@ -391,8 +390,8 @@ protected: p_spec = *p_fmt++; /* make sure we're testing on a signed byte - our mapping only * tests values up to 127 */ - octa::sbyte sp = p_spec; - return (sp >= 65) && (octa::detail::fmt_specs[sp - 65] != 0); + sbyte sp = p_spec; + return (sp >= 65) && (detail::fmt_specs[sp - 65] != 0); } const char *p_fmt; @@ -401,24 +400,24 @@ protected: namespace detail { template - static inline octa::Ptrdiff write_u(R &writer, const FormatSpec *fl, - bool neg, T val) { + static inline Ptrdiff write_u(R &writer, const FormatSpec *fl, + bool neg, T val) { char buf[20]; - octa::Ptrdiff r = 0; - octa::Size n = 0; + Ptrdiff r = 0; + Size n = 0; char spec = fl->spec(); if (spec == 's') spec = 'd'; - octa::byte specn = octa::detail::fmt_specs[spec - 65]; + byte specn = detail::fmt_specs[spec - 65]; if (specn <= 2 || specn > 7) { assert(false && "cannot format integers with the given spec"); return -1; } - int base = octa::detail::fmt_bases[specn]; + int base = detail::fmt_bases[specn]; if (!val) buf[n++] = '0'; for (; val; val /= base) - buf[n++] = octa::detail::fmt_digits[spec >= 'a'][val % base]; + buf[n++] = detail::fmt_digits[spec >= 'a'][val % base]; r = n; int flags = fl->flags(); @@ -431,7 +430,7 @@ namespace detail { const char *pfx = nullptr; int pfxlen = 0; if (flags & FMT_FLAG_HASH && spec != 'd') { - pfx = octa::detail::fmt_intpfx[spec >= 'a'][specn - 3]; + pfx = detail::fmt_intpfx[spec >= 'a'][specn - 3]; pfxlen = !!pfx[1] + 1; r += pfxlen; } @@ -451,52 +450,43 @@ namespace detail { } template - static octa::Ptrdiff format_impl(R &writer, octa::Size &fmtn, - bool escape, const char *fmt, - const A &...args); + static Ptrdiff format_impl(R &writer, Size &fmtn, bool escape, + const char *fmt, const A &...args); - template> - static octa::True test_fmt_range(int); + template> + static True test_fmt_range(int); template - static octa::False test_fmt_range(...); + static False test_fmt_range(...); template using FmtRangeTest = decltype(test_fmt_range(0)); template - static inline octa::Ptrdiff format_ritem(R &writer, octa::Size &fmtn, - bool esc, - const char *fmt, - const T &item) { + static inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc, + const char *fmt, const T &item) { return format_impl(writer, fmtn, esc, fmt, item); } template - static inline octa::Ptrdiff format_ritem(R &writer, octa::Size &fmtn, - bool esc, - const char *fmt, - const octa::Pair &pair) { + static inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc, + const char *fmt, + const Pair &pair) { return format_impl(writer, fmtn, esc, fmt, pair.first, pair.second); } template - static inline octa::Ptrdiff write_range(R &writer, - const FormatSpec *fl, - bool escape, - const char *sep, - octa::Size seplen, - const T &val, - octa::EnableIf< - FmtRangeTest::value, - bool - > = true) { + static inline Ptrdiff write_range(R &writer, const FormatSpec *fl, + bool escape, const char *sep, + Size seplen, const T &val, + EnableIf::value, + bool> = true) { auto range = octa::iter(val); if (range.empty()) return 0; - octa::Ptrdiff ret = 0; - octa::Size fmtn = 0; + Ptrdiff ret = 0; + Size fmtn = 0; /* test first item */ - octa::Ptrdiff fret = format_ritem(writer, fmtn, escape, - fl->rest(), range.front()); + Ptrdiff fret = format_ritem(writer, fmtn, escape, fl->rest(), + range.front()); if (fret < 0) return fret; ret += fret; range.pop_front(); @@ -515,21 +505,18 @@ namespace detail { } template - static inline octa::Ptrdiff write_range(R &, const FormatSpec *, bool, - const char *, octa::Size, - const T &, - octa::EnableIf< - !FmtRangeTest::value, - bool - > = true) { + static inline Ptrdiff write_range(R &, const FormatSpec *, bool, + const char *, Size, const T &, + EnableIf::value, + bool> = true) { assert(false && "invalid value for ranged format"); return -1; } template())) - > static octa::True test_fmt_tostr(int); - template static octa::False test_fmt_tostr(...); + typename = decltype(octa::to_string(declval())) + > static True test_fmt_tostr(int); + template static False test_fmt_tostr(...); template using FmtTostrTest = decltype(test_fmt_tostr(0)); @@ -549,15 +536,15 @@ namespace detail { static inline const char *escape_fmt_char(char v, char quote) { if ((v >= 0 && v < 0x20) || (v == quote)) { - return fmt_escapes[octa::Size(v)]; + return fmt_escapes[Size(v)]; } else if (v == 0x7F) { return "\\x7F"; } return nullptr; } - static inline octa::String escape_fmt_str(const char *val) { - octa::String ret; + static inline String escape_fmt_str(const char *val) { + String ret; ret.push('"'); while (*val) { const char *esc = escape_fmt_char(*val, '"'); @@ -572,7 +559,7 @@ namespace detail { } template - struct FmtWriteRange: octa::OutputRange, char> { + struct FmtWriteRange: OutputRange, char> { FmtWriteRange() = delete; FmtWriteRange(R &out): p_out(out), p_written(0) {} bool put(char v) { @@ -580,15 +567,15 @@ namespace detail { p_written += ret; return ret; } - octa::Size put_n(const char *v, octa::Size n) { - octa::Size ret = p_out.put_n(v, n); + Size put_n(const char *v, Size n) { + Size ret = p_out.put_n(v, n); p_written += ret; return ret; } - octa::Size get_written() const { return p_written; } + Size get_written() const { return p_written; } private: R &p_out; - octa::Size p_written; + Size p_written; }; template @@ -602,21 +589,20 @@ namespace detail { static constexpr bool value = (sizeof(test(0)) == sizeof(char)); }; - struct WriteSpec: octa::FormatSpec { - WriteSpec(): octa::FormatSpec() {} - WriteSpec(const char *fmt, bool esc): octa::FormatSpec(fmt, esc) {} + struct WriteSpec: FormatSpec { + WriteSpec(): FormatSpec() {} + WriteSpec(const char *fmt, bool esc): FormatSpec(fmt, esc) {} /* C string */ template - octa::Ptrdiff write(R &writer, bool escape, const char *val, - octa::Size n) { + Ptrdiff write(R &writer, bool escape, const char *val, Size n) { if (escape) { - octa::String esc = escape_fmt_str(val); + String esc = escape_fmt_str(val); return write(writer, false, (const char *)esc.data(), esc.size()); } if (this->precision()) n = this->precision(); - octa::Ptrdiff r = n; + Ptrdiff r = n; r += this->write_spaces(writer, n, true); writer.put_n(val, n); r += this->write_spaces(writer, n, false); @@ -624,7 +610,7 @@ namespace detail { } template - octa::Ptrdiff write(R &writer, bool escape, const char *val) { + Ptrdiff write(R &writer, bool escape, const char *val) { if (this->spec() != 's') { assert(false && "cannot print strings with the given spec"); return -1; @@ -634,8 +620,7 @@ namespace detail { /* OctaSTD string */ template - octa::Ptrdiff write(R &writer, bool escape, - const octa::AnyString &val) { + Ptrdiff write(R &writer, bool escape, const AnyString &val) { if (this->spec() != 's') { assert(false && "cannot print strings with the given spec"); return -1; @@ -645,7 +630,7 @@ namespace detail { /* character */ template - octa::Ptrdiff write(R &writer, bool escape, char val) { + Ptrdiff write(R &writer, bool escape, char val) { if (this->spec() != 's' && this->spec() != 'c') { assert(false && "cannot print chars with the given spec"); return -1; @@ -655,13 +640,13 @@ namespace detail { if (esc) { char buf[6]; buf[0] = '\''; - octa::Size elen = strlen(esc); + Size elen = strlen(esc); memcpy(buf + 1, esc, elen); buf[elen + 1] = '\''; return write(writer, false, (const char *)buf, elen + 2); } } - octa::Ptrdiff r = 1 + escape * 2; + Ptrdiff r = 1 + escape * 2; r += this->write_spaces(writer, 1 + escape * 2, true); if (escape) { writer.put('\''); @@ -674,7 +659,7 @@ namespace detail { /* bool */ template - octa::Ptrdiff write(R &writer, bool, bool val) { + Ptrdiff write(R &writer, bool, bool val) { if (this->spec() == 's') return write(writer, ("false\0true") + (6 * val)); else @@ -683,32 +668,32 @@ namespace detail { /* signed integers */ template - octa::Ptrdiff write(R &writer, bool, T val, octa::EnableIf< - octa::IsIntegral::value && octa::IsSigned::value, bool + Ptrdiff write(R &writer, bool, T val, EnableIf< + IsIntegral::value && IsSigned::value, bool > = true) { - using UT = octa::MakeUnsigned; - return octa::detail::write_u(writer, this, val < 0, - (val < 0) ? UT(-val) : UT(val)); + using UT = MakeUnsigned; + return detail::write_u(writer, this, val < 0, + (val < 0) ? (UT)(-val) : (UT)(val)); } /* unsigned integers */ template - octa::Ptrdiff write(R &writer, bool, T val, octa::EnableIf< - octa::IsIntegral::value && octa::IsUnsigned::value, bool + Ptrdiff write(R &writer, bool, T val, EnableIf< + IsIntegral::value && IsUnsigned::value, bool > = true) { - return octa::detail::write_u(writer, this, false, val); + return detail::write_u(writer, this, false, val); } template::value - > octa::Ptrdiff write(R &writer, bool, T val, octa::EnableIf< - octa::IsFloatingPoint::value, bool + bool Long = IsSame::value + > Ptrdiff write(R &writer, bool, T val, EnableIf< + IsFloatingPoint::value, bool > = true) { char buf[16], rbuf[128]; char fmtspec[Long + 1]; fmtspec[Long] = this->spec(); - octa::byte specn = octa::detail::fmt_specs[this->spec() - 65]; + byte specn = detail::fmt_specs[this->spec() - 65]; if (specn != 1 && specn != 7) { assert(false && "cannot format floats with the given spec"); return -1; @@ -717,12 +702,12 @@ namespace detail { if (Long) fmtspec[0] = 'L'; this->build_spec(buf, fmtspec, sizeof(fmtspec)); - octa::Ptrdiff ret = snprintf(rbuf, sizeof(rbuf), buf, + Ptrdiff ret = snprintf(rbuf, sizeof(rbuf), buf, this->width(), this->has_precision() ? this->precision() : 6, val); char *dbuf = nullptr; - if (octa::Size(ret) >= sizeof(rbuf)) { + if (Size(ret) >= sizeof(rbuf)) { /* this should typically never happen */ dbuf = (char *)malloc(ret + 1); ret = snprintf(dbuf, ret + 1, buf, this->width(), @@ -735,18 +720,18 @@ namespace detail { /* pointer value */ template - octa::Ptrdiff write(R &writer, bool, T *val) { + Ptrdiff write(R &writer, bool, T *val) { if (this->p_spec == 's') { this->p_spec = 'x'; this->p_flags |= FMT_FLAG_HASH; } - return write(writer, false, octa::Size(val)); + return write(writer, false, Size(val)); } /* generic value */ template - octa::Ptrdiff write(R &writer, bool, const T &val, octa::EnableIf< - !octa::IsArithmetic::value && FmtTostrTest::value && + Ptrdiff write(R &writer, bool, const T &val, EnableIf< + !IsArithmetic::value && FmtTostrTest::value && !FmtTofmtTest>::value, bool > = true) { if (this->spec() != 's') { @@ -758,8 +743,8 @@ namespace detail { /* custom format case */ template - octa::Ptrdiff write(R &writer, bool, const T &val, - octa::EnableIf>::value, bool + Ptrdiff write(R &writer, bool, const T &val, + EnableIf>::value, bool > = true) { FmtWriteRange sink(writer); if (!val.to_format(sink, *this)) return -1; @@ -768,8 +753,8 @@ namespace detail { /* generic failure case */ template - octa::Ptrdiff write(R &, bool, const T &, octa::EnableIf< - !octa::IsArithmetic::value && !FmtTostrTest::value, bool + Ptrdiff write(R &, bool, const T &, EnableIf< + !IsArithmetic::value && !FmtTostrTest::value, bool > = true) { assert(false && "value cannot be formatted"); return -1; @@ -777,7 +762,7 @@ namespace detail { /* actual writer */ template - octa::Ptrdiff write_arg(R &writer, octa::Size idx, const T &val) { + Ptrdiff write_arg(R &writer, Size idx, const T &val) { if (idx) { assert(false && "not enough format args"); return -1; @@ -786,55 +771,50 @@ namespace detail { } template - octa::Ptrdiff write_arg(R &writer, octa::Size idx, const T &val, - const A &...args) { + Ptrdiff write_arg(R &writer, Size idx, const T &val, + const A &...args) { if (idx) return write_arg(writer, idx - 1, args...); return write(writer, this->p_nested_escape, val); } /* range writer */ template - octa::Ptrdiff write_range(R &writer, octa::Size idx, - const char *sep, octa::Size seplen, - const T &val) { + Ptrdiff write_range(R &writer, Size idx, const char *sep, + Size seplen, const T &val) { if (idx) { assert(false && "not enough format args"); return -1; } - return octa::detail::write_range(writer, this, - this->p_nested_escape, sep, seplen, val); + return detail::write_range(writer, this, this->p_nested_escape, + sep, seplen, val); } template - octa::Ptrdiff write_range(R &writer, octa::Size idx, - const char *sep, octa::Size seplen, - const T &val, - const A &...args) { + Ptrdiff write_range(R &writer, Size idx, const char *sep, + Size seplen, const T &val, const A &...args) { if (idx) return write_range(writer, idx - 1, sep, seplen, args...); - return octa::detail::write_range(writer, this, + return detail::write_range(writer, this, this->p_nested_escape, sep, seplen, val); } }; template - static inline octa::Ptrdiff format_impl(R &writer, octa::Size &fmtn, - bool escape, - const char *fmt, - const A &...args) { - octa::Size argidx = 1, retn = 0, twr = 0; - octa::Ptrdiff written = 0; - octa::detail::WriteSpec spec(fmt, escape); + static inline Ptrdiff format_impl(R &writer, Size &fmtn, bool escape, + const char *fmt, const A &...args) { + Size argidx = 1, retn = 0, twr = 0; + Ptrdiff written = 0; + detail::WriteSpec spec(fmt, escape); while (spec.read_until_spec(writer, &twr)) { written += twr; - octa::Size argpos = spec.index(); + Size argpos = spec.index(); if (spec.is_nested()) { if (!argpos) argpos = argidx++; /* FIXME: figure out a better way */ char new_fmt[256]; memcpy(new_fmt, spec.nested(), spec.nested_len()); new_fmt[spec.nested_len()] = '\0'; - octa::detail::WriteSpec nspec(new_fmt, spec.nested_escape()); - octa::Ptrdiff sw = nspec.write_range(writer, argpos - 1, + detail::WriteSpec nspec(new_fmt, spec.nested_escape()); + Ptrdiff sw = nspec.write_range(writer, argpos - 1, spec.nested_sep(), spec.nested_sep_len(), args...); if (sw < 0) return sw; written += sw; @@ -871,7 +851,7 @@ namespace detail { return -1; } } - octa::Ptrdiff sw = spec.write_arg(writer, argpos - 1, args...); + Ptrdiff sw = spec.write_arg(writer, argpos - 1, args...); if (sw < 0) return sw; written += sw; } @@ -881,10 +861,10 @@ namespace detail { } template - static inline octa::Ptrdiff format_impl(R &writer, octa::Size &fmtn, - bool, const char *fmt) { - octa::Size written = 0; - octa::detail::WriteSpec spec(fmt, false); + static inline Ptrdiff format_impl(R &writer, Size &fmtn, bool, + const char *fmt) { + Size written = 0; + detail::WriteSpec spec(fmt, false); if (spec.read_until_spec(writer, &written)) return -1; fmtn = 0; return written; @@ -892,28 +872,26 @@ namespace detail { } /* namespace detail */ template -static inline octa::Ptrdiff format(R &&writer, octa::Size &fmtn, - const char *fmt, const A &...args) { - return octa::detail::format_impl(writer, fmtn, false, fmt, args...); +static inline Ptrdiff format(R &&writer, Size &fmtn, const char *fmt, + const A &...args) { + return detail::format_impl(writer, fmtn, false, fmt, args...); } template -octa::Ptrdiff format(R &&writer, octa::Size &fmtn, - const octa::AnyString &fmt, - const A &...args) { +Ptrdiff format(R &&writer, Size &fmtn, const AnyString &fmt, + const A &...args) { return format(writer, fmtn, fmt.data(), args...); } template -octa::Ptrdiff format(R &&writer, const char *fmt, const A &...args) { - octa::Size fmtn = 0; +Ptrdiff format(R &&writer, const char *fmt, const A &...args) { + Size fmtn = 0; return format(writer, fmtn, fmt, args...); } template -octa::Ptrdiff format(R &&writer, const octa::AnyString &fmt, - const A &...args) { - octa::Size fmtn = 0; +Ptrdiff format(R &&writer, const AnyString &fmt, const A &...args) { + Size fmtn = 0; return format(writer, fmtn, fmt.data(), args...); } diff --git a/octa/functional.hh b/octa/functional.hh index 413f892..8118d25 100644 --- a/octa/functional.hh +++ b/octa/functional.hh @@ -96,8 +96,8 @@ template BinaryNegate not2(const T &fn) { /* endian swap */ -template::value +template::value > struct EndianSwap; template @@ -107,7 +107,7 @@ struct EndianSwap { T operator()(T v) const { union { T iv; uint16_t sv; } u; u.iv = v; - u.sv = octa::endian_swap16(u.sv); + u.sv = endian_swap16(u.sv); return u.iv; } }; @@ -119,7 +119,7 @@ struct EndianSwap { T operator()(T v) const { union { T iv; uint32_t sv; } u; u.iv = v; - u.sv = octa::endian_swap32(u.sv); + u.sv = endian_swap32(u.sv); return u.iv; } }; @@ -131,7 +131,7 @@ struct EndianSwap { T operator()(T v) const { union { T iv; uint64_t sv; } u; u.iv = v; - u.sv = octa::endian_swap64(u.sv); + u.sv = endian_swap64(u.sv); return u.iv; } }; @@ -140,8 +140,8 @@ template T endian_swap(T x) { return EndianSwap()(x); } namespace detail { - template::value + template::value > struct EndianSame; template @@ -165,11 +165,11 @@ namespace detail { } #if OCTA_BYTE_ORDER == OCTA_ENDIAN_LIL -template struct FromLilEndian: octa::detail::EndianSame {}; +template struct FromLilEndian: detail::EndianSame {}; template struct FromBigEndian: EndianSwap {}; #else template struct FromLilEndian: EndianSwap {}; -template struct FromBigEndian: octa::detail::EndianSame {}; +template struct FromBigEndian: detail::EndianSame {}; #endif template T from_lil_endian(T x) { return FromLilEndian()(x); } @@ -179,9 +179,9 @@ template T from_big_endian(T x) { return FromBigEndian()(x); } template struct ToHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(const T &v) const { + Size operator()(const T &v) const { return v.to_hash(); } }; @@ -189,15 +189,15 @@ template struct ToHash { namespace detail { template struct ToHashBase { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - return octa::Size(v); + Size operator()(T v) const { + return Size(v); } }; } -#define OCTA_HASH_BASIC(T) template<> struct ToHash: octa::detail::ToHashBase {}; +#define OCTA_HASH_BASIC(T) template<> struct ToHash: detail::ToHashBase {}; OCTA_HASH_BASIC(bool) OCTA_HASH_BASIC(char) @@ -205,35 +205,35 @@ OCTA_HASH_BASIC(short) OCTA_HASH_BASIC(int) OCTA_HASH_BASIC(long) -OCTA_HASH_BASIC(octa::sbyte) -OCTA_HASH_BASIC(octa::byte) -OCTA_HASH_BASIC(octa::ushort) -OCTA_HASH_BASIC(octa::uint) -OCTA_HASH_BASIC(octa::ulong) +OCTA_HASH_BASIC(sbyte) +OCTA_HASH_BASIC(byte) +OCTA_HASH_BASIC(ushort) +OCTA_HASH_BASIC(uint) +OCTA_HASH_BASIC(ulong) -OCTA_HASH_BASIC(octa::Char16) -OCTA_HASH_BASIC(octa::Char32) -OCTA_HASH_BASIC(octa::Wchar) +OCTA_HASH_BASIC(Char16) +OCTA_HASH_BASIC(Char32) +OCTA_HASH_BASIC(Wchar) #undef OCTA_HASH_BASIC namespace detail { - static inline Size mem_hash(const void *p, octa::Size l) { - const octa::byte *d = (const octa::byte *)p; - octa::Size h = 5381; + static inline Size mem_hash(const void *p, Size l) { + const byte *d = (const byte *)p; + Size h = 5381; for (Size i = 0; i < l; ++i) h = ((h << 5) + h) ^ d[i]; return h; } - template + template struct ScalarHash; template struct ScalarHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - union { T v; octa::Size h; } u; + Size operator()(T v) const { + union { T v; Size h; } u; u.h = 0; u.v = v; return u.h; @@ -242,10 +242,10 @@ namespace detail { template struct ScalarHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - union { T v; octa::Size h; } u; + Size operator()(T v) const { + union { T v; Size h; } u; u.v = v; return u.h; } @@ -253,10 +253,10 @@ namespace detail { template struct ScalarHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - union { T v; struct { octa::Size h1, h2; }; } u; + Size operator()(T v) const { + union { T v; struct { Size h1, h2; }; } u; u.v = v; return mem_hash((const void *)&u, sizeof(u)); } @@ -264,10 +264,10 @@ namespace detail { template struct ScalarHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - union { T v; struct { octa::Size h1, h2, h3; }; } u; + 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)); } @@ -275,76 +275,76 @@ namespace detail { template struct ScalarHash { using Argument = T; - using Result = octa::Size; + using Result = Size; - octa::Size operator()(T v) const { - union { T v; struct { octa::Size h1, h2, h3, h4; }; } u; + 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)); } }; } /* namespace detail */ -template<> struct ToHash: octa::detail::ScalarHash {}; -template<> struct ToHash: octa::detail::ScalarHash {}; +template<> struct ToHash: detail::ScalarHash {}; +template<> struct ToHash: detail::ScalarHash {}; -template<> struct ToHash: octa::detail::ScalarHash { - octa::Size operator()(float v) const { +template<> struct ToHash: detail::ScalarHash { + Size operator()(float v) const { if (v == 0) return 0; - return octa::detail::ScalarHash::operator()(v); + return detail::ScalarHash::operator()(v); } }; -template<> struct ToHash: octa::detail::ScalarHash { - octa::Size operator()(double v) const { +template<> struct ToHash: detail::ScalarHash { + Size operator()(double v) const { if (v == 0) return 0; - return octa::detail::ScalarHash::operator()(v); + return detail::ScalarHash::operator()(v); } }; -template<> struct ToHash: octa::detail::ScalarHash { - octa::Size operator()(octa::ldouble v) const { +template<> struct ToHash: detail::ScalarHash { + Size operator()(ldouble v) const { if (v == 0) return 0; #ifdef __i386__ - union { octa::ldouble v; struct { octa::Size h1, h2, h3, h4; }; } u; + union { ldouble v; struct { Size h1, h2, h3, h4; }; } u; u.h1 = u.h2 = u.h3 = u.h4 = 0; u.v = v; return (u.h1 ^ u.h2 ^ u.h3 ^ u.h4); #else #ifdef __x86_64__ - union { octa::ldouble v; struct { octa::Size h1, h2; }; } u; + union { ldouble v; struct { Size h1, h2; }; } u; u.h1 = u.h2 = 0; u.v = v; return (u.h1 ^ u.h2); #else - return octa::detail::ScalarHash::operator()(v); + return detail::ScalarHash::operator()(v); #endif #endif } }; namespace detail { - template, char>::value> + template, char>::value> struct ToHashPtr { using Argument = T *; - using Result = octa::Size; - octa::Size operator()(T *v) const { - union { T *v; octa::Size h; } u; + using Result = Size; + Size operator()(T *v) const { + union { T *v; Size h; } u; u.v = v; - return octa::detail::mem_hash((const void *)&u, sizeof(u)); + return detail::mem_hash((const void *)&u, sizeof(u)); } }; template struct ToHashPtr { using Argument = T *; - using Result = octa::Size; - octa::Size operator()(T *v) const { - return octa::detail::mem_hash(v, strlen(v)); + using Result = Size; + Size operator()(T *v) const { + return detail::mem_hash(v, strlen(v)); } }; } -template struct ToHash: octa::detail::ToHashPtr {}; +template struct ToHash: detail::ToHashPtr {}; template typename ToHash::Result to_hash(const T &v) { @@ -446,8 +446,8 @@ namespace detail { } /* namespace detail */ template -octa::detail::MemFn mem_fn(R T:: *ptr) { - return octa::detail::MemFn(ptr); +detail::MemFn mem_fn(R T:: *ptr) { + return detail::MemFn(ptr); } /* function impl @@ -465,7 +465,7 @@ namespace detail { struct FunctorInPlace { static constexpr bool value = sizeof(T) <= sizeof(FunctorData) && (alignof(FunctorData) % alignof(T)) == 0 - && octa::IsMoveConstructible::value; + && IsMoveConstructible::value; }; struct FunctionManager; @@ -498,15 +498,15 @@ namespace detail { struct FunctorDataManager { template static R call(const FunctorData &s, Args ...args) { - return ((T &)s)(octa::forward(args)...); + return ((T &)s)(forward(args)...); } static void store_f(FmStorage &s, T v) { - new (&get_ref(s)) T(octa::forward(v)); + new (&get_ref(s)) T(forward(v)); } static void move_f(FmStorage &lhs, FmStorage &&rhs) { - new (&get_ref(lhs)) T(octa::move(get_ref(rhs))); + new (&get_ref(lhs)) T(move(get_ref(rhs))); } static void destroy_f(A &, FmStorage &s) { @@ -529,20 +529,18 @@ namespace detail { > { template static R call(const FunctorData &s, Args ...args) { - return (*(octa::AllocatorPointer &)s) - (octa::forward(args)...); + return (*(AllocatorPointer &)s)(forward(args)...); } static void store_f(FmStorage &s, T v) { A &a = s.get_alloc(); AllocatorPointer *ptr = new (&get_ptr_ref(s)) AllocatorPointer(allocator_allocate(a, 1)); - allocator_construct(a, *ptr, octa::forward(v)); + allocator_construct(a, *ptr, forward(v)); } static void move_f(FmStorage &lhs, FmStorage &&rhs) { - new (&get_ptr_ref(lhs)) AllocatorPointer(octa::move( - get_ptr_ref(rhs))); + new (&get_ptr_ref(lhs)) AllocatorPointer(move(get_ptr_ref(rhs))); get_ptr_ref(rhs) = nullptr; } @@ -572,7 +570,7 @@ namespace detail { template static void create_fm(FmStorage &s, A &&a) { - new (&s.get_alloc()) A(octa::move(a)); + new (&s.get_alloc()) A(move(a)); s.manager = &get_default_fm(); } @@ -599,9 +597,9 @@ namespace detail { static void call_move_and_destroy(FmStorage &lhs, FmStorage &&rhs) { using Spec = FunctorDataManager; - Spec::move_f(lhs, octa::move(rhs)); + Spec::move_f(lhs, move(rhs)); Spec::destroy_f(rhs.get_alloc(), rhs); - create_fm(lhs, octa::move(rhs.get_alloc())); + create_fm(lhs, move(rhs.get_alloc())); rhs.get_alloc().~A(); } @@ -665,7 +663,7 @@ namespace detail { template T func_to_functor(T &&f) { - return octa::forward(f); + return forward(f); } template @@ -685,24 +683,24 @@ namespace detail { struct Nat {}; template - static decltype(func_to_functor(octa::declval()) - (octa::declval()...)) test(U *); + static decltype(func_to_functor(declval()) (declval()...)) + test(U *); template static Nat test(...); - static constexpr bool value = octa::IsConvertible< + static constexpr bool value = IsConvertible< decltype(test(nullptr)), R >::value; }; template - using FunctorType = decltype(func_to_functor(octa::declval())); + using FunctorType = decltype(func_to_functor(declval())); } /* namespace detail */ template -struct Function: octa::detail::FunctionBase { - Function( ) { init_empty(); } - Function(octa::Nullptr) { init_empty(); } +struct Function: detail::FunctionBase { + Function( ) { init_empty(); } + Function(Nullptr) { init_empty(); } Function(Function &&f) { init_empty(); @@ -713,45 +711,45 @@ struct Function: octa::detail::FunctionBase { f.p_stor.manager->call_copyf(p_stor, f.p_stor); } - template::value + template::value >> Function(T f) { if (func_is_null(f)) { init_empty(); return; } - initialize(octa::detail::func_to_functor(octa::forward(f)), - octa::Allocator>()); + initialize(detail::func_to_functor(forward(f)), + Allocator>()); } template - Function(octa::AllocatorArg, const A &) { init_empty(); } + Function(AllocatorArg, const A &) { init_empty(); } template - Function(octa::AllocatorArg, const A &, octa::Nullptr) { init_empty(); } + Function(AllocatorArg, const A &, Nullptr) { init_empty(); } template - Function(octa::AllocatorArg, const A &, Function &&f) { + Function(AllocatorArg, const A &, Function &&f) { init_empty(); swap(f); } template - Function(octa::AllocatorArg, const A &a, const Function &f): + Function(AllocatorArg, const A &a, const Function &f): p_call(f.p_call) { - const octa::detail::FunctionManager *mfa - = &octa::detail::get_default_fm, A>(); + const detail::FunctionManager *mfa + = &detail::get_default_fm, A>(); if (f.p_stor.manager == mfa) { - octa::detail::create_fm, A>(p_stor, A(a)); + detail::create_fm, A>(p_stor, A(a)); mfa->call_copyf_fo(p_stor, f.p_stor); return; } using AA = AllocatorRebind; - const octa::detail::FunctionManager *mff - = &octa::detail::get_default_fm(); + const detail::FunctionManager *mff + = &detail::get_default_fm(); if (f.p_stor.manager == mff) { - octa::detail::create_fm(p_stor, AA(a)); + detail::create_fm(p_stor, AA(a)); mff->call_copyf_fo(p_stor, f.P_stor); return; } @@ -759,14 +757,14 @@ struct Function: octa::detail::FunctionBase { initialize(f, AA(a)); } - template::value - >> Function(octa::AllocatorArg, const A &a, T f) { + template::value + >> Function(AllocatorArg, const A &a, T f) { if (func_is_null(f)) { init_empty(); return; } - initialize(octa::detail::func_to_functor(octa::forward(f)), A(a)); + initialize(detail::func_to_functor(forward(f)), A(a)); } ~Function() { @@ -786,45 +784,41 @@ struct Function: octa::detail::FunctionBase { }; R operator()(Args ...args) const { - return p_call(p_stor.data, octa::forward(args)...); + return p_call(p_stor.data, forward(args)...); } template void assign(F &&f, const A &a) { - Function(octa::allocator_arg, a, octa::forward(f)).swap(*this); + Function(allocator_arg, a, forward(f)).swap(*this); } void swap(Function &f) { - octa::detail::FmStorage tmp; - f.p_stor.manager->call_move_and_destroyf(tmp, - octa::move(f.p_stor)); - p_stor.manager->call_move_and_destroyf(f.p_stor, - octa::move(p_stor)); - tmp.manager->call_move_and_destroyf(p_stor, - octa::move(tmp)); + detail::FmStorage tmp; + f.p_stor.manager->call_move_and_destroyf(tmp, move(f.p_stor)); + p_stor.manager->call_move_and_destroyf(f.p_stor, move(p_stor)); + tmp.manager->call_move_and_destroyf(p_stor, move(tmp)); octa::swap(p_call, f.p_call); } operator bool() const { return p_call != nullptr; } private: - octa::detail::FmStorage p_stor; - R (*p_call)(const octa::detail::FunctorData &, Args...); + detail::FmStorage p_stor; + R (*p_call)(const detail::FunctorData &, Args...); template void initialize(T &&f, A &&a) { - p_call = &octa::detail::FunctorDataManager::template call; - octa::detail::create_fm(p_stor, octa::forward(a)); - octa::detail::FunctorDataManager::store_f(p_stor, - octa::forward(f)); + p_call = &detail::FunctorDataManager::template call; + detail::create_fm(p_stor, forward(a)); + detail::FunctorDataManager::store_f(p_stor, forward(f)); } void init_empty() { using emptyf = R(*)(Args...); - using emptya = octa::Allocator; + using emptya = Allocator; p_call = nullptr; - octa::detail::create_fm(p_stor, emptya()); - octa::detail::FunctorDataManager::store_f(p_stor, + detail::create_fm(p_stor, emptya()); + detail::FunctorDataManager::store_f(p_stor, nullptr); } @@ -847,16 +841,16 @@ private: }; template -bool operator==(octa::Nullptr, const Function &rhs) { return !rhs; } +bool operator==(Nullptr, const Function &rhs) { return !rhs; } template -bool operator==(const Function &lhs, octa::Nullptr) { return !lhs; } +bool operator==(const Function &lhs, Nullptr) { return !lhs; } template -bool operator!=(octa::Nullptr, const Function &rhs) { return rhs; } +bool operator!=(Nullptr, const Function &rhs) { return rhs; } template -bool operator!=(const Function &lhs, octa::Nullptr) { return lhs; } +bool operator!=(const Function &lhs, Nullptr) { return lhs; } namespace detail { template @@ -865,7 +859,7 @@ namespace detail { template struct DcLambdaTypes { using Ptr = R (*)(A...); - using Obj = octa::Function; + using Obj = Function; }; template @@ -874,7 +868,7 @@ namespace detail { static char test(typename DcLambdaTypes::Ptr); template static int test(...); - static constexpr bool value = (sizeof(test(octa::declval())) == 1); + static constexpr bool value = (sizeof(test(declval())) == 1); }; template::value> @@ -887,8 +881,8 @@ namespace detail { using Type = typename DcLambdaTypes::Ptr; }; - template::value && - octa::IsMoveConstructible::value + template::value && + IsMoveConstructible::value > struct DcFuncTypeObj { using Type = typename DcFuncTypeObjBase::Type; }; @@ -898,7 +892,7 @@ namespace detail { using Type = F; }; - template::value> + template::value> struct DcFuncType { using Type = F; }; @@ -910,7 +904,7 @@ namespace detail { } template using FunctionMakeDefaultConstructible - = typename octa::detail::DcFuncType::Type; + = typename detail::DcFuncType::Type; } /* namespace octa */ diff --git a/octa/initializer_list.hh b/octa/initializer_list.hh index 68bf543..4e9b8e0 100644 --- a/octa/initializer_list.hh +++ b/octa/initializer_list.hh @@ -39,13 +39,13 @@ namespace octa { template using InitializerList = std::initializer_list; template -octa::PointerRange iter(std::initializer_list init) { - return octa::PointerRange(init.begin(), init.end()); +PointerRange iter(std::initializer_list init) { + return PointerRange(init.begin(), init.end()); } template -octa::PointerRange citer(std::initializer_list init) { - return octa::PointerRange(init.begin(), init.end()); +PointerRange citer(std::initializer_list init) { + return PointerRange(init.begin(), init.end()); } } diff --git a/octa/internal/hashtable.hh b/octa/internal/hashtable.hh index abbe062..6f4e03d 100644 --- a/octa/internal/hashtable.hh +++ b/octa/internal/hashtable.hh @@ -24,15 +24,15 @@ namespace detail { }; template - static inline octa::Size estimate_hrsize(const R &range, - octa::EnableIf::value, bool> = true + static inline Size estimate_hrsize(const R &range, + EnableIf::value, bool> = true ) { return range.size(); } template - static inline octa::Size estimate_hrsize(const R &, - octa::EnableIf::value, bool> = true + static inline Size estimate_hrsize(const R &, + EnableIf::value, bool> = true ) { /* we have no idea how big the range actually is */ return 16; @@ -40,12 +40,12 @@ namespace detail { } template -struct HashRange: octa::InputRange, octa::ForwardRangeTag, T> { +struct HashRange: InputRange, ForwardRangeTag, T> { private: template friend struct HashRange; - using Chain = octa::detail::HashChain; + using Chain = detail::HashChain; Chain **p_beg; Chain **p_end; @@ -57,7 +57,7 @@ private: if (p_beg != p_end) p_node = p_beg[0]; } public: - HashRange() = delete; + HashRange(): p_beg(nullptr), p_end(nullptr), p_node(nullptr) {} HashRange(const HashRange &v): p_beg(v.p_beg), p_end(v.p_end), p_node(v.p_node) {} HashRange(Chain **beg, Chain **end): p_beg(beg), p_end(end), p_node() { @@ -67,9 +67,9 @@ public: p_node(node) {} template - HashRange(const HashRange &v, octa::EnableIf< - octa::IsSame, RemoveCv>::value && - octa::IsConvertible::value, bool + HashRange(const HashRange &v, EnableIf< + IsSame, RemoveCv>::value && + IsConvertible::value, bool > = true): p_beg((Chain **)v.p_beg), p_end((Chain **)v.p_end), p_node((Chain *)v.p_node) {} @@ -99,22 +99,22 @@ public: }; template -struct BucketRange: octa::InputRange, octa::ForwardRangeTag, T> { +struct BucketRange: InputRange, ForwardRangeTag, T> { private: template friend struct BucketRange; - using Chain = octa::detail::HashChain; + using Chain = detail::HashChain; Chain *p_node; public: - BucketRange() = delete; + BucketRange(): p_node(nullptr) {} BucketRange(Chain *node): p_node(node) {} BucketRange(const BucketRange &v): p_node(v.p_node) {} template - BucketRange(const BucketRange &v, octa::EnableIf< - octa::IsSame, RemoveCv>::value && - octa::IsConvertible::value, bool + BucketRange(const BucketRange &v, EnableIf< + IsSame, RemoveCv>::value && + IsConvertible::value, bool > = true): p_node((Chain *)v.p_node) {} BucketRange &operator=(const BucketRange &v) { @@ -149,51 +149,51 @@ namespace detail { bool Multihash > struct Hashtable { private: - static constexpr octa::Size CHUNKSIZE = 64; + static constexpr Size CHUNKSIZE = 64; - using Chain = octa::detail::HashChain; + using Chain = detail::HashChain; struct Chunk { Chain chains[CHUNKSIZE]; Chunk *next; }; - octa::Size p_size; - octa::Size p_len; + Size p_size; + Size p_len; Chunk *p_chunks; Chain *p_unused; - using CPA = octa::AllocatorRebind; - using CHA = octa::AllocatorRebind; + using CPA = AllocatorRebind; + using CHA = AllocatorRebind; - using CoreAllocPair = octa::detail::CompressedPair; - using AllocPair = octa::detail::CompressedPair; - using FuncPair = octa::detail::CompressedPair; - using FAPair = octa::detail::CompressedPair; - using DataPair = octa::detail::CompressedPair; + using CoreAllocPair = detail::CompressedPair; + using AllocPair = detail::CompressedPair; + using FuncPair = detail::CompressedPair; + using FAPair = detail::CompressedPair; + using DataPair = detail::CompressedPair; - using Range = octa::HashRange; - using ConstRange = octa::HashRange; - using LocalRange = octa::BucketRange; - using ConstLocalRange = octa::BucketRange; + using Range = HashRange; + using ConstRange = HashRange; + using LocalRange = BucketRange; + using ConstLocalRange = BucketRange; DataPair p_data; float p_maxlf; - Range iter_from(Chain *c, octa::Size h) { + Range iter_from(Chain *c, Size h) { return Range(p_data.first() + h + 1, p_data.first() + bucket_count(), c); } - ConstRange iter_from(Chain *c, octa::Size h) const { - using RChain = octa::detail::HashChain; + ConstRange iter_from(Chain *c, Size h) const { + using RChain = detail::HashChain; return ConstRange((RChain **)(p_data.first() + h + 1), (RChain **)(p_data.first() + bucket_count()), (RChain *)c); } - bool find(const K &key, octa::Size &h, Chain *&oc) const { + bool find(const K &key, Size &h, Chain *&oc) const { if (!p_size) return false; h = get_hash()(key) & (p_size - 1); for (Chain *c = p_data.first()[h]; c; c = c->next) { @@ -205,10 +205,10 @@ private: return false; } - Chain *insert(octa::Size h) { + Chain *insert(Size h) { if (!p_unused) { - Chunk *chunk = octa::allocator_allocate(get_challoc(), 1); - octa::allocator_construct(get_challoc(), chunk); + Chunk *chunk = allocator_allocate(get_challoc(), 1); + allocator_construct(get_challoc(), chunk); chunk->next = p_chunks; p_chunks = chunk; for (Size i = 0; i < (CHUNKSIZE - 1); ++i) @@ -227,12 +227,12 @@ private: void delete_chunks(Chunk *chunks) { for (Chunk *nc; chunks; chunks = nc) { nc = chunks->next; - octa::allocator_destroy(get_challoc(), chunks); - octa::allocator_deallocate(get_challoc(), chunks, 1); + allocator_destroy(get_challoc(), chunks); + allocator_deallocate(get_challoc(), chunks, 1); } } - T *access_base(const K &key, octa::Size &h) const { + T *access_base(const K &key, Size &h) const { if (!p_size) return NULL; h = get_hash()(key) & (p_size - 1); for (Chain *c = p_data.first()[h]; c; c = c->next) { @@ -242,23 +242,23 @@ private: return NULL; } - void rehash_ahead(octa::Size n) { + void rehash_ahead(Size n) { if (!bucket_count()) reserve(n); else if ((float(size() + n) / bucket_count()) > max_load_factor()) - rehash(octa::Size((size() + 1) / max_load_factor()) * 2); + rehash(Size((size() + 1) / max_load_factor()) * 2); } protected: template - T &insert(octa::Size h, U &&key) { + T &insert(Size h, U &&key) { Chain *c = insert(h); - B::set_key(c->value, octa::forward(key), get_alloc()); + B::set_key(c->value, forward(key), get_alloc()); return B::get_data(c->value); } T &access_or_insert(const K &key) { - octa::Size h = 0; + Size h = 0; T *v = access_base(key, h); if (v) return *v; rehash_ahead(1); @@ -266,22 +266,22 @@ protected: } T &access_or_insert(K &&key) { - octa::Size h = 0; + Size h = 0; T *v = access_base(key, h); if (v) return *v; rehash_ahead(1); - return insert(h, octa::move(key)); + return insert(h, move(key)); } T &access(const K &key) const { - octa::Size h; + Size h; return *access_base(key, h); } template void assign_range(R range) { clear(); - reserve_at_least(octa::detail::estimate_hrsize(range)); + reserve_at_least(detail::estimate_hrsize(range)); for (; !range.empty(); range.pop_front()) emplace(range.front()); rehash_up(); @@ -311,13 +311,13 @@ protected: return p_data.second().first().second().second(); } - Hashtable(octa::Size size, const H &hf, const C &eqf, const A &alloc): + Hashtable(Size size, const H &hf, const C &eqf, const A &alloc): p_size(size), p_len(0), p_chunks(nullptr), p_unused(nullptr), p_data(nullptr, FAPair(AllocPair(alloc, CoreAllocPair(alloc, alloc)), FuncPair(hf, eqf))), p_maxlf(1.0f) { if (!size) return; - p_data.first() = octa::allocator_allocate(get_cpalloc(), size); + p_data.first() = allocator_allocate(get_cpalloc(), size); memset(p_data.first(), 0, size * sizeof(Chain *)); } @@ -327,22 +327,22 @@ protected: FuncPair(ht.get_hash(), ht.get_eq()))), p_maxlf(ht.p_maxlf) { if (!p_size) return; - p_data.first() = octa::allocator_allocate(get_cpalloc(), p_size); + p_data.first() = allocator_allocate(get_cpalloc(), p_size); memset(p_data.first(), 0, p_size * sizeof(Chain *)); Chain **och = ht.p_data.first(); - for (octa::Size h = 0; h < p_size; ++h) { + for (Size h = 0; h < p_size; ++h) { Chain *oc = och[h]; for (; oc; oc = oc->next) { Chain *nc = insert(h); - octa::allocator_destroy(get_alloc(), &nc->value); - octa::allocator_construct(get_alloc(), &nc->value, oc->value); + allocator_destroy(get_alloc(), &nc->value); + allocator_construct(get_alloc(), &nc->value, oc->value); } } } Hashtable(Hashtable &&ht): p_size(ht.p_size), p_len(ht.p_len), p_chunks(ht.p_chunks), p_unused(ht.p_unused), - p_data(octa::move(ht.p_data)), p_maxlf(ht.p_maxlf) { + p_data(move(ht.p_data)), p_maxlf(ht.p_maxlf) { ht.p_size = ht.p_len = 0; ht.p_chunks = nullptr; ht.p_unused = nullptr; @@ -368,10 +368,10 @@ protected: p_len = 0; p_chunks = nullptr; p_unused = nullptr; - p_data.first() = octa::allocator_allocate(get_cpalloc(), p_size); + p_data.first() = allocator_allocate(get_cpalloc(), p_size); memset(p_data.first(), 0, p_size * sizeof(Chain *)); Chain **och = ht.p_data.first(); - for (octa::Size h = 0; h < p_size; ++h) { + for (Size h = 0; h < p_size; ++h) { Chain *oc = och[h]; for (; oc; oc = oc->next) { Chain *nc = insert(h); @@ -382,11 +382,11 @@ protected: Hashtable &operator=(const Hashtable &ht) { clear(); - if (octa::AllocatorPropagateOnContainerCopyAssignment::value) { + if (AllocatorPropagateOnContainerCopyAssignment::value) { if ((get_cpalloc() != ht.get_cpalloc()) && p_size) { - octa::allocator_deallocate(get_cpalloc(), + allocator_deallocate(get_cpalloc(), p_data.first(), p_size); - p_data.first() = octa::allocator_allocate(get_cpalloc(), + p_data.first() = allocator_allocate(get_cpalloc(), p_size); memset(p_data.first(), 0, p_size * sizeof(Chain *)); } @@ -407,18 +407,18 @@ protected: octa::swap(p_unused, ht.p_unused); octa::swap(p_data.first(), ht.p_data.first()); octa::swap(p_data.second().second(), ht.p_data.second().second()); - if (octa::AllocatorPropagateOnContainerMoveAssignment::value) + if (AllocatorPropagateOnContainerMoveAssignment::value) octa::swap(p_data.second().first(), ht.p_data.second().first()); return *this; } void rehash_up() { if (load_factor() <= max_load_factor()) return; - rehash(octa::Size(size() / max_load_factor()) * 2); + rehash(Size(size() / max_load_factor()) * 2); } - void reserve_at_least(octa::Size count) { - octa::Size nc = octa::Size(ceil(count / max_load_factor())); + void reserve_at_least(Size count) { + Size nc = Size(ceil(count / max_load_factor())); if (p_size > nc) return; rehash(nc); } @@ -430,13 +430,13 @@ protected: octa::swap(p_unused, ht.p_unused); octa::swap(p_data.first(), ht.p_data.first()); octa::swap(p_data.second().second(), ht.p_data.second().second()); - if (octa::AllocatorPropagateOnContainerSwap::value) + if (AllocatorPropagateOnContainerSwap::value) octa::swap(p_data.second().first(), ht.p_data.second().first()); } public: ~Hashtable() { - if (p_size) octa::allocator_deallocate(get_cpalloc(), + if (p_size) allocator_deallocate(get_cpalloc(), p_data.first(), p_size); delete_chunks(p_chunks); } @@ -454,18 +454,18 @@ public: } bool empty() const { return p_len == 0; } - octa::Size size() const { return p_len; } + Size size() const { return p_len; } Size max_size() const { return Size(~0) / sizeof(E); } - octa::Size bucket_count() const { return p_size; } - octa::Size max_bucket_count() const { return Size(~0) / sizeof(Chain); } + Size bucket_count() const { return p_size; } + Size max_bucket_count() const { return Size(~0) / sizeof(Chain); } - octa::Size bucket(const K &key) const { + Size bucket(const K &key) const { return get_hash()(key) & (p_size - 1); } - octa::Size bucket_size(octa::Size n) const { - octa::Size ret = 0; + Size bucket_size(Size n) const { + Size ret = 0; if (ret >= p_size) return ret; Chain *c = p_data.first()[n]; if (!c) return ret; @@ -475,16 +475,16 @@ public: } template - octa::Pair emplace(Args &&...args) { + Pair emplace(Args &&...args) { rehash_ahead(1); - E elem(octa::forward(args)...); - octa::Size h = get_hash()(B::get_key(elem)) & (p_size - 1); + E elem(forward(args)...); + Size h = get_hash()(B::get_key(elem)) & (p_size - 1); if (Multihash) { /* multihash: always insert */ Chain *ch = insert(h); B::swap_elem(ch->value, elem); Chain **hch = p_data.first(); - return octa::make_pair(Range(hch + h + 1, hch + bucket_count(), + return make_pair(Range(hch + h + 1, hch + bucket_count(), ch), true); } Chain *found = nullptr; @@ -501,14 +501,14 @@ public: B::swap_elem(found->value, elem); } Chain **hch = p_data.first(); - return octa::make_pair(Range(hch + h + 1, hch + bucket_count(), + return make_pair(Range(hch + h + 1, hch + bucket_count(), found), ins); } - octa::Size erase(const K &key) { + Size erase(const K &key) { if (!p_len) return 0; - octa::Size olen = p_len; - octa::Size h = get_hash()(key) & (p_size - 1); + Size olen = p_len; + Size h = get_hash()(key) & (p_size - 1); Chain **p = &p_data.first()[h], *c = *p; while (c) { if (get_eq()(key, B::get_key(c->value))) { @@ -516,8 +516,8 @@ public: *p = c->next; c->next = p_unused; p_unused = c; - octa::allocator_destroy(get_alloc(), &c->value); - octa::allocator_construct(get_alloc(), &c->value); + allocator_destroy(get_alloc(), &c->value); + allocator_construct(get_alloc(), &c->value); if (!Multihash) return 1; } else { p = &c->next; @@ -527,10 +527,10 @@ public: return olen - p_len; } - octa::Size count(const K &key) { + Size count(const K &key) { if (!p_len) return 0; - octa::Size h = get_hash()(key) & (p_size - 1); - octa::Size ret = 0; + Size h = get_hash()(key) & (p_size - 1); + Size ret = 0; for (Chain *c = p_data.first()[h]; c; c = c->next) if (get_eq()(key, B::get_key(c->value))) { ++ret; @@ -540,14 +540,14 @@ public: } Range find(const K &key) { - octa::Size h = 0; + Size h = 0; Chain *c; if (find(key, h, c)) return iter_from(c, h); return Range(); } ConstRange find(const K &key) const { - octa::Size h = 0; + Size h = 0; Chain *c; if (find(key, h, c)) return iter_from(c, h); return ConstRange(); @@ -557,21 +557,21 @@ public: float max_load_factor() const { return p_maxlf; } void max_load_factor(float lf) { p_maxlf = lf; } - void rehash(octa::Size count) { - octa::Size fbcount = octa::Size(p_len / max_load_factor()); + void rehash(Size count) { + Size fbcount = Size(p_len / max_load_factor()); if (fbcount > count) count = fbcount; Chain **och = p_data.first(); - Chain **nch = octa::allocator_allocate(get_cpalloc(), count); + Chain **nch = allocator_allocate(get_cpalloc(), count); memset(nch, 0, count * sizeof(Chain *)); p_data.first() = nch; - octa::Size osize = p_size; + Size osize = p_size; p_size = count; - for (octa::Size i = 0; i < osize; ++i) { + for (Size i = 0; i < osize; ++i) { for (Chain *oc = och[i]; oc;) { - octa::Size h = get_hash()(B::get_key(oc->value)) & (p_size - 1); + Size h = get_hash()(B::get_key(oc->value)) & (p_size - 1); Chain *nxc = oc->next; oc->next = nch[h]; nch[h] = oc; @@ -579,39 +579,39 @@ public: } } - if (och && osize) octa::allocator_deallocate(get_cpalloc(), + if (och && osize) allocator_deallocate(get_cpalloc(), och, osize); } - void reserve(octa::Size count) { - rehash(octa::Size(ceil(count / max_load_factor()))); + void reserve(Size count) { + rehash(Size(ceil(count / max_load_factor()))); } Range iter() { return Range(p_data.first(), p_data.first() + bucket_count()); } ConstRange iter() const { - using Chain = octa::detail::HashChain; + using Chain = detail::HashChain; return ConstRange((Chain **)p_data.first(), (Chain **)(p_data.first() + bucket_count())); } ConstRange citer() const { - using Chain = octa::detail::HashChain; + using Chain = detail::HashChain; return ConstRange((Chain **)p_data.first(), (Chain **)(p_data.first() + bucket_count())); } - LocalRange iter(octa::Size n) { + LocalRange iter(Size n) { if (n >= p_size) return LocalRange(); return LocalRange(p_data.first()[n]); } - ConstLocalRange iter(octa::Size n) const { - using Chain = octa::detail::HashChain; + ConstLocalRange iter(Size n) const { + using Chain = detail::HashChain; if (n >= p_size) return ConstLocalRange(); return ConstLocalRange((Chain *)p_data.first()[n]); } - ConstLocalRange citer(octa::Size n) const { - using Chain = octa::detail::HashChain; + ConstLocalRange citer(Size n) const { + using Chain = detail::HashChain; if (n >= p_size) return ConstLocalRange(); return ConstLocalRange((Chain *)p_data.first()[n]); } diff --git a/octa/io.hh b/octa/io.hh index 76b3ec7..4395e2d 100644 --- a/octa/io.hh +++ b/octa/io.hh @@ -39,7 +39,7 @@ struct FileStream: Stream { } template - FileStream(const octa::AnyString &path, StreamMode mode): p_f() { + FileStream(const AnyString &path, StreamMode mode): p_f() { open(path, mode); } @@ -56,13 +56,13 @@ struct FileStream: Stream { bool open(const char *path, StreamMode mode) { if (p_f) return false; - p_f = fopen(path, octa::detail::filemodes[octa::Size(mode)]); + p_f = fopen(path, detail::filemodes[Size(mode)]); p_owned = true; return is_open(); } template - bool open(const octa::AnyString &path, StreamMode mode) { + bool open(const AnyString &path, StreamMode mode) { return open(path.data(), mode); } @@ -104,11 +104,11 @@ struct FileStream: Stream { bool flush() { return !fflush(p_f); } - octa::Size read_bytes(void *buf, octa::Size count) { + Size read_bytes(void *buf, Size count) { return fread(buf, 1, count, p_f); } - octa::Size write_bytes(const void *buf, octa::Size count) { + Size write_bytes(const void *buf, Size count) { return fwrite(buf, 1, count, p_f); } @@ -147,46 +147,46 @@ static inline void write(const char *s) { } template -static inline void write(const octa::AnyString &s) { +static inline void write(const AnyString &s) { fwrite(s.data(), 1, s.size(), ::stdout); } template static inline void write(const T &v) { - octa::write(octa::to_string(v)); + write(octa::to_string(v)); } template static inline void write(const T &v, const A &...args) { - octa::write(v); + write(v); write(args...); } static inline void writeln(const char *s) { - octa::write(s); + write(s); putc('\n', ::stdout); } template -static inline void writeln(const octa::AnyString &s) { - octa::write(s); +static inline void writeln(const AnyString &s) { + write(s); putc('\n', ::stdout); } template static inline void writeln(const T &v) { - octa::writeln(octa::to_string(v)); + writeln(octa::to_string(v)); } template static inline void writeln(const T &v, const A &...args) { - octa::write(v); + write(v); write(args...); putc('\n', ::stdout); } namespace detail { - struct UnsafeWritefRange: octa::OutputRange { + struct UnsafeWritefRange: OutputRange { UnsafeWritefRange(char *p): p_ptr(p) {} bool put(char c) { *p_ptr++ = c; @@ -199,21 +199,21 @@ namespace detail { template static inline void writef(const char *fmt, const A &...args) { char buf[512]; - octa::Ptrdiff need = octa::format(octa::detail::FormatOutRange< - sizeof(buf)>(buf), fmt, args...); + Ptrdiff need = format(detail::FormatOutRange(buf), + fmt, args...); if (need < 0) return; - else if (octa::Size(need) < sizeof(buf)) { + else if (Size(need) < sizeof(buf)) { fwrite(buf, 1, need, ::stdout); return; } - octa::Vector s; + Vector s; s.reserve(need); - octa::format(octa::detail::UnsafeWritefRange(s.data()), fmt, args...); + format(detail::UnsafeWritefRange(s.data()), fmt, args...); fwrite(s.data(), 1, need, ::stdout); } template -static inline void writef(const octa::AnyString &fmt, +static inline void writef(const AnyString &fmt, const A &...args) { writef(fmt.data(), args...); } @@ -225,7 +225,7 @@ static inline void writefln(const char *fmt, const A &...args) { } template -static inline void writefln(const octa::AnyString &fmt, +static inline void writefln(const AnyString &fmt, const A &...args) { writef(fmt, args...); putc('\n', ::stdout); diff --git a/octa/map.hh b/octa/map.hh index 7adc8ac..5efe30f 100644 --- a/octa/map.hh +++ b/octa/map.hh @@ -18,7 +18,7 @@ namespace octa { namespace detail { template struct MapBase { - using Element = octa::Pair; + using Element = Pair; static inline const K &get_key(Element &e) { return e.first; @@ -28,9 +28,8 @@ namespace detail { } template static inline void set_key(Element &e, U &&key, A &alloc) { - octa::allocator_destroy(alloc, &e); - octa::allocator_construct(alloc, &e, octa::forward(key), - octa::move(T())); + allocator_destroy(alloc, &e); + allocator_construct(alloc, &e, forward(key), move(T())); } static inline void swap_elem(Element &a, Element &b) { octa::swap(*((K *)&a.first), *((K *)&b.first)); @@ -41,59 +40,57 @@ namespace detail { template< typename K, typename T, typename H, typename C, typename A, bool IsMultihash - > struct MapImpl: octa::detail::Hashtable< - octa::detail::MapBase, octa::Pair, - K, T, H, C, A, IsMultihash + > struct MapImpl: detail::Hashtable, + Pair, K, T, H, C, A, IsMultihash > { private: - using Base = octa::detail::Hashtable< - octa::detail::MapBase, octa::Pair, - K, T, H, C, A, IsMultihash + using Base = detail::Hashtable, + Pair, K, T, H, C, A, IsMultihash >; public: using Key = K; using Mapped = T; - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Hasher = H; using KeyEqual = C; - using Value = octa::Pair; + using Value = Pair; using Reference = Value &; - using Pointer = octa::AllocatorPointer; - using ConstPointer = octa::AllocatorConstPointer; - using Range = octa::HashRange>; - using ConstRange = octa::HashRange>; - using LocalRange = octa::BucketRange>; - using ConstLocalRange = octa::BucketRange>; + using Pointer = AllocatorPointer; + using ConstPointer = AllocatorConstPointer; + using Range = HashRange>; + using ConstRange = HashRange>; + using LocalRange = BucketRange>; + using ConstLocalRange = BucketRange>; using Allocator = A; - explicit MapImpl(octa::Size size, const H &hf = H(), + explicit MapImpl(Size size, const H &hf = H(), const C &eqf = C(), const A &alloc = A() ): Base(size, hf, eqf, alloc) {} MapImpl(): MapImpl(0) {} explicit MapImpl(const A &alloc): MapImpl(0, H(), C(), alloc) {} - MapImpl(octa::Size size, const A &alloc): + MapImpl(Size size, const A &alloc): MapImpl(size, H(), C(), alloc) {} - MapImpl(octa::Size size, const H &hf, const A &alloc): + MapImpl(Size size, const H &hf, const A &alloc): MapImpl(size, hf, C(), alloc) {} MapImpl(const MapImpl &m): Base(m, - octa::allocator_container_copy(m.get_alloc())) {} + allocator_container_copy(m.get_alloc())) {} MapImpl(const MapImpl &m, const A &alloc): Base(m, alloc) {} - MapImpl(MapImpl &&m): Base(octa::move(m)) {} - MapImpl(MapImpl &&m, const A &alloc): Base(octa::move(m), alloc) {} + MapImpl(MapImpl &&m): Base(move(m)) {} + MapImpl(MapImpl &&m, const A &alloc): Base(move(m), alloc) {} - template::value && - octa::IsConvertible, Value>::value - >> MapImpl(R range, octa::Size size = 0, const H &hf = H(), + template::value && IsConvertible, + Value>::value + >> MapImpl(R range, Size size = 0, const H &hf = H(), const C &eqf = C(), const A &alloc = A() - ): Base(size ? size : octa::detail::estimate_hrsize(range), + ): Base(size ? size : detail::estimate_hrsize(range), hf, eqf, alloc) { for (; !range.empty(); range.pop_front()) Base::emplace(range.front()); @@ -101,23 +98,23 @@ namespace detail { } template - MapImpl(R range, octa::Size size, const A &alloc) + MapImpl(R range, Size size, const A &alloc) : MapImpl(range, size, H(), C(), alloc) {} template - MapImpl(R range, octa::Size size, const H &hf, const A &alloc) + MapImpl(R range, Size size, const H &hf, const A &alloc) : MapImpl(range, size, hf, C(), alloc) {} - MapImpl(octa::InitializerList init, octa::Size size = 0, + MapImpl(InitializerList init, Size size = 0, const H &hf = H(), const C &eqf = C(), const A &alloc = A() - ): MapImpl(octa::iter(init), size, hf, eqf, alloc) {} + ): MapImpl(iter(init), size, hf, eqf, alloc) {} - MapImpl(octa::InitializerList init, octa::Size size, const A &alloc) - : MapImpl(octa::iter(init), size, H(), C(), alloc) {} + MapImpl(InitializerList init, Size size, const A &alloc) + : MapImpl(iter(init), size, H(), C(), alloc) {} - MapImpl(octa::InitializerList init, octa::Size size, const H &hf, + MapImpl(InitializerList init, Size size, const H &hf, const A &alloc - ): MapImpl(octa::iter(init), size, hf, C(), alloc) {} + ): MapImpl(iter(init), size, hf, C(), alloc) {} MapImpl &operator=(const MapImpl &m) { Base::operator=(m); @@ -125,13 +122,13 @@ namespace detail { } MapImpl &operator=(MapImpl &&m) { - Base::operator=(octa::move(m)); + Base::operator=(move(m)); return *this; } - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> MapImpl &operator=(R range) { Base::assign_range(range); return *this; @@ -157,7 +154,7 @@ namespace detail { } T &operator[](K &&key) { static_assert(!IsMultihash, "operator[] only allowed on regular maps"); - return Base::access_or_insert(octa::move(key)); + return Base::access_or_insert(move(key)); } void swap(MapImpl &v) { @@ -168,17 +165,17 @@ namespace detail { template< typename K, typename T, - typename H = octa::ToHash, - typename C = octa::Equal, - typename A = octa::Allocator> -> using Map = octa::detail::MapImpl; + typename H = ToHash, + typename C = Equal, + typename A = Allocator> +> using Map = detail::MapImpl; template< typename K, typename T, - typename H = octa::ToHash, - typename C = octa::Equal, - typename A = octa::Allocator> -> using Multimap = octa::detail::MapImpl; + typename H = ToHash, + typename C = Equal, + typename A = Allocator> +> using Multimap = detail::MapImpl; } /* namespace octa */ diff --git a/octa/maybe.hh b/octa/maybe.hh index 445a057..ec37f36 100644 --- a/octa/maybe.hh +++ b/octa/maybe.hh @@ -24,7 +24,7 @@ struct Nothing { constexpr Nothing nothing = Nothing(0); namespace detail { - template::value> + template::value> class MaybeStorage { protected: using Value = T; @@ -37,19 +37,19 @@ namespace detail { constexpr MaybeStorage(): p_null_state('\0') {} MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) { - if (p_engaged) ::new(octa::address_of(p_value)) Value(v.p_value); + if (p_engaged) ::new(address_of(p_value)) Value(v.p_value); } MaybeStorage(MaybeStorage &&v): p_engaged(v.p_engaged) { if (p_engaged) - ::new(octa::address_of(p_value)) Value(octa::move(v.p_value)); + ::new(address_of(p_value)) Value(move(v.p_value)); } constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {} - constexpr MaybeStorage(Value &&v): p_value(octa::move(v)), p_engaged(true) {} + constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {} - template constexpr MaybeStorage(octa::InPlace, A &&...args): - p_value(octa::forward(args)...), p_engaged(true) {} + template constexpr MaybeStorage(InPlace, A &&...args): + p_value(forward(args)...), p_engaged(true) {} ~MaybeStorage() { if (p_engaged) p_value.~Value(); @@ -69,58 +69,58 @@ namespace detail { constexpr MaybeStorage(): p_null_state('\0') {} MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) { - if (p_engaged) ::new(octa::address_of(p_value)) Value(v.p_value); + if (p_engaged) ::new(address_of(p_value)) Value(v.p_value); } MaybeStorage(MaybeStorage &&v): p_engaged(v.p_engaged) { if (p_engaged) - ::new(octa::address_of(p_value)) Value(octa::move(v.p_value)); + ::new(address_of(p_value)) Value(move(v.p_value)); } constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {} constexpr MaybeStorage(Value &&v): - p_value(octa::move(v)), p_engaged(true) {} + p_value(move(v)), p_engaged(true) {} template - constexpr MaybeStorage(octa::InPlace, A &&...args): - p_value(octa::forward(args)...), p_engaged(true) {} + constexpr MaybeStorage(InPlace, A &&...args): + p_value(forward(args)...), p_engaged(true) {} }; } template -class Maybe: private octa::detail::MaybeStorage { - using Base = octa::detail::MaybeStorage; +class Maybe: private detail::MaybeStorage { + using Base = detail::MaybeStorage; public: using Value = T; - static_assert(!octa::IsReference::value, + static_assert(!IsReference::value, "Initialization of Maybe with a reference type is not allowed."); - static_assert(!octa::IsSame, octa::InPlace>::value, + static_assert(!IsSame, InPlace>::value, "Initialization of Maybe with InPlace is not allowed."); - static_assert(!octa::IsSame, octa::Nothing>::value, + static_assert(!IsSame, Nothing>::value, "Initialization of Maybe with Nothing is not allowed."); - static_assert(octa::IsObject::value, + static_assert(IsObject::value, "Initialization of Maybe with non-object type is not allowed."); - static_assert(octa::IsDestructible::value, + static_assert(IsDestructible::value, "Initialization of Maybe with a non-destructible object is not allowed."); constexpr Maybe() {} Maybe(const Maybe &) = default; Maybe(Maybe &&) = default; - constexpr Maybe(octa::Nothing) {} + constexpr Maybe(Nothing) {} constexpr Maybe(const Value &v): Base(v) {} - constexpr Maybe(Value &&v): Base(octa::move(v)) {} + constexpr Maybe(Value &&v): Base(move(v)) {} - template::value>> - constexpr explicit Maybe(octa::InPlace, A &&...args): Base(octa::in_place, - octa::forward(args)...) {} + template::value>> + constexpr explicit Maybe(InPlace, A &&...args): Base(in_place, + forward(args)...) {} - template &, A...>::value>> + template &, A...>::value>> constexpr explicit - Maybe(octa::InPlace, std::initializer_list il, A &&...args): - Base(octa::in_place, il, octa::forward(args)...) {} + Maybe(InPlace, std::initializer_list il, A &&...args): + Base(in_place, il, forward(args)...) {} ~Maybe() = default; @@ -139,7 +139,7 @@ public: if (this->p_engaged) this->p_value.~Value(); else - ::new(octa::address_of(this->p_value)) Value(v.p_value); + ::new(address_of(this->p_value)) Value(v.p_value); this->p_engaged = v.p_engaged; } return *this; @@ -147,60 +147,58 @@ public: Maybe &operator=(Maybe &&v) { if (this->p_engaged == v.p_engaged) { - if (this->p_engaged) this->p_value = octa::move(v.p_value); + if (this->p_engaged) this->p_value = move(v.p_value); } else { if (this->p_engaged) this->p_value.~Value(); else { - ::new(octa::address_of(this->p_value)) - Value(octa::move(v.p_value)); + ::new(address_of(this->p_value)) Value(move(v.p_value)); } this->p_engaged = v.p_engaged; } return *this; } - template, Value>::value && - octa::IsConstructible::value && - octa::IsAssignable::value + template, Value>::value && + IsConstructible::value && + IsAssignable::value >> Maybe &operator=(U &&v) { if (this->p_engaged) { - this->p_value = octa::forward(v); + this->p_value = forward(v); } else { - ::new(octa::address_of(this->p_value)) Value(octa::forward(v)); + ::new(address_of(this->p_value)) Value(forward(v)); this->p_engaged = true; } return *this; } - template::value + template::value >> void emplace(A &&...args) { - *this = octa::nothing; - ::new(octa::address_of(this->p_value)) - Value(octa::forward(args)...); + *this = nothing; + ::new(address_of(this->p_value)) Value(forward(args)...); this->p_engaged = true; } - template &, A...>::value + template &, A...>::value >> void emplace(std::initializer_list il, A &&...args) { - *this = octa::nothing; - ::new(octa::address_of(this->p_value)) - Value(il, octa::forward(args)...); + *this = nothing; + ::new(address_of(this->p_value)) + Value(il, forward(args)...); this->p_engaged = true; } constexpr const Value *operator->() const { - return octa::address_of(this->p_value); + return address_of(this->p_value); } Value *operator->() { - return octa::address_of(this->p_value); + return address_of(this->p_value); } constexpr const Value &operator*() const { @@ -223,21 +221,21 @@ public: template constexpr Value value_or(U &&v) const & { - static_assert(octa::IsCopyConstructible::value, + static_assert(IsCopyConstructible::value, "Maybe::value_or: T must be copy constructible"); - static_assert(octa::IsConvertible::value, + static_assert(IsConvertible::value, "Maybe::value_or: U must be convertible to T"); - return this->p_engaged ? this->p_value : Value(octa::forward(v)); + return this->p_engaged ? this->p_value : Value(forward(v)); } template Value value_or(U &&v) && { - static_assert(octa::IsMoveConstructible::value, + static_assert(IsMoveConstructible::value, "Maybe::value_or: T must be copy constructible"); - static_assert(octa::IsConvertible::value, + static_assert(IsConvertible::value, "Maybe::value_or: U must be convertible to T"); - return this->p_engaged ? octa::move(this->p_value) - : Value(octa::forward(v)); + return this->p_engaged ? move(this->p_value) + : Value(forward(v)); } void swap(Maybe &v) { @@ -245,19 +243,17 @@ public: if (this->p_engaged) octa::swap(this->p_value, v.p_value); } else { if (this->p_engaged) { - ::new(octa::address_of(v.p_value)) - Value(octa::move(this->p_value)); + ::new(address_of(v.p_value)) Value(move(this->p_value)); this->p_value.~Value(); } else { - ::new(octa::address_of(this->p_value)) - Value(octa::move(v.p_value)); + ::new(address_of(this->p_value)) Value(move(v.p_value)); v.p_value.~Value(); } octa::swap(this->p_engaged, v.p_engaged); } } - octa::Size to_hash() const { + Size to_hash() const { return this->p_engaged ? octa::ToHash()(this->p_value) : 0; } }; @@ -380,12 +376,12 @@ static inline constexpr bool operator!=(const T &b, const Maybe &a) { template static inline constexpr bool operator<(const Maybe &a, const T &b) { - return bool(a) ? octa::Less()(*a, b) : true; + return bool(a) ? Less()(*a, b) : true; } template static inline constexpr bool operator<(const T &b, const Maybe &a) { - return bool(a) ? octa::Less()(b, *a) : false; + return bool(a) ? Less()(b, *a) : false; } template @@ -421,8 +417,8 @@ static inline constexpr bool operator>=(const T &b, const Maybe &a) { /* make maybe */ template -constexpr Maybe> make_maybe(T &&v) { - return Maybe>(octa::forward(v)); +constexpr Maybe> make_maybe(T &&v) { + return Maybe>(forward(v)); } } /* namespace octa */ diff --git a/octa/memory.hh b/octa/memory.hh index b6a66df..9e447ea 100644 --- a/octa/memory.hh +++ b/octa/memory.hh @@ -68,7 +68,7 @@ namespace detail { template::value> struct PointerDifferenceBase { - using Type = octa::Ptrdiff; + using Type = Ptrdiff; }; template struct PointerDifferenceBase { @@ -82,7 +82,7 @@ namespace detail { template struct PointerDifferenceType { - using Type = octa::Ptrdiff; + using Type = Ptrdiff; }; template @@ -135,16 +135,16 @@ namespace detail { } /*namespace detail */ template -using Pointer = typename octa::detail::PointerPointer::Type; +using Pointer = typename detail::PointerPointer::Type; template -using PointerElement = typename octa::detail::PointerElementType::Type; +using PointerElement = typename detail::PointerElementType::Type; template -using PointerDifference = typename octa::detail::PointerDifferenceType::Type; +using PointerDifference = typename detail::PointerDifferenceType::Type; template -using PointerRebind = typename octa::detail::PointerRebindType::Type; +using PointerRebind = typename detail::PointerRebindType::Type; /* pointer to */ @@ -153,8 +153,7 @@ namespace detail { template struct PointerTo { - static T pointer_to(octa::Conditional< - octa::IsVoid>::value, + static T pointer_to(Conditional>::value, PointerToNat, PointerElement > &r) { return T::pointer_to(r); @@ -163,20 +162,19 @@ namespace detail { template struct PointerTo { - static T pointer_to(octa::Conditional< - octa::IsVoid::value, PointerToNat, T + static T pointer_to(Conditional::value, + PointerToNat, T > &r) { - return octa::address_of(r); + return address_of(r); } }; } template -static T pointer_to(octa::Conditional< - octa::IsVoid>::value, - octa::detail::PointerToNat, PointerElement +static T pointer_to(Conditional>::value, + detail::PointerToNat, PointerElement > &r) { - return octa::detail::PointerTo::pointer_to(r); + return detail::PointerTo::pointer_to(r); } /* default deleter */ @@ -212,7 +210,7 @@ namespace detail { template static char ptr_test(typename T::Pointer * = 0); - template struct HasPtr: octa::IntegralConstant struct HasPtr: IntegralConstant(0)) == 1) > {}; @@ -226,7 +224,7 @@ namespace detail { }; template struct PointerType { - using Type = typename PointerBase>::Type; + using Type = typename PointerBase>::Type; }; } /* namespace detail */ @@ -234,7 +232,7 @@ template> struct Box { using Element = T; using Deleter = D; - using Pointer = typename octa::detail::PointerType::Type; + using Pointer = typename detail::PointerType::Type; private: struct Nat { int x; }; @@ -244,63 +242,63 @@ private: public: constexpr Box(): p_stor(nullptr, D()) { - static_assert(!octa::IsPointer::value, + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } - constexpr Box(octa::Nullptr): p_stor(nullptr, D()) { - static_assert(!octa::IsPointer::value, + constexpr Box(Nullptr): p_stor(nullptr, D()) { + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } explicit Box(Pointer p): p_stor(p, D()) { - static_assert(!octa::IsPointer::value, + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } - Box(Pointer p, octa::Conditional::value, - D, octa::AddLvalueReference + Box(Pointer p, Conditional::value, + D, AddLvalueReference > d): p_stor(p, d) {} - Box(Pointer p, octa::RemoveReference &&d): - p_stor(p, octa::move(d)) { - static_assert(!octa::IsReference::value, + Box(Pointer p, RemoveReference &&d): + p_stor(p, move(d)) { + static_assert(!IsReference::value, "rvalue deleter cannot be a ref"); } - Box(Box &&u): p_stor(u.release(), octa::forward(u.get_deleter())) {} + Box(Box &&u): p_stor(u.release(), forward(u.get_deleter())) {} template - Box(Box &&u, octa::EnableIf::value - && octa::IsConvertible::Pointer, Pointer>::value - && octa::IsConvertible::value - && (!octa::IsReference::value || octa::IsSame::value) - > = Nat()): p_stor(u.release(), octa::forward
(u.get_deleter())) {} + Box(Box &&u, EnableIf::value + && IsConvertible::Pointer, Pointer>::value + && IsConvertible::value + && (!IsReference::value || IsSame::value) + > = Nat()): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { reset(u.release()); - p_stor.second() = octa::forward(u.get_deleter()); + p_stor.second() = forward(u.get_deleter()); return *this; } template - EnableIf::value - && octa::IsConvertible::Pointer, Pointer>::value - && octa::IsAssignable::value, + EnableIf::value + && IsConvertible::Pointer, Pointer>::value + && IsAssignable::value, Box & > operator=(Box &&u) { reset(u.release()); - p_stor.second() = octa::forward
(u.get_deleter()); + p_stor.second() = forward
(u.get_deleter()); return *this; } - Box &operator=(octa::Nullptr) { + Box &operator=(Nullptr) { reset(); return *this; } ~Box() { reset(); } - octa::AddLvalueReference operator*() const { return *p_stor.first(); } + AddLvalueReference operator*() const { return *p_stor.first(); } Pointer operator->() const { return p_stor.first(); } explicit operator bool() const { @@ -329,31 +327,31 @@ public: } private: - octa::detail::CompressedPair p_stor; + detail::CompressedPair p_stor; }; namespace detail { - template>, - octa::RemoveCv> - >::value> struct SameOrLessCvQualifiedBase: octa::IsConvertible {}; + template>, + RemoveCv> + >::value> struct SameOrLessCvQualifiedBase: IsConvertible {}; template - struct SameOrLessCvQualifiedBase: octa::False {}; + struct SameOrLessCvQualifiedBase: False {}; - template::value - || octa::IsSame::value || octa::detail::HasElement::value + template::value + || IsSame::value || detail::HasElement::value > struct SameOrLessCvQualified: SameOrLessCvQualifiedBase {}; template - struct SameOrLessCvQualified: octa::False {}; + struct SameOrLessCvQualified: False {}; } /* namespace detail */ template struct Box { using Element = T; using Deleter = D; - using Pointer = typename octa::detail::PointerType::Type; + using Pointer = typename detail::PointerType::Type; private: struct Nat { int x; }; @@ -363,82 +361,82 @@ private: public: constexpr Box(): p_stor(nullptr, D()) { - static_assert(!octa::IsPointer::value, + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } - constexpr Box(octa::Nullptr): p_stor(nullptr, D()) { - static_assert(!octa::IsPointer::value, + constexpr Box(Nullptr): p_stor(nullptr, D()) { + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } - template explicit Box(U p, octa::EnableIf< - octa::detail::SameOrLessCvQualified::value, Nat + template explicit Box(U p, EnableIf< + detail::SameOrLessCvQualified::value, Nat > = Nat()): p_stor(p, D()) { - static_assert(!octa::IsPointer::value, + static_assert(!IsPointer::value, "Box constructed with null fptr deleter"); } - template Box(U p, octa::Conditional< - octa::IsReference::value, + template Box(U p, Conditional< + IsReference::value, D, AddLvalueReference - > d, octa::EnableIf::value, + > d, EnableIf::value, Nat> = Nat()): p_stor(p, d) {} - Box(octa::Nullptr, octa::Conditional::value, + Box(Nullptr, Conditional::value, D, AddLvalueReference > d): p_stor(nullptr, d) {} - template Box(U p, octa::RemoveReference &&d, - octa::EnableIf< - octa::detail::SameOrLessCvQualified::value, Nat - > = Nat()): p_stor(p, octa::move(d)) { - static_assert(!octa::IsReference::value, + template Box(U p, RemoveReference &&d, + EnableIf< + detail::SameOrLessCvQualified::value, Nat + > = Nat()): p_stor(p, move(d)) { + static_assert(!IsReference::value, "rvalue deleter cannot be a ref"); } - Box(octa::Nullptr, octa::RemoveReference &&d): - p_stor(nullptr, octa::move(d)) { - static_assert(!octa::IsReference::value, + Box(Nullptr, RemoveReference &&d): + p_stor(nullptr, move(d)) { + static_assert(!IsReference::value, "rvalue deleter cannot be a ref"); } - Box(Box &&u): p_stor(u.release(), octa::forward(u.get_deleter())) {} + Box(Box &&u): p_stor(u.release(), forward(u.get_deleter())) {} template Box(Box &&u, EnableIf::value - && octa::detail::SameOrLessCvQualified::Pointer, - Pointer>::value - && octa::IsConvertible::value - && (!octa::IsReference::value || - octa::IsSame::value)> = Nat() - ): p_stor(u.release(), octa::forward
(u.get_deleter())) {} + && detail::SameOrLessCvQualified::Pointer, + Pointer>::value + && IsConvertible::value + && (!IsReference::value || + IsSame::value)> = Nat() + ): p_stor(u.release(), forward
(u.get_deleter())) {} Box &operator=(Box &&u) { reset(u.release()); - p_stor.second() = octa::forward(u.get_deleter()); + p_stor.second() = forward(u.get_deleter()); return *this; } template - EnableIf::value - && octa::detail::SameOrLessCvQualified::Pointer, - Pointer>::value + EnableIf::value + && detail::SameOrLessCvQualified::Pointer, + Pointer>::value && IsAssignable::value, Box & > operator=(Box &&u) { reset(u.release()); - p_stor.second() = octa::forward
(u.get_deleter()); + p_stor.second() = forward
(u.get_deleter()); return *this; } - Box &operator=(octa::Nullptr) { + Box &operator=(Nullptr) { reset(); return *this; } ~Box() { reset(); } - octa::AddLvalueReference operator[](octa::Size idx) const { + AddLvalueReference operator[](Size idx) const { return p_stor.first()[idx]; } @@ -458,14 +456,14 @@ public: } template EnableIf< - octa::detail::SameOrLessCvQualified::value, void + detail::SameOrLessCvQualified::value, void > reset(U p) { Pointer tmp = p_stor.first(); p_stor.first() = p; if (tmp) p_stor.second()(tmp); } - void reset(octa::Nullptr) { + void reset(Nullptr) { Pointer tmp = p_stor.first(); p_stor.first() = nullptr; if (tmp) p_stor.second()(tmp); @@ -480,35 +478,35 @@ public: } private: - octa::detail::CompressedPair p_stor; + detail::CompressedPair p_stor; }; namespace detail { template struct BoxIf { - using Box = octa::Box; + using Box = Box; }; template struct BoxIf { - using BoxUnknownSize = octa::Box; + using BoxUnknownSize = Box; }; - template struct BoxIf { + template struct BoxIf { using BoxKnownSize = void; }; } template -typename octa::detail::BoxIf::Box make_box(A &&...args) { - return Box(new T(octa::forward(args)...)); +typename detail::BoxIf::Box make_box(A &&...args) { + return Box(new T(forward(args)...)); } template -typename octa::detail::BoxIf::BoxUnknownSize make_box(octa::Size n) { - return Box(new octa::RemoveExtent[n]()); +typename detail::BoxIf::BoxUnknownSize make_box(Size n) { + return Box(new RemoveExtent[n]()); } template -typename octa::detail::BoxIf::BoxKnownSize make_box(A &&...args) = delete; +typename detail::BoxIf::BoxKnownSize make_box(A &&...args) = delete; /* allocator */ @@ -531,8 +529,8 @@ template<> struct Allocator { }; template struct Allocator { - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Value = T; using Reference = T &; using ConstReference = const T &; @@ -554,22 +552,22 @@ template struct Allocator { Size max_size() const { return Size(~0) / sizeof(T); } Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return (Pointer) ::new octa::byte[n * sizeof(T)]; + return (Pointer) ::new byte[n * sizeof(T)]; } - void deallocate(Pointer p, Size) { ::delete[] (octa::byte *) p; } + void deallocate(Pointer p, Size) { ::delete[] (byte *) p; } template void construct(U *p, A &&...args) { - ::new((void *)p) U(octa::forward(args)...); + ::new((void *)p) U(forward(args)...); } void destroy(Pointer p) { p->~T(); } }; template struct Allocator { - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Value = const T; using Reference = const T &; using ConstReference = const T &; @@ -588,14 +586,14 @@ template struct Allocator { Size max_size() const { return Size(~0) / sizeof(T); } Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return (Pointer) ::new octa::byte[n * sizeof(T)]; + return (Pointer) ::new byte[n * sizeof(T)]; } - void deallocate(Pointer p, Size) { ::delete[] (octa::byte *) p; } + void deallocate(Pointer p, Size) { ::delete[] (byte *) p; } template void construct(U *p, A &&...args) { - ::new((void *)p) U(octa::forward(args)...); + ::new((void *)p) U(forward(args)...); } void destroy(Pointer p) { p->~T(); } @@ -678,7 +676,7 @@ namespace detail { template::value> struct SizeBase { - using Type = octa::MakeUnsigned; + using Type = MakeUnsigned; }; template @@ -696,22 +694,22 @@ template using AllocatorValue = typename AllocatorType::Value; template -using AllocatorPointer = typename octa::detail::PointerType< +using AllocatorPointer = typename detail::PointerType< AllocatorValue, AllocatorType >::Type; template -using AllocatorConstPointer = typename octa::detail::ConstPointer< +using AllocatorConstPointer = typename detail::ConstPointer< AllocatorValue, AllocatorPointer, AllocatorType >::Type; template -using AllocatorVoidPointer = typename octa::detail::VoidPointer< +using AllocatorVoidPointer = typename detail::VoidPointer< AllocatorPointer, AllocatorType >::Type; template -using AllocatorConstVoidPointer = typename octa::detail::ConstVoidPointer< +using AllocatorConstVoidPointer = typename detail::ConstVoidPointer< AllocatorPointer, AllocatorType >::Type; @@ -737,21 +735,21 @@ namespace detail { } template -using AllocatorDifference = typename octa::detail::AllocDifference< +using AllocatorDifference = typename detail::AllocDifference< A, AllocatorPointer >::Type; /* allocator size */ template -using AllocatorSize = typename octa::detail::SizeBase< +using AllocatorSize = typename detail::SizeBase< A, AllocatorDifference >::Type; /* allocator rebind */ namespace detail { - template::value> + template::value> struct AllocTraitsRebindType { using Type = typename T::template Rebind; }; @@ -772,7 +770,7 @@ namespace detail { } /* namespace detail */ template -using AllocatorRebind = typename octa::detail::AllocTraitsRebindType< +using AllocatorRebind = typename detail::AllocTraitsRebindType< AllocatorType, T >::Type; @@ -790,7 +788,7 @@ namespace detail { template::value> struct PropagateOnContainerCopyAssignmentBase { - using Type = octa::False; + using Type = False; }; template @@ -801,7 +799,7 @@ namespace detail { template using AllocatorPropagateOnContainerCopyAssignment - = typename octa::detail::PropagateOnContainerCopyAssignmentBase::Type; + = typename detail::PropagateOnContainerCopyAssignmentBase::Type; /* allocator propagate on container move assignment */ @@ -817,7 +815,7 @@ namespace detail { template::value> struct PropagateOnContainerMoveAssignmentBase { - using Type = octa::False; + using Type = False; }; template @@ -828,7 +826,7 @@ namespace detail { template using AllocatorPropagateOnContainerMoveAssignment - = typename octa::detail::PropagateOnContainerMoveAssignmentBase::Type; + = typename detail::PropagateOnContainerMoveAssignmentBase::Type; /* allocator propagate on container swap */ @@ -843,7 +841,7 @@ namespace detail { template::value> struct PropagateOnContainerSwapBase { - using Type = octa::False; + using Type = False; }; template @@ -854,7 +852,7 @@ namespace detail { template using AllocatorPropagateOnContainerSwap - = typename octa::detail::PropagateOnContainerSwapBase::Type; + = typename detail::PropagateOnContainerSwapBase::Type; /* allocator is always equal */ @@ -868,7 +866,7 @@ namespace detail { template::value> struct IsAlwaysEqualBase { - using Type = typename octa::IsEmpty::Type; + using Type = typename IsEmpty::Type; }; template @@ -878,7 +876,7 @@ namespace detail { } /* namespace detail */ template -using AllocatorIsAlwaysEqual = typename octa::detail::IsAlwaysEqualBase::Type; +using AllocatorIsAlwaysEqual = typename detail::IsAlwaysEqualBase::Type; /* allocator allocate */ @@ -891,33 +889,31 @@ allocator_allocate(A &a, AllocatorSize n) { namespace detail { template auto allocate_hint_test(A &&a, S &&sz, CVP &&p) - -> decltype(a.allocate(sz, p), octa::True()); + -> decltype(a.allocate(sz, p), True()); template auto allocate_hint_test(const A &, S &&, CVP &&) - -> octa::False; + -> False; template - struct AllocateHintTest: octa::IntegralConstant(), - octa::declval(), - octa::declval())), - octa::True + struct AllocateHintTest: IntegralConstant(), + declval(), + declval())), True >::value > {}; template inline AllocatorPointer allocate(A &a, AllocatorSize n, AllocatorConstVoidPointer h, - octa::True) { + True) { return a.allocate(n, h); } template inline AllocatorPointer allocate(A &a, AllocatorSize n, AllocatorConstVoidPointer, - octa::False) { + False) { return a.allocate(n); } } /* namespace detail */ @@ -926,8 +922,8 @@ template inline AllocatorPointer allocator_allocate(A &a, AllocatorSize n, AllocatorConstVoidPointer h) { - return octa::detail::allocate(a, n, h, - octa::detail::AllocateHintTest< + return detail::allocate(a, n, h, + detail::AllocateHintTest< A, AllocatorSize, AllocatorConstVoidPointer >()); } @@ -945,139 +941,129 @@ inline void allocator_deallocate(A &a, AllocatorPointer p, namespace detail { template auto construct_test(A &&a, T *p, Args &&...args) - -> decltype(a.construct(p, octa::forward(args)...), - octa::True()); + -> decltype(a.construct(p, forward(args)...), + True()); template auto construct_test(const A &, T *, Args &&...) - -> octa::False; + -> False; template - struct ConstructTest: octa::IntegralConstant(), - octa::declval(), - octa::declval()...)), - octa::True + struct ConstructTest: IntegralConstant(), + declval(), + declval()...)), True >::value > {}; template - inline void construct(octa::True, A &a, T *p, Args &&...args) { - a.construct(p, octa::forward(args)...); + inline void construct(True, A &a, T *p, Args &&...args) { + a.construct(p, forward(args)...); } template - inline void construct(octa::False, A &, T *p, Args &&...args) { - ::new ((void *)p) T(octa::forward(args)...); + inline void construct(False, A &, T *p, Args &&...args) { + ::new ((void *)p) T(forward(args)...); } } /* namespace detail */ template inline void allocator_construct(A &a, T *p, Args &&...args) { - octa::detail::construct(octa::detail::ConstructTest< - A, T *, Args... - >(), a, p, octa::forward(args)...); + detail::construct(detail::ConstructTest(), a, p, + forward(args)...); } /* allocator destroy */ namespace detail { template - auto destroy_test(A &&a, P &&p) -> decltype(a.destroy(p), octa::True()); + auto destroy_test(A &&a, P &&p) -> decltype(a.destroy(p), True()); template - auto destroy_test(const A &, P &&) -> octa::False; + auto destroy_test(const A &, P &&) -> False; template - struct DestroyTest: octa::IntegralConstant(), octa::declval

())), - octa::True + struct DestroyTest: IntegralConstant(), declval

())), True >::value > {}; template - inline void destroy(octa::True, A &a, T *p) { + inline void destroy(True, A &a, T *p) { a.destroy(p); } template - inline void destroy(octa::False, A &, T *p) { + inline void destroy(False, A &, T *p) { p->~T(); } } /* namespace detail */ template inline void allocator_destroy(A &a, T *p) { - octa::detail::destroy(octa::detail::DestroyTest(), a, p); + detail::destroy(detail::DestroyTest(), a, p); } /* allocator max size */ namespace detail { template - auto alloc_max_size_test(A &&a) -> decltype(a.max_size(), octa::True()); + auto alloc_max_size_test(A &&a) -> decltype(a.max_size(), True()); template - auto alloc_max_size_test(const A &) -> octa::False; + auto alloc_max_size_test(const A &) -> False; template - struct AllocMaxSizeTest: octa::IntegralConstant())), - octa::True + struct AllocMaxSizeTest: IntegralConstant())), True >::value > {}; template - inline AllocatorSize alloc_max_size(octa::True, const A &a) { + inline AllocatorSize alloc_max_size(True, const A &a) { return a.max_size(); } template - inline AllocatorSize alloc_max_size(octa::False, const A &) { + inline AllocatorSize alloc_max_size(False, const A &) { return AllocatorSize(~0); } } /* namespace detail */ template inline AllocatorSize allocator_max_size(const A &a) { - return octa::detail::alloc_max_size(octa::detail::AllocMaxSizeTest< - const A - >(), a); + return detail::alloc_max_size(detail::AllocMaxSizeTest(), a); } /* allocator container copy */ namespace detail { template - auto alloc_copy_test(A &&a) -> decltype(a.container_copy(), octa::True()); + auto alloc_copy_test(A &&a) -> decltype(a.container_copy(), True()); template - auto alloc_copy_test(const A &) -> octa::False; + auto alloc_copy_test(const A &) -> False; template - struct AllocCopyTest: octa::IntegralConstant())), octa::True + struct AllocCopyTest: IntegralConstant())), True >::value > {}; template - inline AllocatorType alloc_container_copy(octa::True, const A &a) { + inline AllocatorType alloc_container_copy(True, const A &a) { return a.container_copy(); } template - inline AllocatorType alloc_container_copy(octa::False, const A &a) { + inline AllocatorType alloc_container_copy(False, const A &a) { return a; } } /* namespace detail */ template inline AllocatorType allocator_container_copy(const A &a) { - return octa::detail::alloc_container_copy(octa::detail::AllocCopyTest< + return detail::alloc_container_copy(detail::AllocCopyTest< const A >(), a); } diff --git a/octa/range.hh b/octa/range.hh index 4724a1b..18b4d82 100644 --- a/octa/range.hh +++ b/octa/range.hh @@ -41,7 +41,7 @@ namespace detail { \ }; \ } \ template \ -using Range##Name = typename octa::detail::Range##Name##Base::Type; +using Range##Name = typename detail::Range##Name##Base::Type; OCTA_RANGE_TRAIT(Category) OCTA_RANGE_TRAIT(Size) @@ -70,7 +70,7 @@ namespace detail { // is input range namespace detail { - template, InputRangeTag >::value> struct IsInputRangeBase: False {}; @@ -78,16 +78,16 @@ namespace detail { struct IsInputRangeBase: True {}; } -template::value> +template::value> struct IsInputRange: False {}; template -struct IsInputRange: octa::detail::IsInputRangeBase::Type {}; +struct IsInputRange: detail::IsInputRangeBase::Type {}; // is forward range namespace detail { - template, ForwardRangeTag >::value> struct IsForwardRangeBase: False {}; @@ -95,16 +95,16 @@ namespace detail { struct IsForwardRangeBase: True {}; } -template::value> +template::value> struct IsForwardRange: False {}; template -struct IsForwardRange: octa::detail::IsForwardRangeBase::Type {}; +struct IsForwardRange: detail::IsForwardRangeBase::Type {}; // is bidirectional range namespace detail { - template, BidirectionalRangeTag >::value> struct IsBidirectionalRangeBase: False {}; @@ -112,17 +112,17 @@ namespace detail { struct IsBidirectionalRangeBase: True {}; } -template::value> +template::value> struct IsBidirectionalRange: False {}; template struct IsBidirectionalRange: - octa::detail::IsBidirectionalRangeBase::Type {}; + detail::IsBidirectionalRangeBase::Type {}; // is random access range namespace detail { - template, RandomAccessRangeTag >::value> struct IsRandomAccessRangeBase: False {}; @@ -130,17 +130,17 @@ namespace detail { struct IsRandomAccessRangeBase: True {}; } -template::value> +template::value> struct IsRandomAccessRange: False {}; template struct IsRandomAccessRange: - octa::detail::IsRandomAccessRangeBase::Type {}; + detail::IsRandomAccessRangeBase::Type {}; // is finite random access range namespace detail { - template, FiniteRandomAccessRangeTag >::value> struct IsFiniteRandomAccessRangeBase: False {}; @@ -148,12 +148,12 @@ namespace detail { struct IsFiniteRandomAccessRangeBase: True {}; } -template::value> +template::value> struct IsFiniteRandomAccessRange: False {}; template struct IsFiniteRandomAccessRange: - octa::detail::IsFiniteRandomAccessRangeBase::Type {}; + detail::IsFiniteRandomAccessRangeBase::Type {}; // is infinite random access range @@ -174,12 +174,12 @@ namespace detail { }; } -template, OutputRangeTag >::value || (IsInputRange::value && - (octa::detail::OutputRangeTest &>::value || - octa::detail::OutputRangeTest &&>::value || - octa::detail::OutputRangeTest >::value) + (detail::OutputRangeTest &>::value || + detail::OutputRangeTest &&>::value || + detail::OutputRangeTest >::value) ))> struct IsOutputRange: False {}; template @@ -195,7 +195,7 @@ namespace detail { ::new(&get_ref()) T(range); } explicit RangeIterator(T &&range) { - ::new(&get_ref()) T(octa::move(range)); + ::new(&get_ref()) T(move(range)); } RangeIterator &operator++() { get_ref().pop_front(); @@ -208,7 +208,7 @@ namespace detail { private: T &get_ref() { return *((T *)&p_range); } const T &get_ref() const { return *((T *)&p_range); } - octa::AlignedStorage p_range; + AlignedStorage p_range; }; } @@ -259,12 +259,12 @@ public: RangeHalf() = delete; RangeHalf(const T &range): p_range(range) {} - template::value + template::value >> RangeHalf(const RangeHalf &half): p_range(half.p_range) {} RangeHalf(const RangeHalf &half): p_range(half.p_range) {} - RangeHalf(RangeHalf &&half): p_range(octa::move(half.p_range)) {} + RangeHalf(RangeHalf &&half): p_range(move(half.p_range)) {} RangeHalf &operator=(const RangeHalf &half) { p_range = half.p_range; @@ -272,7 +272,7 @@ public: } RangeHalf &operator=(RangeHalf &&half) { - p_range = octa::move(half.p_range); + p_range = move(half.p_range); return *this; } @@ -287,10 +287,10 @@ public: } RangeDifference add_n(RangeDifference n) { - return octa::detail::RangeAdd>::add_n(*this, n); + return detail::RangeAdd>::add_n(*this, n); } RangeDifference sub_n(RangeDifference n) { - return octa::detail::RangeAdd>::sub_n(*this, n); + return detail::RangeAdd>::sub_n(*this, n); } RangeReference get() const { @@ -408,7 +408,7 @@ template struct ReverseRange; template struct MoveRange; template struct InputRange { using Category = C; using Size = S; @@ -416,27 +416,27 @@ template begin() const { - return octa::detail::RangeIterator((const B &)*this); + detail::RangeIterator begin() const { + return detail::RangeIterator((const B &)*this); } - octa::detail::RangeIterator end() const { - return octa::detail::RangeIterator(); + detail::RangeIterator end() const { + return detail::RangeIterator(); } Size pop_front_n(Size n) { - return octa::detail::pop_front_n(*((B *)this), n); + return detail::pop_front_n(*((B *)this), n); } Size pop_back_n(Size n) { - return octa::detail::pop_back_n(*((B *)this), n); + return detail::pop_back_n(*((B *)this), n); } Size push_front_n(Size n) { - return octa::detail::push_front_n(*((B *)this), n); + return detail::push_front_n(*((B *)this), n); } Size push_back_n(Size n) { - return octa::detail::push_back_n(*((B *)this), n); + return detail::push_back_n(*((B *)this), n); } B iter() const { @@ -463,8 +463,8 @@ template::value - >> Size copy(OR &&orange, Size n = -1) { + typename = EnableIf::value> + > Size copy(OR &&orange, Size n = -1) { B r(*((B *)this)); Size on = n; for (; n && !r.empty(); --n) { @@ -474,7 +474,7 @@ template *p, Size n = -1) { + Size copy(RemoveCv *p, Size n = -1) { B r(*((B *)this)); Size on = n; for (; n && !r.empty(); --n) { @@ -501,7 +501,7 @@ auto citer(const T &r) -> decltype(r.iter()) { } template struct OutputRange { using Category = OutputRangeTag; using Size = S; @@ -533,12 +533,12 @@ public: HalfRange() = delete; HalfRange(const HalfRange &range): p_beg(range.p_beg), p_end(range.p_end) {} - HalfRange(HalfRange &&range): p_beg(octa::move(range.p_beg)), - p_end(octa::move(range.p_end)) {} + HalfRange(HalfRange &&range): p_beg(move(range.p_beg)), + p_end(move(range.p_end)) {} HalfRange(const T &beg, const T &end): p_beg(beg), p_end(end) {} - HalfRange(T &&beg, T &&end): p_beg(octa::move(beg)), - p_end(octa::move(end)) {} + HalfRange(T &&beg, T &&end): p_beg(move(beg)), + p_end(move(end)) {} HalfRange &operator=(const HalfRange &range) { p_beg = range.p_beg; @@ -547,8 +547,8 @@ public: } HalfRange &operator=(HalfRange &&range) { - p_beg = octa::move(range.p_beg); - p_end = octa::move(range.p_end); + p_beg = move(range.p_beg); + p_end = move(range.p_end); return *this; } @@ -601,7 +601,7 @@ public: return p_beg.range().put(v); } bool put(RangeValue &&v) { - return p_beg.range().put(octa::move(v)); + return p_beg.range().put(move(v)); } }; @@ -620,14 +620,14 @@ public: ReverseRange() = delete; ReverseRange(const T &range): p_range(range) {} ReverseRange(const ReverseRange &it): p_range(it.p_range) {} - ReverseRange(ReverseRange &&it): p_range(octa::move(it.p_range)) {} + ReverseRange(ReverseRange &&it): p_range(move(it.p_range)) {} ReverseRange &operator=(const ReverseRange &v) { p_range = v.p_range; return *this; } ReverseRange &operator=(ReverseRange &&v) { - p_range = octa::move(v.p_range); + p_range = move(v.p_range); return *this; } ReverseRange &operator=(const T &v) { @@ -635,7 +635,7 @@ public: return *this; } ReverseRange &operator=(T &&v) { - p_range = octa::move(v); + p_range = move(v); return *this; } @@ -695,14 +695,14 @@ public: MoveRange() = delete; MoveRange(const T &range): p_range(range) {} MoveRange(const MoveRange &it): p_range(it.p_range) {} - MoveRange(MoveRange &&it): p_range(octa::move(it.p_range)) {} + MoveRange(MoveRange &&it): p_range(move(it.p_range)) {} MoveRange &operator=(const MoveRange &v) { p_range = v.p_range; return *this; } MoveRange &operator=(MoveRange &&v) { - p_range = octa::move(v.p_range); + p_range = move(v.p_range); return *this; } MoveRange &operator=(const T &v) { @@ -710,7 +710,7 @@ public: return *this; } MoveRange &operator=(T &&v) { - p_range = octa::move(v); + p_range = move(v); return *this; } @@ -743,17 +743,17 @@ public: Rsize push_front_n(Rsize n) { return p_range.push_front_n(n); } Rsize push_back_n(Rsize n) { return p_range.push_back_n(n); } - Rref front() const { return octa::move(p_range.front()); } - Rref back() const { return octa::move(p_range.back()); } + Rref front() const { return move(p_range.front()); } + Rref back() const { return move(p_range.back()); } - Rref operator[](Rsize i) const { return octa::move(p_range[i]); } + Rref operator[](Rsize i) const { return move(p_range[i]); } MoveRange slice(Rsize start, Rsize end) const { return MoveRange(p_range.slice(start, end)); } bool put(const Rval &v) { return p_range.put(v); } - bool put(Rval &&v) { return p_range.put(octa::move(v)); } + bool put(Rval &&v) { return p_range.put(move(v)); } }; template @@ -792,10 +792,10 @@ template struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> { PointerRange() = delete; PointerRange(T *beg, T *end): p_beg(beg), p_end(end) {} - PointerRange(T *beg, octa::Size n): p_beg(beg), p_end(beg + n) {} + PointerRange(T *beg, Size n): p_beg(beg), p_end(beg + n) {} - template::value + template::value >> PointerRange(const PointerRange &v): p_beg(&v[0]), p_end(&v[v.size()]) {} @@ -817,8 +817,8 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> --p_beg; return true; } - octa::Size pop_front_n(octa::Size n) { - octa::Size olen = p_end - p_beg; + Size pop_front_n(Size n) { + Size olen = p_end - p_beg; p_beg += n; if (p_beg > p_end) { p_beg = p_end; @@ -827,7 +827,7 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> return n; } - octa::Size push_front_n(octa::Size n) { + Size push_front_n(Size n) { p_beg -= n; return true; } @@ -837,7 +837,7 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> return p_beg == range.p_beg; } - octa::Ptrdiff distance_front(const PointerRange &range) const { + Ptrdiff distance_front(const PointerRange &range) const { return range.p_beg - p_beg; } @@ -851,8 +851,8 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> ++p_end; return true; } - octa::Size pop_back_n(octa::Size n) { - octa::Size olen = p_end - p_beg; + Size pop_back_n(Size n) { + Size olen = p_end - p_beg; p_end -= n; if (p_end < p_beg) { p_end = p_beg; @@ -861,7 +861,7 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> return n; } - octa::Size push_back_n(octa::Size n) { + Size push_back_n(Size n) { p_end += n; return true; } @@ -871,18 +871,18 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> return p_end == range.p_end; } - octa::Ptrdiff distance_back(const PointerRange &range) const { + Ptrdiff distance_back(const PointerRange &range) const { return range.p_end - p_end; } /* satisfy FiniteRandomAccessRange */ - octa::Size size() const { return p_end - p_beg; } + Size size() const { return p_end - p_beg; } - PointerRange slice(octa::Size start, octa::Size end) const { + PointerRange slice(Size start, Size end) const { return PointerRange(p_beg + start, p_beg + end); } - T &operator[](octa::Size i) const { return p_beg[i]; } + T &operator[](Size i) const { return p_beg[i]; } /* satisfy OutputRange */ bool put(const T &v) { @@ -892,33 +892,33 @@ struct PointerRange: InputRange, FiniteRandomAccessRangeTag, T> } bool put(T &&v) { if (empty()) return false; - *(p_beg++) = octa::move(v); + *(p_beg++) = move(v); return true; } - octa::Size put_n(const T *p, octa::Size n) { - octa::Size ret = size(); + Size put_n(const T *p, Size n) { + Size ret = size(); if (n < ret) ret = n; - if (octa::IsPod()) { + if (IsPod()) { memcpy(p_beg, p, ret * sizeof(T)); p_beg += ret; return ret; } - for (octa::Size i = ret; i; --i) + for (Size i = ret; i; --i) *p_beg++ = *p++; return ret; } template::value - >> octa::Size copy(R &&orange, octa::Size n = -1) { - octa::Size c = size(); + typename = EnableIf::value + >> Size copy(R &&orange, Size n = -1) { + Size c = size(); if (n < c) c = n; return orange.put_n(p_beg, c); } - octa::Size copy(octa::RemoveCv *p, octa::Size n = -1) { - octa::Size c = size(); + Size copy(RemoveCv *p, Size n = -1) { + Size c = size(); if (n < c) c = n; return copy(PointerRange(p, c), c); } @@ -927,12 +927,12 @@ private: T *p_beg, *p_end; }; -template +template PointerRange iter(T (&array)[N]) { return PointerRange(array, N); } -template +template PointerRange iter(const T (&array)[N]) { return PointerRange(array, N); } @@ -965,7 +965,7 @@ public: p_range(it.p_range), p_index(it.p_index) {} EnumeratedRange(EnumeratedRange &&it): - p_range(octa::move(it.p_range)), p_index(it.p_index) {} + p_range(move(it.p_range)), p_index(it.p_index) {} EnumeratedRange &operator=(const EnumeratedRange &v) { p_range = v.p_range; @@ -973,7 +973,7 @@ public: return *this; } EnumeratedRange &operator=(EnumeratedRange &&v) { - p_range = octa::move(v.p_range); + p_range = move(v.p_range); p_index = v.p_index; return *this; } @@ -983,7 +983,7 @@ public: return *this; } EnumeratedRange &operator=(T &&v) { - p_range = octa::move(v); + p_range = move(v); p_index = 0; return *this; } @@ -1032,14 +1032,14 @@ public: p_remaining(rem) {} TakeRange(const TakeRange &it): p_range(it.p_range), p_remaining(it.p_remaining) {} - TakeRange(TakeRange &&it): p_range(octa::move(it.p_range)), + TakeRange(TakeRange &&it): p_range(move(it.p_range)), p_remaining(it.p_remaining) {} TakeRange &operator=(const TakeRange &v) { p_range = v.p_range; p_remaining = v.p_remaining; return *this; } TakeRange &operator=(TakeRange &&v) { - p_range = octa::move(v.p_range); + p_range = move(v.p_range); p_remaining = v.p_remaining; return *this; } @@ -1086,14 +1086,14 @@ public: p_chunksize(chs) {} ChunksRange(const ChunksRange &it): p_range(it.p_range), p_chunksize(it.p_chunksize) {} - ChunksRange(ChunksRange &&it): p_range(octa::move(it.p_range)), + ChunksRange(ChunksRange &&it): p_range(move(it.p_range)), p_chunksize(it.p_chunksize) {} ChunksRange &operator=(const ChunksRange &v) { p_range = v.p_range; p_chunksize = v.p_chunksize; return *this; } ChunksRange &operator=(ChunksRange &&v) { - p_range = octa::move(v.p_range); + p_range = move(v.p_range); p_chunksize = v.p_chunksize; return *this; } @@ -1122,9 +1122,9 @@ 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 &&v): p_data(octa::move(v)) {} + AppenderRange(T &&v): p_data(move(v)) {} AppenderRange(const AppenderRange &v): p_data(v.p_data) {} - AppenderRange(AppenderRange &&v): p_data(octa::move(v.p_data)) {} + AppenderRange(AppenderRange &&v): p_data(move(v.p_data)) {} AppenderRange &operator=(const AppenderRange &v) { p_data = v.p_data; @@ -1132,7 +1132,7 @@ struct AppenderRange: OutputRange, typename T::Value, } AppenderRange &operator=(AppenderRange &&v) { - p_data = octa::move(v.p_data); + p_data = move(v.p_data); return *this; } @@ -1142,7 +1142,7 @@ struct AppenderRange: OutputRange, typename T::Value, } AppenderRange &operator=(T &&v) { - p_data = octa::move(v); + p_data = move(v); return *this; } @@ -1160,7 +1160,7 @@ struct AppenderRange: OutputRange, typename T::Value, } bool put(typename T::Value &&v) { - p_data.push(octa::move(v)); + p_data.push(move(v)); return true; } @@ -1176,11 +1176,11 @@ AppenderRange appender() { template AppenderRange appender(T &&v) { - return AppenderRange(octa::forward(v)); + return AppenderRange(forward(v)); } // range of -template using RangeOf = decltype(octa::iter(octa::declval())); +template using RangeOf = decltype(iter(declval())); } /* namespace octa */ diff --git a/octa/set.hh b/octa/set.hh index e8d4ebe..92ceb2f 100644 --- a/octa/set.hh +++ b/octa/set.hh @@ -30,56 +30,56 @@ namespace detail { }; template - struct SetImpl: octa::detail::Hashtable< - octa::detail::SetBase, T, T, T, H, C, A, IsMultihash + struct SetImpl: detail::Hashtable< + detail::SetBase, T, T, T, H, C, A, IsMultihash > { private: - using Base = octa::detail::Hashtable< - octa::detail::SetBase, T, T, T, H, C, A, IsMultihash + using Base = detail::Hashtable< + detail::SetBase, T, T, T, H, C, A, IsMultihash >; public: using Key = T; - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Hasher = H; using KeyEqual = C; using Value = T; using Reference = Value &; - using Pointer = octa::AllocatorPointer; - using ConstPointer = octa::AllocatorConstPointer; - using Range = octa::HashRange; - using ConstRange = octa::HashRange; - using LocalRange = octa::BucketRange; - using ConstLocalRange = octa::BucketRange; + using Pointer = AllocatorPointer; + using ConstPointer = AllocatorConstPointer; + using Range = HashRange; + using ConstRange = HashRange; + using LocalRange = BucketRange; + using ConstLocalRange = BucketRange; using Allocator = A; - explicit SetImpl(octa::Size size, const H &hf = H(), + explicit SetImpl(Size size, const H &hf = H(), const C &eqf = C(), const A &alloc = A() ): Base(size, hf, eqf, alloc) {} SetImpl(): SetImpl(0) {} explicit SetImpl(const A &alloc): SetImpl(0, H(), C(), alloc) {} - SetImpl(octa::Size size, const A &alloc): + SetImpl(Size size, const A &alloc): SetImpl(size, H(), C(), alloc) {} - SetImpl(octa::Size size, const H &hf, const A &alloc): + SetImpl(Size size, const H &hf, const A &alloc): SetImpl(size, hf, C(), alloc) {} SetImpl(const SetImpl &m): Base(m, - octa::allocator_container_copy(m.get_alloc())) {} + allocator_container_copy(m.get_alloc())) {} SetImpl(const SetImpl &m, const A &alloc): Base(m, alloc) {} - SetImpl(SetImpl &&m): Base(octa::move(m)) {} - SetImpl(SetImpl &&m, const A &alloc): Base(octa::move(m), alloc) {} + SetImpl(SetImpl &&m): Base(move(m)) {} + SetImpl(SetImpl &&m, const A &alloc): Base(move(m), alloc) {} - template::value && - octa::IsConvertible, Value>::value - >> SetImpl(R range, octa::Size size = 0, const H &hf = H(), + template::value && + IsConvertible, Value>::value + >> SetImpl(R range, Size size = 0, const H &hf = H(), const C &eqf = C(), const A &alloc = A() - ): Base(size ? size : octa::detail::estimate_hrsize(range), + ): Base(size ? size : detail::estimate_hrsize(range), hf, eqf, alloc) { for (; !range.empty(); range.pop_front()) Base::emplace(range.front()); @@ -87,23 +87,23 @@ namespace detail { } template - SetImpl(R range, octa::Size size, const A &alloc) + SetImpl(R range, Size size, const A &alloc) : SetImpl(range, size, H(), C(), alloc) {} template - SetImpl(R range, octa::Size size, const H &hf, const A &alloc) + SetImpl(R range, Size size, const H &hf, const A &alloc) : SetImpl(range, size, hf, C(), alloc) {} - SetImpl(octa::InitializerList init, octa::Size size = 0, + SetImpl(InitializerList init, Size size = 0, const H &hf = H(), const C &eqf = C(), const A &alloc = A() - ): SetImpl(octa::iter(init), size, hf, eqf, alloc) {} + ): SetImpl(iter(init), size, hf, eqf, alloc) {} - SetImpl(octa::InitializerList init, octa::Size size, const A &alloc) - : SetImpl(octa::iter(init), size, H(), C(), alloc) {} + SetImpl(InitializerList init, Size size, const A &alloc) + : SetImpl(iter(init), size, H(), C(), alloc) {} - SetImpl(octa::InitializerList init, octa::Size size, const H &hf, + SetImpl(InitializerList init, Size size, const H &hf, const A &alloc - ): SetImpl(octa::iter(init), size, hf, C(), alloc) {} + ): SetImpl(iter(init), size, hf, C(), alloc) {} SetImpl &operator=(const SetImpl &m) { Base::operator=(m); @@ -111,13 +111,13 @@ namespace detail { } SetImpl &operator=(SetImpl &&m) { - Base::operator=(octa::move(m)); + Base::operator=(move(m)); return *this; } - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> SetImpl &operator=(R range) { Base::assign_range(range); return *this; @@ -136,17 +136,17 @@ namespace detail { template< typename T, - typename H = octa::ToHash, - typename C = octa::Equal, - typename A = octa::Allocator -> using Set = octa::detail::SetImpl; + typename H = ToHash, + typename C = Equal, + typename A = Allocator +> using Set = detail::SetImpl; template< typename T, - typename H = octa::ToHash, - typename C = octa::Equal, - typename A = octa::Allocator -> using Multiset = octa::detail::SetImpl; + typename H = ToHash, + typename C = Equal, + typename A = Allocator +> using Multiset = detail::SetImpl; } /* namespace octa */ diff --git a/octa/stream.hh b/octa/stream.hh index 7069640..a0631f2 100644 --- a/octa/stream.hh +++ b/octa/stream.hh @@ -30,16 +30,16 @@ enum class StreamSeek { set = SEEK_SET }; -template::value> +template::value> struct StreamRange; namespace detail { - template - struct FormatOutRange: octa::OutputRange, char> { + template + struct FormatOutRange: OutputRange, char> { FormatOutRange(char *buf): buf(buf), idx(0) {} FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {} char *buf; - octa::Size idx; + Size idx; bool put(char v) { if (idx < N) { buf[idx++] = v; @@ -74,30 +74,30 @@ struct Stream { virtual bool flush() { return true; } - virtual octa::Size read_bytes(void *, octa::Size) { return 0; } - virtual octa::Size write_bytes(const void *, octa::Size) { return 0; } + virtual Size read_bytes(void *, Size) { return 0; } + virtual Size write_bytes(const void *, Size) { return 0; } virtual int getchar() { - octa::byte c; + byte c; return (read_bytes(&c, 1) == 1) ? c : -1; } virtual bool putchar(int c) { - octa::byte wc = octa::byte(c); + byte wc = byte(c); return write_bytes(&wc, 1) == 1; } virtual bool write(const char *s) { - octa::Size len = strlen(s); + Size len = strlen(s); return write_bytes(s, len) == len; } - virtual bool write(const octa::String &s) { + virtual bool write(const String &s) { return write_bytes(s.data(), s.size()) == s.size(); } template bool write(const T &v) { - return write(octa::to_string(v)); + return write(to_string(v)); } template @@ -105,7 +105,7 @@ struct Stream { return write(v) && write(args...); } - virtual bool writeln(const octa::String &s) { + virtual bool writeln(const String &s) { return write(s) && putchar('\n'); } @@ -125,19 +125,19 @@ struct Stream { template bool writef(const char *fmt, const A &...args) { char buf[512]; - octa::Size need = octa::format(octa::detail::FormatOutRange< - sizeof(buf)>(buf), fmt, args...); + Size need = format(detail::FormatOutRange(buf), + fmt, args...); if (need < sizeof(buf)) return write_bytes(buf, need) == need; - octa::String s; + String s; s.reserve(need); s[need] = '\0'; - octa::format(s.iter(), fmt, args...); + format(s.iter(), fmt, args...); return write_bytes(s.data(), need) == need; } template - bool writef(const octa::String &fmt, const A &...args) { + bool writef(const String &fmt, const A &...args) { return writef(fmt.data(), args...); } @@ -147,14 +147,14 @@ struct Stream { } template - bool writefln(const octa::String &fmt, const A &...args) { + bool writefln(const String &fmt, const A &...args) { return writefln(fmt.data(), args...); } template StreamRange iter(); - template octa::Size put(const T *v, octa::Size count) { + template Size put(const T *v, Size count) { return write_bytes(v, count * sizeof(T)) / sizeof(T); } @@ -162,7 +162,7 @@ struct Stream { return write_bytes(&v, sizeof(T)) == sizeof(T); } - template octa::Size get(T *v, octa::Size count) { + template Size get(T *v, Size count) { return read_bytes(v, count * sizeof(T)) / sizeof(T); } @@ -178,7 +178,7 @@ struct Stream { template struct StreamRange: InputRange< - StreamRange, octa::InputRangeTag, T, T, octa::Size, StreamOffset + StreamRange, InputRangeTag, T, T, Size, StreamOffset > { StreamRange() = delete; StreamRange(Stream &s): p_stream(&s), p_size(s.size()) {} @@ -205,17 +205,17 @@ struct StreamRange: InputRange< } bool put(T val) { - octa::Size v = p_stream->write_bytes(&val, sizeof(T)); + Size v = p_stream->write_bytes(&val, sizeof(T)); p_size += v; return (v == sizeof(T)); } - octa::Size put_n(const T *p, octa::Size n) { + Size put_n(const T *p, Size n) { return p_stream->put(p, n); } - octa::Size copy(octa::RemoveCv *p, octa::Size n = -1) { - if (n == octa::Size(-1)) { + Size copy(RemoveCv *p, Size n = -1) { + if (n == Size(-1)) { n = p_stream->size() / sizeof(T); } return p_stream->get(p, n); diff --git a/octa/string.hh b/octa/string.hh index 4f19ed5..26e46b0 100644 --- a/octa/string.hh +++ b/octa/string.hh @@ -14,9 +14,9 @@ #include "octa/vector.hh" namespace octa { -static constexpr octa::Size npos = -1; +static constexpr Size npos = -1; -template> class StringBase; +template> class StringBase; template struct StringRangeBase: InputRange< @@ -24,7 +24,7 @@ struct StringRangeBase: InputRange< > { StringRangeBase() = delete; StringRangeBase(T *beg, T *end): p_beg(beg), p_end(end) {} - StringRangeBase(T *beg, octa::Size n): p_beg(beg), p_end(beg + n) {} + StringRangeBase(T *beg, Size n): p_beg(beg), p_end(beg + n) {} /* TODO: traits for utf-16/utf-32 string lengths, for now assume char */ StringRangeBase(T *beg): p_beg(beg), p_end(beg + strlen(beg)) {} @@ -32,8 +32,8 @@ struct StringRangeBase: InputRange< StringRangeBase(const StringBase &s): p_beg(s.data()), p_end(s.data() + s.size()) {} - template::value + template::value >> StringRangeBase(const StringRangeBase &v): p_beg(&v[0]), p_end(&v[v.size()]) {} @@ -59,8 +59,8 @@ struct StringRangeBase: InputRange< } bool push_front() { --p_beg; return true; } - octa::Size pop_front_n(octa::Size n) { - octa::Size olen = p_end - p_beg; + Size pop_front_n(Size n) { + Size olen = p_end - p_beg; p_beg += n; if (p_beg > p_end) { p_beg = p_end; @@ -69,7 +69,7 @@ struct StringRangeBase: InputRange< return n; } - octa::Size push_front_n(octa::Size n) { p_beg -= n; return true; } + Size push_front_n(Size n) { p_beg -= n; return true; } T &front() const { return *p_beg; } @@ -77,7 +77,7 @@ struct StringRangeBase: InputRange< return p_beg == range.p_beg; } - octa::Ptrdiff distance_front(const StringRangeBase &range) const { + Ptrdiff distance_front(const StringRangeBase &range) const { return range.p_beg - p_beg; } @@ -88,8 +88,8 @@ struct StringRangeBase: InputRange< } bool push_back() { ++p_end; return true; } - octa::Size pop_back_n(octa::Size n) { - octa::Size olen = p_end - p_beg; + Size pop_back_n(Size n) { + Size olen = p_end - p_beg; p_end -= n; if (p_end < p_beg) { p_end = p_beg; @@ -98,7 +98,7 @@ struct StringRangeBase: InputRange< return n; } - octa::Size push_back_n(octa::Size n) { p_end += n; return true; } + Size push_back_n(Size n) { p_end += n; return true; } T &back() const { return *(p_end - 1); } @@ -106,17 +106,17 @@ struct StringRangeBase: InputRange< return p_end == range.p_end; } - octa::Ptrdiff distance_back(const StringRangeBase &range) const { + Ptrdiff distance_back(const StringRangeBase &range) const { return range.p_end - p_end; } - octa::Size size() const { return p_end - p_beg; } + Size size() const { return p_end - p_beg; } - StringRangeBase slice(octa::Size start, octa::Size end) const { + StringRangeBase slice(Size start, Size end) const { return StringRangeBase(p_beg + start, p_beg + end); } - T &operator[](octa::Size i) const { return p_beg[i]; } + T &operator[](Size i) const { return p_beg[i]; } bool put(T v) { if (empty()) return false; @@ -128,7 +128,7 @@ struct StringRangeBase: InputRange< T *data() { return p_beg; } const T *data() const { return p_beg; } - octa::Size to_hash() const { + Size to_hash() const { const T *d = data(); Size h = 5381, len = size(); for (Size i = 0; i < len; ++i) @@ -142,22 +142,22 @@ private: template class StringBase { - octa::Vector p_buf; + Vector p_buf; void terminate() { if (p_buf.empty() || (p_buf.back() != '\0')) p_buf.push('\0'); } public: - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Value = T; using Reference = T &; using ConstReference = const T &; - using Pointer = octa::AllocatorPointer; - using ConstPointer = octa::AllocatorConstPointer; - using Range = octa::StringRangeBase; - using ConstRange = octa::StringRangeBase; + using Pointer = AllocatorPointer; + using ConstPointer = AllocatorConstPointer; + using Range = StringRangeBase; + using ConstRange = StringRangeBase; using Allocator = A; StringBase(const A &a = A()): p_buf(1, '\0', a) {} @@ -168,11 +168,11 @@ public: StringBase(const StringBase &s): p_buf(s.p_buf) {} StringBase(const StringBase &s, const A &a): p_buf(s.p_buf, a) {} - StringBase(StringBase &&s): p_buf(octa::move(s.p_buf)) {} + StringBase(StringBase &&s): p_buf(move(s.p_buf)) {} StringBase(StringBase &&s, const A &a): - p_buf(octa::move(s.p_buf), a) {} + p_buf(move(s.p_buf), a) {} - StringBase(const StringBase &s, octa::Size pos, octa::Size len = npos, + StringBase(const StringBase &s, Size pos, Size len = npos, const A &a = A()): p_buf(s.p_buf.iter().slice(pos, (len == npos) ? s.p_buf.size() : (pos + len)), a) { @@ -186,9 +186,9 @@ public: StringBase(const Value *v, Size n, const A &a = A()): p_buf(ConstRange(v, n), a) {} - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> StringBase(R range, const A &a = A()): p_buf(range, a) { terminate(); } @@ -200,37 +200,37 @@ public: return *this; } StringBase &operator=(StringBase &&v) { - p_buf.operator=(octa::move(v)); + p_buf.operator=(move(v)); return *this; } StringBase &operator=(const Value *v) { p_buf = ConstRange(v, strlen(v) + 1); return *this; } - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> StringBase &operator=(const R &r) { p_buf = r; terminate(); return *this; } - void resize(octa::Size n, T v = T()) { + void resize(Size n, T v = T()) { p_buf.pop(); p_buf.resize(n, v); terminate(); } - void reserve(octa::Size n) { + void reserve(Size n) { p_buf.reserve(n + 1); } - T &operator[](octa::Size i) { return p_buf[i]; } - const T &operator[](octa::Size i) const { return p_buf[i]; } + T &operator[](Size i) { return p_buf[i]; } + const T &operator[](Size i) const { return p_buf[i]; } - T &at(octa::Size i) { return p_buf[i]; } - const T &at(octa::Size i) const { return p_buf[i]; } + T &at(Size i) { return p_buf[i]; } + const T &at(Size i) const { return p_buf[i]; } T &front() { return p_buf[0]; } const T &front() const { return p_buf[0]; }; @@ -241,15 +241,15 @@ public: Value *data() { return p_buf.data(); } const Value *data() const { return p_buf.data(); } - octa::Size size() const { + Size size() const { return p_buf.size() - 1; } - octa::Size capacity() const { + Size capacity() const { return p_buf.capacity() - 1; } - octa::Size length() const { + Size length() const { /* TODO: unicode */ return size(); } @@ -267,7 +267,7 @@ public: return *this; } - StringBase &append(const StringBase &s, octa::Size idx, octa::Size len) { + StringBase &append(const StringBase &s, Size idx, Size len) { p_buf.pop(); p_buf.insert_range(p_buf.size(), Range(&s[idx], (len == npos) ? (s.size() - idx) : len)); @@ -282,9 +282,9 @@ public: return *this; } - StringBase &append(octa::Size n, T c) { + StringBase &append(Size n, T c) { p_buf.pop(); - for (octa::Size i = 0; i < n; ++i) p_buf.push(c); + for (Size i = 0; i < n; ++i) p_buf.push(c); p_buf.push('\0'); return *this; } @@ -441,23 +441,21 @@ template struct ToString { template static String to_str(const U &v, - octa::EnableIf::value, bool> = true + EnableIf::value, bool> = true ) { return v.to_string(); } template static String to_str(const U &v, - octa::EnableIf::value && - !octa::IsScalar::value, bool> = true + EnableIf::value && + !IsScalar::value, bool> = true ) { String ret("{"); ret += concat(octa::iter(v), ", ", ToString< - octa::RemoveCv< - octa::RemoveReference< - octa::RangeReference - > - > + RemoveCv + >> >()); ret += "}"; return ret; @@ -465,8 +463,8 @@ template struct ToString { template static String to_str(const U &v, - octa::EnableIf::value && - octa::IsScalar::value, bool> = true + EnableIf::value && + IsScalar::value, bool> = true ) { return ToString()(v); } @@ -478,7 +476,7 @@ template struct ToString { namespace detail { template - void str_printf(octa::Vector *s, const char *fmt, T v) { + void str_printf(Vector *s, const char *fmt, T v) { char buf[256]; int n = snprintf(buf, sizeof(buf), fmt, v); s->clear(); @@ -491,7 +489,7 @@ namespace detail { n = 0; *(s->data()) = '\0'; } - *((octa::Size *)s) = n + 1; + *((Size *)s) = n + 1; } } @@ -519,24 +517,24 @@ template<> struct ToString { \ using Result = String; \ String operator()(T v) { \ String ret; \ - octa::detail::str_printf((octa::Vector *)&ret, fmt, v); \ + detail::str_printf((Vector *)&ret, fmt, v); \ return ret; \ } \ }; -OCTA_TOSTR_NUM(octa::sbyte, "%d") +OCTA_TOSTR_NUM(sbyte, "%d") OCTA_TOSTR_NUM(int, "%d") OCTA_TOSTR_NUM(int &, "%d") OCTA_TOSTR_NUM(long, "%ld") OCTA_TOSTR_NUM(float, "%f") OCTA_TOSTR_NUM(double, "%f") -OCTA_TOSTR_NUM(octa::byte, "%u") -OCTA_TOSTR_NUM(octa::uint, "%u") -OCTA_TOSTR_NUM(octa::ulong, "%lu") -OCTA_TOSTR_NUM(octa::llong, "%lld") -OCTA_TOSTR_NUM(octa::ullong, "%llu") -OCTA_TOSTR_NUM(octa::ldouble, "%Lf") +OCTA_TOSTR_NUM(byte, "%u") +OCTA_TOSTR_NUM(uint, "%u") +OCTA_TOSTR_NUM(ulong, "%lu") +OCTA_TOSTR_NUM(llong, "%lld") +OCTA_TOSTR_NUM(ullong, "%llu") +OCTA_TOSTR_NUM(ldouble, "%Lf") #undef OCTA_TOSTR_NUM @@ -545,7 +543,7 @@ template struct ToString { using Result = String; String operator()(Argument v) { String ret; - octa::detail::str_printf((octa::Vector *)&ret, "%p", v); + detail::str_printf((Vector *)&ret, "%p", v); return ret; } }; @@ -566,8 +564,8 @@ template<> struct ToString { } }; -template struct ToString> { - using Argument = octa::Pair; +template struct ToString> { + using Argument = Pair; using Result = String; String operator()(const Argument &v) { String ret("{"); @@ -579,7 +577,7 @@ template struct ToString> { } }; -template()(octa::declval()))> +template()(declval()))> String to_string(const T &v) { return ToString()(v); } diff --git a/octa/type_traits.hh b/octa/type_traits.hh index 12f0b11..0438b9e 100644 --- a/octa/type_traits.hh +++ b/octa/type_traits.hh @@ -28,25 +28,25 @@ template struct IsReference; template struct IsTriviallyDefaultConstructible; template -using RemoveCv = typename octa::detail::RemoveCvBase::Type; +using RemoveCv = typename detail::RemoveCvBase::Type; template -using AddLvalueReference = typename octa::detail::AddLr::Type; +using AddLvalueReference = typename detail::AddLr::Type; template -using AddRvalueReference = typename octa::detail::AddRr::Type; +using AddRvalueReference = typename detail::AddRr::Type; template -using AddConst = typename octa::detail::AddConstBase::Type; +using AddConst = typename detail::AddConstBase::Type; template -using RemoveReference = typename octa::detail::RemoveReferenceBase::Type; +using RemoveReference = typename detail::RemoveReferenceBase::Type; template -using RemoveAllExtents = typename octa::detail::RemoveAllExtentsBase::Type; +using RemoveAllExtents = typename detail::RemoveAllExtentsBase::Type; namespace detail { - template octa::AddRvalueReference declval_in(); + template AddRvalueReference declval_in(); } /* integral constant */ @@ -75,17 +75,17 @@ namespace detail { } template - struct IsVoid: octa::detail::IsVoidBase> {}; + struct IsVoid: detail::IsVoidBase> {}; /* is null pointer */ namespace detail { - template struct IsNullPointerBase : False {}; - template< > struct IsNullPointerBase: True {}; + template struct IsNullPointerBase : False {}; + template< > struct IsNullPointerBase: True {}; } template struct IsNullPointer: - octa::detail::IsNullPointerBase> {}; + detail::IsNullPointerBase> {}; /* is integer */ @@ -98,21 +98,21 @@ namespace detail { template<> struct IsIntegralBase: True {}; template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; } template -struct IsIntegral: octa::detail::IsIntegralBase> {}; +struct IsIntegral: detail::IsIntegralBase> {}; /* is floating point */ @@ -122,17 +122,17 @@ namespace detail { template<> struct IsFloatingPointBase: True {}; template<> struct IsFloatingPointBase: True {}; - template<> struct IsFloatingPointBase: True {}; + template<> struct IsFloatingPointBase: True {}; } template -struct IsFloatingPoint: octa::detail::IsFloatingPointBase> {}; +struct IsFloatingPoint: detail::IsFloatingPointBase> {}; /* is array */ -template struct IsArray : False {}; -template struct IsArray: True {}; -template struct IsArray: True {}; +template struct IsArray : False {}; +template struct IsArray: True {}; +template struct IsArray: True {}; /* is pointer */ @@ -142,7 +142,7 @@ namespace detail { } template -struct IsPointer: octa::detail::IsPointerBase> {}; +struct IsPointer: detail::IsPointerBase> {}; /* is lvalue reference */ @@ -178,11 +178,11 @@ namespace detail { template T &function_source(int); template FunctionTestDummy function_source(...); - template::value || - octa::IsUnion::value || - octa::IsVoid::value || - octa::IsReference::value || - octa::IsNullPointer::value + template::value || + IsUnion::value || + IsVoid::value || + IsReference::value || + IsNullPointer::value > struct IsFunctionBase: IntegralConstant(function_source(0))) == 1 > {}; @@ -190,7 +190,7 @@ namespace detail { template struct IsFunctionBase: False {}; } /* namespace detail */ -template struct IsFunction: octa::detail::IsFunctionBase {}; +template struct IsFunction: detail::IsFunctionBase {}; /* is arithmetic */ @@ -221,7 +221,7 @@ namespace detail { } template -struct IsMemberPointer: octa::detail::IsMemberPointerBase> {}; +struct IsMemberPointer: detail::IsMemberPointerBase> {}; /* is pointer to member object */ @@ -231,12 +231,12 @@ namespace detail { template struct IsMemberObjectPointerBase: IntegralConstant::value + !IsFunction::value > {}; } template struct IsMemberObjectPointer: - octa::detail::IsMemberObjectPointerBase> {}; + detail::IsMemberObjectPointerBase> {}; /* is pointer to member function */ @@ -246,12 +246,12 @@ namespace detail { template struct IsMemberFunctionPointerBase: IntegralConstant::value + IsFunction::value > {}; } template struct IsMemberFunctionPointer: - octa::detail::IsMemberFunctionPointerBase> {}; + detail::IsMemberFunctionPointerBase> {}; /* is reference */ @@ -308,11 +308,11 @@ namespace detail { struct IsSignedBase: IntegralConstant {}; } -template::value> +template::value> struct IsSigned: False {}; template -struct IsSigned: octa::detail::IsSignedBase {}; +struct IsSigned: detail::IsSignedBase {}; /* is unsigned */ @@ -321,11 +321,11 @@ namespace detail { struct IsUnsignedBase: IntegralConstant {}; } -template::value> +template::value> struct IsUnsigned: False {}; template -struct IsUnsigned: octa::detail::IsUnsignedBase {}; +struct IsUnsigned: detail::IsUnsignedBase {}; /* is standard layout */ @@ -359,7 +359,7 @@ struct HasVirtualDestructor: IntegralConstant &&>(v) +#define OCTA_MOVE(v) static_cast &&>(v) template struct Select2nd { using Type = T; }; struct Any { Any(...); }; @@ -383,7 +383,7 @@ namespace detail { /* scalars are default constructible, refs are not */ template - struct CtibleCore: octa::IsScalar {}; + struct CtibleCore: IsScalar {}; /* scalars and references are constructible from one arg if * implicitly convertible to scalar or reference */ @@ -405,7 +405,7 @@ namespace detail { /* treat scalars and refs separately */ template struct CtibleVoidCheck: CtibleCore< - (octa::IsScalar::value || octa::IsReference::value), T, A... + (IsScalar::value || IsReference::value), T, A... > {}; /* if any of T or A is void, IsConstructible should be false */ @@ -418,23 +418,23 @@ namespace detail { template struct CtibleContainsVoid { - static constexpr bool value = octa::IsVoid::value + static constexpr bool value = IsVoid::value || CtibleContainsVoid::value; }; /* entry point */ template struct Ctible: CtibleVoidCheck< - CtibleContainsVoid::value || octa::IsAbstract::value, + CtibleContainsVoid::value || IsAbstract::value, T, A... > {}; /* array types are default constructible if their element type is */ - template - struct CtibleCore: Ctible> {}; + template + struct CtibleCore: Ctible> {}; /* otherwise array types are not constructible by this syntax */ - template + template struct CtibleCore: False {}; /* incomplete array types are not constructible */ @@ -443,7 +443,7 @@ namespace detail { } /* namespace detail */ template -struct IsConstructible: octa::detail::Ctible {}; +struct IsConstructible: detail::Ctible {}; /* is default constructible */ @@ -464,14 +464,14 @@ template struct IsMoveConstructible: IsConstructible typename octa::detail::Select2nd< + template typename detail::Select2nd< decltype((declval_in() = declval_in())), True >::Type assign_test(T &&, U &&); template False assign_test(Any, T &&); - template::value || - octa::IsVoid::value + template::value || + IsVoid::value > struct IsAssignableBase: CommonTypeBase< decltype(assign_test(declval_in(), declval_in())) >::Type {}; @@ -481,7 +481,7 @@ namespace detail { } /* namespace detail */ template -struct IsAssignable: octa::detail::IsAssignableBase {}; +struct IsAssignable: detail::IsAssignableBase {}; /* is copy assignable */ @@ -504,7 +504,7 @@ namespace detail { template struct IsDestructorWellformed { template static char test(typename IsDtibleApply< - decltype(octa::detail::declval_in().~TT()) + decltype(detail::declval_in().~TT()) >::Type); template static int test(...); @@ -515,8 +515,8 @@ namespace detail { template struct DtibleImpl; template - struct DtibleImpl: octa::IntegralConstant>::value + struct DtibleImpl: IntegralConstant>::value > {}; template @@ -525,13 +525,13 @@ namespace detail { template struct DtibleFalse; template struct DtibleFalse - : DtibleImpl::value> {}; + : DtibleImpl::value> {}; template struct DtibleFalse: False {}; } /* namespace detail */ template -struct IsDestructible: octa::detail::DtibleFalse::value> {}; +struct IsDestructible: detail::DtibleFalse::value> {}; template struct IsDestructible: False {}; template< > struct IsDestructible: False {}; @@ -634,10 +634,10 @@ struct IsBaseOf: IntegralConstant {}; /* is convertible */ namespace detail { - template::value - || octa::IsFunction::value || octa::IsArray::value + template::value + || IsFunction::value || IsArray::value > struct IsConvertibleBase { - using Type = typename octa::IsVoid::Type; + using Type = typename IsVoid::Type; }; template @@ -646,16 +646,16 @@ namespace detail { template(declval_in())) - > static octa::True test(int); + > static True test(int); - template static octa::False test(...); + template static False test(...); using Type = decltype(test(0)); }; } template -struct IsConvertible: octa::detail::IsConvertibleBase::Type {}; +struct IsConvertible: detail::IsConvertibleBase::Type {}; /* type equality */ @@ -664,30 +664,30 @@ template struct IsSame: True {}; /* extent */ -template -struct Extent: IntegralConstant {}; +template +struct Extent: IntegralConstant {}; template -struct Extent: IntegralConstant {}; +struct Extent: IntegralConstant {}; -template -struct Extent: IntegralConstant::value> {}; +template +struct Extent: IntegralConstant::value> {}; -template -struct Extent: IntegralConstant {}; +template +struct Extent: IntegralConstant {}; -template -struct Extent: IntegralConstant::value> {}; +template +struct Extent: IntegralConstant::value> {}; /* rank */ -template struct Rank: IntegralConstant {}; +template struct Rank: IntegralConstant {}; template -struct Rank: IntegralConstant::value + 1> {}; +struct Rank: IntegralConstant::value + 1> {}; -template -struct Rank: IntegralConstant::value + 1> {}; +template +struct Rank: IntegralConstant::value + 1> {}; /* remove const, volatile, cv */ @@ -704,22 +704,22 @@ namespace detail { } template -using RemoveConst = typename octa::detail::RemoveConstBase::Type; +using RemoveConst = typename detail::RemoveConstBase::Type; template -using RemoveVolatile = typename octa::detail::RemoveVolatileBase::Type; +using RemoveVolatile = typename detail::RemoveVolatileBase::Type; namespace detail { template struct RemoveCvBase { - using Type = octa::RemoveVolatile>; + using Type = RemoveVolatile>; }; } /* add const, volatile, cv */ namespace detail { - template::value - || octa::IsFunction::value || octa::IsConst::value> + template::value + || IsFunction::value || IsConst::value> struct AddConstCore { using Type = T; }; template struct AddConstCore { @@ -730,8 +730,8 @@ namespace detail { using Type = typename AddConstCore::Type; }; - template::value - || octa::IsFunction::value || octa::IsVolatile::value> + template::value + || IsFunction::value || IsVolatile::value> struct AddVolatileCore { using Type = T; }; template struct AddVolatileCore { @@ -744,17 +744,17 @@ namespace detail { } template -using AddVolatile = typename octa::detail::AddVolatileBase::Type; +using AddVolatile = typename detail::AddVolatileBase::Type; namespace detail { template struct AddCvBase { - using Type = octa::AddConst>; + using Type = AddConst>; }; } template -using AddCv = typename octa::detail::AddCvBase::Type; +using AddCv = typename detail::AddCvBase::Type; /* remove reference */ @@ -783,18 +783,18 @@ namespace detail { } template -using RemovePointer = typename octa::detail::RemovePointerBase::Type; +using RemovePointer = typename detail::RemovePointerBase::Type; /* add pointer */ namespace detail { template struct AddPointerBase { - using Type = octa::RemoveReference *; + using Type = RemoveReference *; }; } template -using AddPointer = typename octa::detail::AddPointerBase::Type; +using AddPointer = typename detail::AddPointerBase::Type; /* add lvalue reference */ @@ -843,12 +843,12 @@ namespace detail { struct RemoveExtentBase { using Type = T; }; template struct RemoveExtentBase { using Type = T; }; - template + template struct RemoveExtentBase { using Type = T; }; } template -using RemoveExtent = typename octa::detail::RemoveExtentBase::Type; +using RemoveExtent = typename detail::RemoveExtentBase::Type; /* remove all extents */ @@ -859,7 +859,7 @@ namespace detail { using Type = RemoveAllExtentsBase; }; - template struct RemoveAllExtentsBase { + template struct RemoveAllExtentsBase { using Type = RemoveAllExtentsBase; }; } @@ -884,34 +884,34 @@ namespace detail { ~TlNat() = delete; }; - using Stypes = TypeList>>>>; + TypeList>>>>; - using Utypes = TypeList>>>>; + using Utypes = TypeList>>>>; - template + template struct TypeFindFirst; - template + template struct TypeFindFirst, N, true> { using Type = T; }; - template + template struct TypeFindFirst, N, false> { using Type = typename TypeFindFirst::Type; }; template>::value, - bool = octa::IsVolatile>::value + bool = IsConst>::value, + bool = IsVolatile>::value > struct ApplyCv { using Type = U; }; @@ -946,67 +946,67 @@ namespace detail { using Type = const volatile U &; }; - template::value || - octa::IsEnum::value> - struct MakeSigned {}; + template::value || + IsEnum::value> + struct MakeSignedCore {}; - template::value || - octa::IsEnum::value> - struct MakeUnsigned {}; + template::value || + IsEnum::value> + struct MakeUnsignedCore {}; template - struct MakeSigned { + struct MakeSignedCore { using Type = typename TypeFindFirst::Type; }; template - struct MakeUnsigned { + struct MakeUnsignedCore { using Type = typename TypeFindFirst::Type; }; - template<> struct MakeSigned {}; - template<> struct MakeSigned { using Type = short; }; - template<> struct MakeSigned { using Type = int; }; - template<> struct MakeSigned { using Type = long; }; + template<> struct MakeSignedCore {}; + template<> struct MakeSignedCore { using Type = short; }; + template<> struct MakeSignedCore { using Type = int; }; + template<> struct MakeSignedCore { using Type = long; }; - template<> struct MakeSigned { using Type = octa::sbyte; }; - template<> struct MakeSigned { using Type = octa::sbyte; }; - template<> struct MakeSigned { using Type = short; }; - template<> struct MakeSigned { using Type = int; }; - template<> struct MakeSigned { using Type = long; }; - template<> struct MakeSigned { using Type = octa::llong; }; - template<> struct MakeSigned { using Type = octa::llong; }; + template<> struct MakeSignedCore { using Type = sbyte; }; + template<> struct MakeSignedCore { using Type = sbyte; }; + template<> struct MakeSignedCore { using Type = short; }; + template<> struct MakeSignedCore { using Type = int; }; + template<> struct MakeSignedCore { using Type = long; }; + template<> struct MakeSignedCore { using Type = llong; }; + template<> struct MakeSignedCore { using Type = llong; }; - template<> struct MakeUnsigned {}; - template<> struct MakeUnsigned { using Type = octa::ushort; }; - template<> struct MakeUnsigned { using Type = octa::uint; }; - template<> struct MakeUnsigned { using Type = octa::ulong; }; + template<> struct MakeUnsignedCore {}; + template<> struct MakeUnsignedCore { using Type = ushort; }; + template<> struct MakeUnsignedCore { using Type = uint; }; + template<> struct MakeUnsignedCore { using Type = ulong; }; - template<> struct MakeUnsigned { using Type = octa::byte; }; - template<> struct MakeUnsigned { using Type = octa::byte; }; - template<> struct MakeUnsigned { using Type = octa::ushort; }; - template<> struct MakeUnsigned { using Type = octa::uint; }; - template<> struct MakeUnsigned { using Type = octa::ulong; }; - template<> struct MakeUnsigned { using Type = octa::ullong; }; - template<> struct MakeUnsigned { using Type = octa::ullong; }; + template<> struct MakeUnsignedCore { using Type = byte; }; + template<> struct MakeUnsignedCore { using Type = byte; }; + template<> struct MakeUnsignedCore { using Type = ushort; }; + template<> struct MakeUnsignedCore { using Type = uint; }; + template<> struct MakeUnsignedCore { using Type = ulong; }; + template<> struct MakeUnsignedCore { using Type = ullong; }; + template<> struct MakeUnsignedCore { using Type = ullong; }; template struct MakeSignedBase { using Type = typename ApplyCv>::Type + typename MakeSignedCore>::Type >::Type; }; template struct MakeUnsignedBase { using Type = typename ApplyCv>::Type + typename MakeUnsignedCore>::Type >::Type; }; } /* namespace detail */ template -using MakeSigned = typename octa::detail::MakeSignedBase::Type; +using MakeSigned = typename detail::MakeSignedBase::Type; template -using MakeUnsigned = typename octa::detail::MakeUnsignedBase::Type; +using MakeUnsigned = typename detail::MakeUnsignedBase::Type; /* conditional */ @@ -1023,7 +1023,7 @@ namespace detail { } template -using Conditional = typename octa::detail::ConditionalBase<_cond, T, U>::Type; +using Conditional = typename detail::ConditionalBase<_cond, T, U>::Type; /* result of call at compile time */ @@ -1062,16 +1062,16 @@ namespace detail { struct ResultOfCore {}; template struct ResultOfCore(), octa::detail::declval_in()...)))> { - using type = decltype(rof_invoke(octa::detail::declval_in(), - octa::detail::declval_in()...)); + detail::declval_in(), detail::declval_in()...)))> { + using type = decltype(rof_invoke(detail::declval_in(), + detail::declval_in()...)); }; template struct ResultOfBase: ResultOfCore {}; } /* namespace detail */ template -using ResultOf = typename octa::detail::ResultOfBase::Type; +using ResultOf = typename detail::ResultOfBase::Type; /* enable if */ @@ -1082,7 +1082,7 @@ namespace detail { } template -using EnableIf = typename octa::detail::EnableIfBase::Type; +using EnableIf = typename detail::EnableIfBase::Type; /* decay */ @@ -1090,18 +1090,18 @@ namespace detail { template struct DecayBase { private: - using U = octa::RemoveReference; + using U = RemoveReference; public: - using Type = octa::Conditional::value, - octa::RemoveExtent *, - octa::Conditional::value, - octa::AddPointer, octa::RemoveCv> + using Type = Conditional::value, + RemoveExtent *, + Conditional::value, + AddPointer, RemoveCv> >; }; } template -using Decay = typename octa::detail::DecayBase::Type; +using Decay = typename detail::DecayBase::Type; /* common type */ @@ -1113,8 +1113,8 @@ namespace detail { }; template struct CommonTypeBase { - using Type = Decay() - : octa::detail::declval_in())>; + using Type = Decay() + : detail::declval_in())>; }; template @@ -1126,61 +1126,61 @@ namespace detail { } template -using CommonType = typename octa::detail::CommonTypeBase::Type; +using CommonType = typename detail::CommonTypeBase::Type; /* aligned storage */ namespace detail { - template struct AlignedTest { + template struct AlignedTest { union Type { - octa::byte data[N]; - octa::MaxAlign align; + byte data[N]; + MaxAlign align; }; }; - template struct AlignedStorageBase { + template struct AlignedStorageBase { struct Type { - alignas(A) octa::byte data[N]; + alignas(A) byte data[N]; }; }; } -template::Type) -> using AlignedStorage = typename octa::detail::AlignedStorageBase::Type; +template::Type) +> using AlignedStorage = typename detail::AlignedStorageBase::Type; /* aligned union */ namespace detail { - template struct AlignMax; + template struct AlignMax; - template struct AlignMax { - static constexpr octa::Size value = N; + template struct AlignMax { + static constexpr Size value = N; }; - template struct AlignMax { - static constexpr octa::Size value = (N1 > N2) ? N1 : N2; + template struct AlignMax { + static constexpr Size value = (N1 > N2) ? N1 : N2; }; - template + template struct AlignMax { - static constexpr octa::Size value + static constexpr Size value = AlignMax::value, N...>::value; }; - template struct AlignedUnionBase { - static constexpr octa::Size alignment_value + template struct AlignedUnionBase { + static constexpr Size alignment_value = AlignMax::value; struct type { - alignas(alignment_value) octa::byte data[AlignMax::value]; }; }; } /* namespace detail */ -template -using AlignedUnion = typename octa::detail::AlignedUnionBase::Type; +template +using AlignedUnion = typename detail::AlignedUnionBase::Type; /* underlying type */ @@ -1192,7 +1192,7 @@ namespace detail { } template -using UnderlyingType = typename octa::detail::UnderlyingTypeBase::Type; +using UnderlyingType = typename detail::UnderlyingTypeBase::Type; } /* namespace octa */ #endif \ No newline at end of file diff --git a/octa/utility.hh b/octa/utility.hh index 8af2881..5919d44 100644 --- a/octa/utility.hh +++ b/octa/utility.hh @@ -56,26 +56,26 @@ namespace detail { }; template inline void swap(T &a, T &b, EnableIf< - octa::detail::SwapTest::value, bool + detail::SwapTest::value, bool > = true) { a.swap(b); } template inline void swap(T &a, T &b, EnableIf< - !octa::detail::SwapTest::value, bool + !detail::SwapTest::value, bool > = true) { - T c(octa::move(a)); - a = octa::move(b); - b = octa::move(c); + T c(move(a)); + a = move(b); + b = move(c); } } template void swap(T &a, T &b) { - octa::detail::swap(a, b); + detail::swap(a, b); } -template void swap(T (&a)[N], T (&b)[N]) { - for (octa::Size i = 0; i < N; ++i) { +template void swap(T (&a)[N], T (&b)[N]) { + for (Size i = 0; i < N; ++i) { octa::swap(a[i], b[i]); } } @@ -97,14 +97,14 @@ struct Pair { template Pair(TT &&x, UU &&y): - first(octa::forward(x)), second(octa::forward(y)) {} + first(forward(x)), second(forward(y)) {} template Pair(const Pair &v): first(v.first), second(v.second) {} template Pair(Pair &&v): - first(octa::move(v.first)), second(octa::move(v.second)) {} + first(move(v.first)), second(move(v.second)) {} Pair &operator=(const Pair &v) { first = v.first; @@ -120,21 +120,21 @@ struct Pair { } Pair &operator=(Pair &&v) { - first = octa::move(v.first); - second = octa::move(v.second); + first = move(v.first); + second = move(v.second); return *this; } template Pair &operator=(Pair &&v) { - first = octa::forward(v.first); - second = octa::forward(v.second); + first = forward(v.first); + second = forward(v.second); return *this; } void swap(Pair &v) { - octa::swap(first, v.first); - octa::swap(second, v.second); + swap(first, v.first); + swap(second, v.second); } }; @@ -153,24 +153,24 @@ namespace detail { template struct MakePairRet { - using Type = typename octa::detail::MakePairRetBase>::Type; + using Type = typename detail::MakePairRetBase>::Type; }; } /* namespace detail */ template -Pair::Type, - typename octa::detail::MakePairRet::Type +Pair::Type, + typename detail::MakePairRet::Type > make_pair(T &&a, U &&b) { - return Pair::Type, - typename octa::detail::MakePairRet::Type + return Pair::Type, + typename detail::MakePairRet::Type >(forward(a), forward(b));; } namespace detail { template, octa::RemoveCv>::value, - bool = octa::IsEmpty::value, - bool = octa::IsEmpty::value + bool = IsSame, RemoveCv>::value, + bool = IsEmpty::value, + bool = IsEmpty::value > struct CompressedPairSwitch; /* neither empty */ @@ -193,7 +193,7 @@ namespace detail { template struct CompressedPairSwitch { enum { value = 1 }; }; - template::value> + template::value> struct CompressedPairBase; template @@ -202,8 +202,8 @@ namespace detail { U p_second; template - CompressedPairBase(TT &&a, UU &&b): p_first(octa::forward(a)), - p_second(octa::forward(b)) {} + CompressedPairBase(TT &&a, UU &&b): p_first(forward(a)), + p_second(forward(b)) {} T &first() { return p_first; } const T &first() const { return p_first; } @@ -222,8 +222,8 @@ namespace detail { U p_second; template - CompressedPairBase(TT &&a, UU &&b): T(octa::forward(a)), - p_second(octa::forward(b)) {} + CompressedPairBase(TT &&a, UU &&b): T(forward(a)), + p_second(forward(b)) {} T &first() { return *this; } const T &first() const { return *this; } @@ -241,8 +241,8 @@ namespace detail { T p_first; template - CompressedPairBase(TT &&a, UU &&b): U(octa::forward(b)), - p_first(octa::forward(a)) {} + CompressedPairBase(TT &&a, UU &&b): U(forward(b)), + p_first(forward(a)) {} T &first() { return p_first; } const T &first() const { return p_first; } @@ -258,8 +258,8 @@ namespace detail { template struct CompressedPairBase: T, U { template - CompressedPairBase(TT &&a, UU &&b): T(octa::forward(a)), - U(octa::forward(b)) {} + CompressedPairBase(TT &&a, UU &&b): T(forward(a)), + U(forward(b)) {} T &first() { return *this; } const T &first() const { return *this; } @@ -275,8 +275,8 @@ namespace detail { using Base = CompressedPairBase; template - CompressedPair(TT &&a, UU &&b): Base(octa::forward(a), - octa::forward(b)) {} + CompressedPair(TT &&a, UU &&b): Base(forward(a), + forward(b)) {} T &first() { return Base::first(); } const T &first() const { return Base::first(); } diff --git a/octa/vector.hh b/octa/vector.hh index 02eb16d..f69efbe 100644 --- a/octa/vector.hh +++ b/octa/vector.hh @@ -21,28 +21,28 @@ namespace octa { namespace detail { } /* namespace detail */ -template> +template> class Vector { - using VecPair = octa::detail::CompressedPair, A>; + using VecPair = detail::CompressedPair, A>; - octa::Size p_len, p_cap; + Size p_len, p_cap; VecPair p_buf; - void insert_base(octa::Size idx, octa::Size n) { + void insert_base(Size idx, Size n) { if (p_len + n > p_cap) reserve(p_len + n); p_len += n; - for (octa::Size i = p_len - 1; i > idx + n - 1; --i) { - p_buf.first()[i] = octa::move(p_buf.first()[i - n]); + for (Size i = p_len - 1; i > idx + n - 1; --i) { + p_buf.first()[i] = move(p_buf.first()[i - n]); } } template - void ctor_from_range(R &range, octa::EnableIf< - octa::IsFiniteRandomAccessRange::value && - octa::IsPod::value && - octa::IsSame>>::value, bool + void ctor_from_range(R &range, EnableIf< + IsFiniteRandomAccessRange::value && + IsPod::value && + IsSame>>::value, bool > = true) { - octa::RangeSize l = range.size(); + RangeSize l = range.size(); reserve(l); p_len = l; range.copy(p_buf.first(), l); @@ -50,58 +50,57 @@ class Vector { template void ctor_from_range(R &range, EnableIf< - !octa::IsFiniteRandomAccessRange::value || - !octa::IsPod::value || - !octa::IsSame>>::value, bool + !IsFiniteRandomAccessRange::value || + !IsPod::value || + !IsSame>>::value, bool > = true) { - octa::Size i = 0; + Size i = 0; for (; !range.empty(); range.pop_front()) { reserve(i + 1); - octa::allocator_construct(p_buf.second(), - &p_buf.first()[i], range.front()); + allocator_construct(p_buf.second(), &p_buf.first()[i], + range.front()); ++i; p_len = i; } } void copy_contents(const Vector &v) { - if (octa::IsPod()) { + if (IsPod()) { memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; Pointer vbuf = v.p_buf.first(); while (cur != last) { - octa::allocator_construct(p_buf.second(), - cur++, *vbuf++); + allocator_construct(p_buf.second(), cur++, *vbuf++); } } } public: - using Size = octa::Size; - using Difference = octa::Ptrdiff; + using Size = Size; + using Difference = Ptrdiff; using Value = T; using Reference = T &; using ConstReference = const T &; - using Pointer = octa::AllocatorPointer; - using ConstPointer = octa::AllocatorConstPointer; - using Range = octa::PointerRange; - using ConstRange = octa::PointerRange; + using Pointer = AllocatorPointer; + using ConstPointer = AllocatorConstPointer; + using Range = PointerRange; + using ConstRange = PointerRange; using Allocator = A; Vector(const A &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) { - p_buf.first() = octa::allocator_allocate(p_buf.second(), n); + p_buf.first() = allocator_allocate(p_buf.second(), n); p_len = p_cap = n; Pointer cur = p_buf.first(), last = p_buf.first() + n; while (cur != last) - octa::allocator_construct(p_buf.second(), cur++, val); + allocator_construct(p_buf.second(), cur++, val); } Vector(const Vector &v): p_len(0), p_cap(0), p_buf(nullptr, - octa::allocator_container_copy(v.p_buf.second())) { + allocator_container_copy(v.p_buf.second())) { reserve(v.p_cap); p_len = v.p_len; copy_contents(v); @@ -114,7 +113,7 @@ public: } Vector(Vector &&v): p_len(v.p_len), p_cap(v.p_cap), p_buf(v.p_buf.first(), - octa::move(v.p_buf.second())) { + move(v.p_buf.second())) { v.p_buf.first() = nullptr; v.p_len = v.p_cap = 0; } @@ -123,14 +122,13 @@ public: if (a != v.p_buf.second()) { reserve(v.p_cap); p_len = v.p_len; - if (octa::IsPod()) { + if (IsPod()) { memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; Pointer vbuf = v.p_buf.first(); while (cur != last) { - octa::allocator_construct(p_buf.second(), cur++, - octa::move(*vbuf++)); + allocator_construct(p_buf.second(), cur++, move(*vbuf++)); } } return; @@ -144,12 +142,11 @@ public: Vector(const Value *buf, Size n, const A &a = A()): Vector(a) { reserve(n); - if (octa::IsPod()) { + if (IsPod()) { memcpy(p_buf.first(), buf, n * sizeof(T)); } else { for (Size i = 0; i < n; ++i) - octa::allocator_construct(p_buf.second(), - &p_buf.first()[i], buf[i]); + allocator_construct(p_buf.second(), &p_buf.first()[i], buf[i]); } p_len = n; } @@ -157,23 +154,23 @@ public: Vector(InitializerList v, const A &a = A()): Vector(v.begin(), v.size(), a) {} - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> Vector(R range, const A &a = A()): Vector(a) { ctor_from_range(range); } ~Vector() { clear(); - octa::allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); + allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); } void clear() { - if (p_len > 0 && !octa::IsPod()) { + if (p_len > 0 && !IsPod()) { Pointer cur = p_buf.first(), last = p_buf.first() + p_len; while (cur != last) - octa::allocator_destroy(p_buf.second(), cur++); + allocator_destroy(p_buf.second(), cur++); } p_len = 0; } @@ -181,9 +178,9 @@ public: Vector &operator=(const Vector &v) { if (this == &v) return *this; clear(); - if (octa::AllocatorPropagateOnContainerCopyAssignment::value) { + if (AllocatorPropagateOnContainerCopyAssignment::value) { if (p_buf.second() != v.p_buf.second()) { - octa::allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); + allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); p_cap = 0; } p_buf.second() = v.p_buf.second(); @@ -196,13 +193,13 @@ public: Vector &operator=(Vector &&v) { clear(); - octa::allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); - if (octa::AllocatorPropagateOnContainerMoveAssignment::value) + allocator_deallocate(p_buf.second(), p_buf.first(), p_cap); + if (AllocatorPropagateOnContainerMoveAssignment::value) p_buf.second() = v.p_buf.second(); p_len = v.p_len; p_cap = v.p_cap; p_buf.~VecPair(); - new (&p_buf) VecPair(v.disown(), octa::move(v.p_buf.second())); + new (&p_buf) VecPair(v.disown(), move(v.p_buf.second())); return *this; } @@ -210,13 +207,13 @@ public: clear(); Size ilen = il.end() - il.begin(); reserve(ilen); - if (octa::IsPod()) { + if (IsPod()) { memcpy(p_buf.first(), il.begin(), ilen); } else { Pointer tbuf = p_buf.first(), ibuf = il.begin(), last = il.end(); while (ibuf != last) { - octa::allocator_construct(p_buf.second(), + allocator_construct(p_buf.second(), tbuf++, *ibuf++); } } @@ -224,9 +221,9 @@ public: return *this; } - template::value && - octa::IsConvertible, Value>::value + template::value && + IsConvertible, Value>::value >> Vector &operator=(R range) { clear(); ctor_from_range(range); @@ -237,7 +234,7 @@ public: Size l = p_len; reserve(n); p_len = n; - if (octa::IsPod()) { + if (IsPod()) { for (Size i = l; i < p_len; ++i) { p_buf.first()[i] = T(v); } @@ -245,7 +242,7 @@ public: Pointer first = p_buf.first() + l; Pointer last = p_buf.first() + p_len; while (first != last) - octa::allocator_construct(p_buf.second(), first++, v); + allocator_construct(p_buf.second(), first++, v); } } @@ -253,25 +250,24 @@ public: if (n <= p_cap) return; Size oc = p_cap; if (!oc) { - p_cap = octa::max(n, Size(8)); + p_cap = max(n, Size(8)); } else { while (p_cap < n) p_cap *= 2; } - Pointer tmp = octa::allocator_allocate(p_buf.second(), p_cap); + Pointer tmp = allocator_allocate(p_buf.second(), p_cap); if (oc > 0) { - if (octa::IsPod()) { + if (IsPod()) { memcpy(tmp, p_buf.first(), p_len * sizeof(T)); } else { Pointer cur = p_buf.first(), tcur = tmp, last = tmp + p_len; while (tcur != last) { - octa::allocator_construct(p_buf.second(), tcur++, - octa::move(*cur)); - octa::allocator_destroy(p_buf.second(), cur); + allocator_construct(p_buf.second(), tcur++, move(*cur)); + allocator_destroy(p_buf.second(), cur); ++cur; } } - octa::allocator_deallocate(p_buf.second(), p_buf.first(), oc); + allocator_deallocate(p_buf.second(), p_buf.first(), oc); } p_buf.first() = tmp; } @@ -290,36 +286,33 @@ public: T &push(const T &v) { if (p_len == p_cap) reserve(p_len + 1); - octa::allocator_construct(p_buf.second(), - &p_buf.first()[p_len], v); + allocator_construct(p_buf.second(), &p_buf.first()[p_len], v); return p_buf.first()[p_len++]; } T &push(T &&v) { if (p_len == p_cap) reserve(p_len + 1); - octa::allocator_construct(p_buf.second(), - &p_buf.first()[p_len], octa::move(v)); + allocator_construct(p_buf.second(), &p_buf.first()[p_len], move(v)); return p_buf.first()[p_len++]; } T &push() { if (p_len == p_cap) reserve(p_len + 1); - octa::allocator_construct(p_buf.second(), &p_buf.first()[p_len]); + allocator_construct(p_buf.second(), &p_buf.first()[p_len]); return p_buf.first()[p_len++]; } template T &emplace_back(U &&...args) { if (p_len == p_cap) reserve(p_len + 1); - octa::allocator_construct(p_buf.second(), &p_buf.first()[p_len], - octa::forward(args)...); + allocator_construct(p_buf.second(), &p_buf.first()[p_len], + forward(args)...); return p_buf.first()[p_len++]; } void pop() { - if (!octa::IsPod()) { - octa::allocator_destroy(p_buf.second(), - &p_buf.first()[--p_len]); + if (!IsPod()) { + allocator_destroy(p_buf.second(), &p_buf.first()[--p_len]); } else { --p_len; } @@ -356,7 +349,7 @@ public: Range insert(Size idx, T &&v) { insert_base(idx, 1); - p_buf.first()[idx] = octa::move(v); + p_buf.first()[idx] = move(v); return Range(&p_buf.first()[idx], &p_buf.first()[p_len]); } @@ -407,7 +400,7 @@ public: octa::swap(p_len, v.p_len); octa::swap(p_cap, v.p_cap); octa::swap(p_buf.first(), v.p_buf.first()); - if (octa::AllocatorPropagateOnContainerSwap::value) + if (AllocatorPropagateOnContainerSwap::value) octa::swap(p_buf.second(), v.p_buf.second()); }