const syntax refactoring

master
Daniel Kolesa 2016-06-23 19:18:35 +01:00
parent 430ca81bfd
commit 7912c24e3a
25 changed files with 801 additions and 810 deletions

View File

@ -12,7 +12,7 @@ struct Foo {
/* implementing formatting for custom objects - external function */
template<typename R>
bool to_format(const Foo &, R &writer, const FormatSpec &fs) {
bool to_format(Foo const &, R &writer, FormatSpec const &fs) {
switch (fs.spec()) {
case 'i':
writer.put_string("Foo1");
@ -27,7 +27,7 @@ bool to_format(const Foo &, R &writer, const FormatSpec &fs) {
struct Bar {
/* implementing formatting for custom objects - method */
template<typename R>
bool to_format(R &writer, const FormatSpec &fs) const {
bool to_format(R &writer, FormatSpec const &fs) const {
switch (fs.spec()) {
case 'i':
writer.put_string("Bar1");
@ -64,7 +64,7 @@ int main() {
writefln("{ %-#(%s: %d, %) }", m);
/* tuple format test */
Tuple<int, float, const char *> xt[] = {
Tuple<int, float, char const *> xt[] = {
make_tuple(5, 3.14f, "foo"),
make_tuple(3, 1.23f, "bar"),
make_tuple(9, 8.66f, "baz")

View File

@ -9,8 +9,8 @@ struct SignalTest {
* can actually emit (in that case, the reference passed to each
* callback will always be const to make sure nothing changes)
*/
Signal<const SignalTest, int, ConstCharRange> on_simple = this;
Signal< SignalTest, float > on_param = this;
Signal<SignalTest const, int, ConstCharRange> on_simple = this;
Signal<SignalTest , float > on_param = this;
SignalTest(): p_param(3.14f) {
/* we can connect methods */
@ -48,7 +48,7 @@ int main() {
/* we can connect lambdas, including closures
* this callback can access "test" easily and it will still work
*/
auto idx = st.on_simple.connect([&](const SignalTest &, int v,
auto idx = st.on_simple.connect([&](SignalTest const &, int v,
ConstCharRange str) {
writefln("and lambda test: %d, %s (%d)", v, str, test);
});

View File

@ -156,20 +156,20 @@ inline auto sort() {
/* min/max(_element) */
template<typename T>
inline const T &min(const T &a, const T &b) {
inline T const &min(T const &a, T const &b) {
return (a < b) ? a : b;
}
template<typename T, typename C>
inline const T &min_cmp(const T &a, const T &b, C compare) {
inline T const &min_cmp(T const &a, T const &b, C compare) {
return compare(a, b) ? a : b;
}
template<typename T>
inline const T &max(const T &a, const T &b) {
inline T const &max(T const &a, T const &b) {
return (a < b) ? b : a;
}
template<typename T, typename C>
inline const T &max_cmp(const T &a, const T &b, C compare) {
inline T const &max_cmp(T const &a, T const &b, C compare) {
return compare(a, b) ? b : a;
}
@ -247,12 +247,12 @@ inline T max_cmp(std::initializer_list<T> il, C compare) {
/* clamp */
template<typename T, typename U>
inline T clamp(const T &v, const U &lo, const U &hi) {
inline T clamp(T const &v, U const &lo, U const &hi) {
return ostd::max(T(lo), ostd::min(v, T(hi)));
}
template<typename T, typename U, typename C>
inline T clamp(const T &v, const U &lo, const U &hi, C compare) {
inline T clamp(T const &v, U const &lo, U const &hi, C compare) {
return ostd::max_cmp(T(lo), ostd::min_cmp(v, T(hi), compare), compare);
}
@ -352,7 +352,7 @@ inline auto none_of(F &&func) {
}
template<typename R, typename T>
inline R find(R range, const T &v) {
inline R find(R range, T const &v) {
for (; !range.empty(); range.pop_front())
if (range.front() == v)
break;
@ -367,7 +367,7 @@ inline auto find(T &&v) {
}
template<typename R, typename T>
inline R find_last(R range, const T &v) {
inline R find_last(R range, T const &v) {
range = find(range, v);
if (!range.empty()) for (;;) {
R prev = range;
@ -449,7 +449,7 @@ inline auto find_one_of(R &&values) {
}
template<typename R, typename T>
inline RangeSize<R> count(R range, const T &v) {
inline RangeSize<R> count(R range, T const &v) {
RangeSize<R> ret = 0;
for (; !range.empty(); range.pop_front())
if (range.front() == v)
@ -574,7 +574,7 @@ inline R2 reverse_copy(R1 irange, R2 orange) {
}
template<typename R, typename T>
inline void fill(R range, const T &v) {
inline void fill(R range, T const &v) {
for (; !range.empty(); range.pop_front())
range.front() = v;
}
@ -666,14 +666,14 @@ private:
public:
MapRange() = delete;
template<typename FF>
MapRange(const T &range, FF &&func):
MapRange(T const &range, FF &&func):
p_range(range), p_func(forward<FF>(func)) {}
MapRange(const MapRange &it):
MapRange(MapRange const &it):
p_range(it.p_range), p_func(it.p_func) {}
MapRange(MapRange &&it):
p_range(move(it.p_range)), p_func(move(it.p_func)) {}
MapRange &operator=(const MapRange &v) {
MapRange &operator=(MapRange const &v) {
p_range = v.p_range;
p_func = v.p_func;
return *this;
@ -687,17 +687,17 @@ public:
bool empty() const { return p_range.empty(); }
RangeSize<T> size() const { return p_range.size(); }
bool equals_front(const MapRange &r) const {
bool equals_front(MapRange const &r) const {
return p_range.equals_front(r.p_range);
}
bool equals_back(const MapRange &r) const {
bool equals_back(MapRange const &r) const {
return p_range.equals_front(r.p_range);
}
RangeDifference<T> distance_front(const MapRange &r) const {
RangeDifference<T> distance_front(MapRange const &r) const {
return p_range.distance_front(r.p_range);
}
RangeDifference<T> distance_back(const MapRange &r) const {
RangeDifference<T> distance_back(MapRange const &r) const {
return p_range.distance_back(r.p_range);
}
@ -766,11 +766,11 @@ private:
public:
FilterRange() = delete;
template<typename P>
FilterRange(const T &range, P &&pred): p_range(range),
FilterRange(T const &range, P &&pred): p_range(range),
p_pred(forward<P>(pred)) {
advance_valid();
}
FilterRange(const FilterRange &it): p_range(it.p_range),
FilterRange(FilterRange const &it): p_range(it.p_range),
p_pred(it.p_pred) {
advance_valid();
}
@ -779,7 +779,7 @@ public:
advance_valid();
}
FilterRange &operator=(const FilterRange &v) {
FilterRange &operator=(FilterRange const &v) {
p_range = v.p_range;
p_pred = v.p_pred;
advance_valid();
@ -794,7 +794,7 @@ public:
bool empty() const { return p_range.empty(); }
bool equals_front(const FilterRange &r) const {
bool equals_front(FilterRange const &r) const {
return p_range.equals_front(r.p_range);
}

View File

@ -21,29 +21,29 @@ struct Array {
using Difference = Ptrdiff;
using Value = T;
using Reference = T &;
using ConstReference = const T &;
using ConstReference = T const &;
using Pointer = T *;
using ConstPointer = const T *;
using ConstPointer = T const *;
using Range = PointerRange<T>;
using ConstRange = PointerRange<const T>;
using ConstRange = PointerRange<T const>;
T &operator[](Size i) { return p_buf[i]; }
const T &operator[](Size i) const { return p_buf[i]; }
T const &operator[](Size i) const { return p_buf[i]; }
T *at(Size i) {
if (!in_range(i)) return nullptr;
return &p_buf[i];
}
const T *at(Size i) const {
T const *at(Size i) const {
if (!in_range(i)) return nullptr;
return &p_buf[i];
}
T &front() { return p_buf[0]; }
const T &front() const { return p_buf[0]; }
T const &front() const { return p_buf[0]; }
T &back() { return p_buf[(N > 0) ? (N - 1) : 0]; }
const T &back() const { return p_buf[(N > 0) ? (N - 1) : 0]; }
T const &back() const { return p_buf[(N > 0) ? (N - 1) : 0]; }
Size size() const { return N; }
Size max_size() const { return Size(~0) / sizeof(T); }
@ -90,7 +90,7 @@ inline TupleElement<I, Array<T, N>> &get(Array<T, N> &a) {
}
template<Size I, typename T, Size N>
inline const TupleElement<I, Array<T, N>> &get(const Array<T, N> &a) {
inline TupleElement<I, Array<T, N>> const &get(Array<T, N> const &a) {
return a[I];
}
@ -100,37 +100,37 @@ inline TupleElement<I, Array<T, N>> &&get(Array<T, N> &&a) {
}
template<Size I, typename T, Size N>
inline const TupleElement<I, Array<T, N>> &&get(const Array<T, N> &&a) {
inline TupleElement<I, Array<T, N>> const &&get(Array<T, N> const &&a) {
return move(a.p_buf[I]);
}
template<typename T, Size N>
inline bool operator==(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator==(Array<T, N> const &x, Array<T, N> const &y) {
return equal(x.iter(), y.iter());
}
template<typename T, Size N>
inline bool operator!=(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator!=(Array<T, N> const &x, Array<T, N> const &y) {
return !(x == y);
}
template<typename T, Size N>
inline bool operator<(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator<(Array<T, N> const &x, Array<T, N> const &y) {
return lexicographical_compare(x.iter(), y.iter());
}
template<typename T, Size N>
inline bool operator>(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator>(Array<T, N> const &x, Array<T, N> const &y) {
return (y < x);
}
template<typename T, Size N>
inline bool operator<=(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator<=(Array<T, N> const &x, Array<T, N> const &y) {
return !(y < x);
}
template<typename T, Size N>
inline bool operator>=(const Array<T, N> &x, const Array<T, N> &y) {
inline bool operator>=(Array<T, N> const &x, Array<T, N> const &y) {
return !(x < y);
}

View File

@ -46,18 +46,18 @@ namespace detail {
template<typename T>
static inline EnableIf<
CanAtomicAssign<volatile AtomicBase<T> *, T>
> atomic_init(volatile AtomicBase<T> *a, T v) {
CanAtomicAssign<AtomicBase<T> volatile *, T>
> atomic_init(AtomicBase<T> volatile *a, T v) {
a->p_value = v;
}
template<typename T>
static inline EnableIf<
!CanAtomicAssign<volatile AtomicBase<T> *, T> &&
CanAtomicAssign< AtomicBase<T> *, T>
> atomic_init(volatile AtomicBase<T> *a, T v) {
volatile char *to = (volatile char *)(&a->p_value);
volatile char *end = to + sizeof(T);
!CanAtomicAssign<AtomicBase<T> volatile *, T> &&
CanAtomicAssign<AtomicBase<T> *, T>
> atomic_init(AtomicBase<T> volatile *a, T v) {
char volatile *to = (char volatile *)(&a->p_value);
char volatile *end = to + sizeof(T);
char *from = (char *)(&v);
while (to != end) *to++ =*from++;
}
@ -119,44 +119,40 @@ namespace detail {
}
template<typename T>
static inline void atomic_store(volatile AtomicBase<T> *a,
T v, MemoryOrder ord) {
static inline void atomic_store(AtomicBase<T> volatile *a,
T v, MemoryOrder ord) {
__atomic_store(&a->p_value, &v, to_gcc_order(ord));
}
template<typename T>
static inline void atomic_store(AtomicBase<T> *a,
T v, MemoryOrder ord) {
static inline void atomic_store(AtomicBase<T> *a,T v, MemoryOrder ord) {
__atomic_store(&a->p_value, &v, to_gcc_order(ord));
}
template<typename T>
static inline T atomic_load(volatile AtomicBase<T> *a,
MemoryOrder ord) {
static inline T atomic_load(AtomicBase<T> volatile *a, MemoryOrder ord) {
T r;
__atomic_load(&a->p_value, &r, to_gcc_order(ord));
return r;
}
template<typename T>
static inline T atomic_load(AtomicBase<T> *a,
MemoryOrder ord) {
static inline T atomic_load(AtomicBase<T> *a, MemoryOrder ord) {
T r;
__atomic_load(&a->p_value, &r, to_gcc_order(ord));
return r;
}
template<typename T>
static inline T atomic_exchange(volatile AtomicBase<T> *a,
T v, MemoryOrder ord) {
static inline T atomic_exchange(AtomicBase<T> volatile *a,
T v, MemoryOrder ord) {
T r;
__atomic_exchange(&a->p_value, &v, &r, to_gcc_order(ord));
return r;
}
template<typename T>
static inline T atomic_exchange(AtomicBase<T> *a,
T v, MemoryOrder ord) {
static inline T atomic_exchange(AtomicBase<T> *a, T v, MemoryOrder ord) {
T r;
__atomic_exchange(&a->p_value, &v, &r, to_gcc_order(ord));
return r;
@ -164,7 +160,7 @@ namespace detail {
template<typename T>
static inline bool atomic_compare_exchange_strong(
volatile AtomicBase<T> *a, T *expected, T v,
AtomicBase<T> volatile *a, T *expected, T v,
MemoryOrder success, MemoryOrder failure
) {
return __atomic_compare_exchange(&a->p_value, expected, &v, false,
@ -182,7 +178,7 @@ namespace detail {
template<typename T>
static inline bool atomic_compare_exchange_weak(
volatile AtomicBase<T> *a, T *expected, T v,
AtomicBase<T> volatile *a, T *expected, T v,
MemoryOrder success, MemoryOrder failure
) {
return __atomic_compare_exchange(&a->p_value, expected, &v, true,
@ -208,71 +204,71 @@ namespace detail {
template<typename T, Size N> struct SkipAmt<T[N]> {};
template<typename T, typename U>
static inline T atomic_fetch_add(volatile AtomicBase<T> *a,
U d, MemoryOrder ord) {
static inline T atomic_fetch_add(AtomicBase<T> volatile *a,
U d, MemoryOrder ord) {
return __atomic_fetch_add(&a->p_value, d * SkipAmt<T>::value,
to_gcc_order(ord));
}
template<typename T, typename U>
static inline T atomic_fetch_add(AtomicBase<T> *a,
U d, MemoryOrder ord) {
U d, MemoryOrder ord) {
return __atomic_fetch_add(&a->p_value, d * SkipAmt<T>::value,
to_gcc_order(ord));
}
template<typename T, typename U>
static inline T atomic_fetch_sub(volatile AtomicBase<T> *a,
U d, MemoryOrder ord) {
static inline T atomic_fetch_sub(AtomicBase<T> volatile *a,
U d, MemoryOrder ord) {
return __atomic_fetch_sub(&a->p_value, d * SkipAmt<T>::value,
to_gcc_order(ord));
}
template<typename T, typename U>
static inline T atomic_fetch_sub(AtomicBase<T> *a,
U d, MemoryOrder ord) {
U d, MemoryOrder ord) {
return __atomic_fetch_sub(&a->p_value, d * SkipAmt<T>::value,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_and(volatile AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
static inline T atomic_fetch_and(AtomicBase<T> volatile *a,
T pattern, MemoryOrder ord) {
return __atomic_fetch_and(&a->p_value, pattern,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_and(AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
T pattern, MemoryOrder ord) {
return __atomic_fetch_and(&a->p_value, pattern,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_or(volatile AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
static inline T atomic_fetch_or(AtomicBase<T> volatile *a,
T pattern, MemoryOrder ord) {
return __atomic_fetch_or(&a->p_value, pattern,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_or(AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
T pattern, MemoryOrder ord) {
return __atomic_fetch_or(&a->p_value, pattern,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_xor(volatile AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
static inline T atomic_fetch_xor(AtomicBase<T> volatile *a,
T pattern, MemoryOrder ord) {
return __atomic_fetch_xor(&a->p_value, pattern,
to_gcc_order(ord));
}
template<typename T>
static inline T atomic_fetch_xor(AtomicBase<T> *a,
T pattern, MemoryOrder ord) {
T pattern, MemoryOrder ord) {
return __atomic_fetch_xor(&a->p_value, pattern,
to_gcc_order(ord));
}
@ -294,10 +290,10 @@ namespace detail {
constexpr Atomic(T v): p_a(v) {}
Atomic(const Atomic &) = delete;
Atomic(Atomic const &) = delete;
Atomic &operator=(const Atomic &) = delete;
Atomic &operator=(const Atomic &) volatile = delete;
Atomic &operator=(Atomic const &) = delete;
Atomic &operator=(Atomic const &) volatile = delete;
bool is_lock_free() const volatile {
return atomic_is_lock_free(sizeof(T));
@ -515,17 +511,17 @@ struct Atomic<T *>: detail::Atomic<T *> {
};
template<typename T>
inline bool atomic_is_lock_free(const volatile Atomic<T> *a) {
inline bool atomic_is_lock_free(Atomic<T> const volatile *a) {
return a->is_lock_free();
}
template<typename T>
inline bool atomic_is_lock_free(const Atomic<T> *a) {
inline bool atomic_is_lock_free(Atomic<T> const *a) {
return a->is_lock_free();
}
template<typename T>
inline void atomic_init(volatile Atomic<T> *a, T v) {
inline void atomic_init(Atomic<T> volatile *a, T v) {
detail::atomic_init(&a->p_a, v);
}
@ -535,7 +531,7 @@ inline void atomic_init(Atomic<T> *a, T v) {
}
template <typename T>
inline void atomic_store(volatile Atomic<T> *a, T v) {
inline void atomic_store(Atomic<T> volatile *a, T v) {
a->store(v);
}
@ -545,40 +541,37 @@ inline void atomic_store(Atomic<T> *a, T v) {
}
template <typename T>
inline void atomic_store_explicit(volatile Atomic<T> *a, T v,
MemoryOrder ord) {
inline void atomic_store_explicit(Atomic<T> volatile *a, T v, MemoryOrder ord) {
a->store(v, ord);
}
template <typename T>
inline void atomic_store_explicit(Atomic<T> *a, T v,
MemoryOrder ord) {
inline void atomic_store_explicit(Atomic<T> *a, T v, MemoryOrder ord) {
a->store(v, ord);
}
template <typename T>
inline T atomic_load(const volatile Atomic<T> *a) {
inline T atomic_load(Atomic<T> const volatile *a) {
return a->load();
}
template <typename T>
inline T atomic_load(const Atomic<T> *a) {
inline T atomic_load(Atomic<T> const *a) {
return a->load();
}
template <typename T>
inline T atomic_load_explicit(const volatile Atomic<T> *a,
MemoryOrder ord) {
inline T atomic_load_explicit(Atomic<T> const volatile *a, MemoryOrder ord) {
return a->load(ord);
}
template <typename T>
inline T atomic_load_explicit(const Atomic<T> *a, MemoryOrder ord) {
inline T atomic_load_explicit(Atomic<T> const *a, MemoryOrder ord) {
return a->load(ord);
}
template <typename T>
inline T atomic_exchange(volatile Atomic<T> *a, T v) {
inline T atomic_exchange(Atomic<T> volatile *a, T v) {
return a->exchange(v);
}
@ -588,7 +581,7 @@ inline T atomic_exchange(Atomic<T> *a, T v) {
}
template <typename T>
inline T atomic_exchange_explicit(volatile Atomic<T> *a, T v,
inline T atomic_exchange_explicit(Atomic<T> volatile *a, T v,
MemoryOrder ord) {
return a->exchange(v, ord);
}
@ -600,7 +593,7 @@ inline T atomic_exchange_explicit(Atomic<T> *a, T v,
}
template <typename T>
inline bool atomic_compare_exchange_weak(volatile Atomic<T> *a,
inline bool atomic_compare_exchange_weak(Atomic<T> volatile *a,
T *e, T v) {
return a->compare_exchange_weak(*e, v);
}
@ -611,7 +604,7 @@ inline bool atomic_compare_exchange_weak(Atomic<T> *a, T *e, T v) {
}
template <typename T>
inline bool atomic_compare_exchange_strong(volatile Atomic<T> *a,
inline bool atomic_compare_exchange_strong(Atomic<T> volatile *a,
T *e, T v) {
return a->compare_exchange_strong(*e, v);
}
@ -622,7 +615,7 @@ inline bool atomic_compare_exchange_strong(Atomic<T> *a, T *e, T v) {
}
template <typename T>
inline bool atomic_compare_exchange_weak_explicit(volatile Atomic<T> *a,
inline bool atomic_compare_exchange_weak_explicit(Atomic<T> volatile *a,
T *e, T v,
MemoryOrder s,
MemoryOrder f) {
@ -638,7 +631,7 @@ inline bool atomic_compare_exchange_weak_explicit(Atomic<T> *a, T *e,
}
template <typename T>
inline bool atomic_compare_exchange_strong_explicit(volatile Atomic<T> *a,
inline bool atomic_compare_exchange_strong_explicit(Atomic<T> volatile *a,
T *e, T v,
MemoryOrder s,
MemoryOrder f) {
@ -655,7 +648,7 @@ inline bool atomic_compare_exchange_strong_explicit(Atomic<T> *a, T *e,
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_add(volatile Atomic<T> *a, T op) {
atomic_fetch_add(Atomic<T> volatile *a, T op) {
return a->fetch_add(op);
}
@ -666,7 +659,7 @@ atomic_fetch_add(Atomic<T> *a, T op) {
}
template <typename T>
inline T *atomic_fetch_add(volatile Atomic<T *> *a, Ptrdiff op) {
inline T *atomic_fetch_add(Atomic<T *> volatile *a, Ptrdiff op) {
return a->fetch_add(op);
}
@ -677,7 +670,7 @@ inline T *atomic_fetch_add(Atomic<T *> *a, Ptrdiff op) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_add_explicit(volatile Atomic<T> *a, T op,
atomic_fetch_add_explicit(Atomic<T> volatile *a, T op,
MemoryOrder ord) {
return a->fetch_add(op, ord);
}
@ -689,7 +682,7 @@ atomic_fetch_add_explicit(Atomic<T> *a, T op, MemoryOrder ord) {
}
template <typename T>
inline T *atomic_fetch_add_explicit(volatile Atomic<T *> *a,
inline T *atomic_fetch_add_explicit(Atomic<T *> volatile *a,
Ptrdiff op, MemoryOrder ord) {
return a->fetch_add(op, ord);
}
@ -702,7 +695,7 @@ inline T *atomic_fetch_add_explicit(Atomic<T *> *a, Ptrdiff op,
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_sub(volatile Atomic<T> *a, T op) {
atomic_fetch_sub(Atomic<T> volatile *a, T op) {
return a->fetch_sub(op);
}
@ -713,7 +706,7 @@ atomic_fetch_sub(Atomic<T> *a, T op) {
}
template <typename T>
inline T *atomic_fetch_sub(volatile Atomic<T *> *a, Ptrdiff op) {
inline T *atomic_fetch_sub(Atomic<T *> volatile *a, Ptrdiff op) {
return a->fetch_sub(op);
}
@ -724,7 +717,7 @@ inline T *atomic_fetch_sub(Atomic<T *> *a, Ptrdiff op) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_sub_explicit(volatile Atomic<T> *a, T op,
atomic_fetch_sub_explicit(Atomic<T> volatile *a, T op,
MemoryOrder ord) {
return a->fetch_sub(op, ord);
}
@ -736,7 +729,7 @@ atomic_fetch_sub_explicit(Atomic<T> *a, T op, MemoryOrder ord) {
}
template <typename T>
inline T *atomic_fetch_sub_explicit(volatile Atomic<T *> *a,
inline T *atomic_fetch_sub_explicit(Atomic<T *> volatile *a,
Ptrdiff op, MemoryOrder ord) {
return a->fetch_sub(op, ord);
}
@ -749,7 +742,7 @@ inline T *atomic_fetch_sub_explicit(Atomic<T *> *a, Ptrdiff op,
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_and(volatile Atomic<T> *a, T op) {
atomic_fetch_and(Atomic<T> volatile *a, T op) {
return a->fetch_and(op);
}
@ -761,7 +754,7 @@ atomic_fetch_and(Atomic<T> *a, T op) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_and_explicit(volatile Atomic<T> *a, T op,
atomic_fetch_and_explicit(Atomic<T> volatile *a, T op,
MemoryOrder ord) {
return a->fetch_and(op, ord);
}
@ -774,7 +767,7 @@ atomic_fetch_and_explicit(Atomic<T> *a, T op, MemoryOrder ord) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_or(volatile Atomic<T> *a, T op) {
atomic_fetch_or(Atomic<T> volatile *a, T op) {
return a->fetch_or(op);
}
@ -786,7 +779,7 @@ atomic_fetch_or(Atomic<T> *a, T op) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_or_explicit(volatile Atomic<T> *a, T op,
atomic_fetch_or_explicit(Atomic<T> volatile *a, T op,
MemoryOrder ord) {
return a->fetch_or(op, ord);
}
@ -799,7 +792,7 @@ atomic_fetch_or_explicit(Atomic<T> *a, T op, MemoryOrder ord) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_xor(volatile Atomic<T> *a, T op) {
atomic_fetch_xor(Atomic<T> volatile *a, T op) {
return a->fetch_xor(op);
}
@ -811,7 +804,7 @@ atomic_fetch_xor(Atomic<T> *a, T op) {
template <typename T>
inline EnableIf<IsIntegral<T> && !IsSame<T, bool>, T>
atomic_fetch_xor_explicit(volatile Atomic<T> *a, T op,
atomic_fetch_xor_explicit(Atomic<T> volatile *a, T op,
MemoryOrder ord) {
return a->fetch_xor(op, ord);
}
@ -829,10 +822,10 @@ struct AtomicFlag {
AtomicFlag(bool b): p_a(b) {}
AtomicFlag(const AtomicFlag &) = delete;
AtomicFlag(AtomicFlag const &) = delete;
AtomicFlag &operator=(const AtomicFlag &) = delete;
AtomicFlag &operator=(const AtomicFlag &) volatile = delete;
AtomicFlag &operator=(AtomicFlag const &) = delete;
AtomicFlag &operator=(AtomicFlag const &) volatile = delete;
bool test_and_set(MemoryOrder ord = MemoryOrder::seq_cst) volatile {
return detail::atomic_exchange(&p_a, true, ord);
@ -851,7 +844,7 @@ struct AtomicFlag {
}
};
inline bool atomic_flag_test_and_set(volatile AtomicFlag *a) {
inline bool atomic_flag_test_and_set(AtomicFlag volatile *a) {
return a->test_and_set();
}
@ -859,7 +852,7 @@ inline bool atomic_flag_test_and_set(AtomicFlag *a) {
return a->test_and_set();
}
inline bool atomic_flag_test_and_set_explicit(volatile AtomicFlag *a,
inline bool atomic_flag_test_and_set_explicit(AtomicFlag volatile *a,
MemoryOrder ord) {
return a->test_and_set(ord);
}
@ -869,7 +862,7 @@ inline bool atomic_flag_test_and_set_explicit(AtomicFlag *a,
return a->test_and_set(ord);
}
inline void atomic_flag_clear(volatile AtomicFlag *a) {
inline void atomic_flag_clear(AtomicFlag volatile *a) {
a->clear();
}
@ -877,7 +870,7 @@ inline void atomic_flag_clear(AtomicFlag *a) {
a->clear();
}
inline void atomic_flag_clear_explicit(volatile AtomicFlag *a,
inline void atomic_flag_clear_explicit(AtomicFlag volatile *a,
MemoryOrder ord) {
a->clear(ord);
}

View File

@ -17,7 +17,7 @@ namespace environ {
inline Maybe<ConstCharRange> get(ConstCharRange name) {
char buf[256];
const char *ret = getenv(to_temp_cstr(name, buf, sizeof(buf)).get());
char const *ret = getenv(to_temp_cstr(name, buf, sizeof(buf)).get());
if (!ret) return ostd::nothing;
return ostd::move(ConstCharRange(ret));
}

View File

@ -16,8 +16,8 @@ namespace detail {
struct SignalBase {
SignalBase(C *cl): p_class(cl), p_funcs(nullptr), p_nfuncs(0) {}
SignalBase(const SignalBase &ev): p_class(ev.p_class),
p_nfuncs(ev.p_nfuncs) {
SignalBase(SignalBase const &ev): p_class(ev.p_class),
p_nfuncs(ev.p_nfuncs) {
using Func = Function<void(C &, A...)>;
Func *nbuf = (Func *)new byte[sizeof(Func) * p_nfuncs];
for (Size i = 0; i < p_nfuncs; ++i)
@ -30,7 +30,7 @@ namespace detail {
swap(ev);
}
SignalBase &operator=(const SignalBase &ev) {
SignalBase &operator=(SignalBase const &ev) {
using Func = Function<void(C &, A...)>;
p_class = ev.p_class;
p_nfuncs = ev.p_nfuncs;
@ -118,10 +118,10 @@ private:
Base p_base;
public:
Signal(C *cl): p_base(cl) {}
Signal(const Signal &ev): p_base(ev.p_base) {}
Signal(Signal const &ev): p_base(ev.p_base) {}
Signal(Signal &&ev): p_base(move(ev.p_base)) {}
Signal &operator=(const Signal &ev) {
Signal &operator=(Signal const &ev) {
p_base = ev.p_base;
return *this;
}
@ -151,16 +151,16 @@ public:
};
template<typename C, typename ...A>
struct Signal<const C, A...> {
struct Signal<C const, A...> {
private:
using Base = detail::SignalBase<const C, A...>;
using Base = detail::SignalBase<C const, A...>;
Base p_base;
public:
Signal(C *cl): p_base(cl) {}
Signal(const Signal &ev): p_base(ev.p_base) {}
Signal(Signal const &ev): p_base(ev.p_base) {}
Signal(Signal &&ev): p_base(move(ev.p_base)) {}
Signal &operator=(const Signal &ev) {
Signal &operator=(Signal const &ev) {
p_base = ev.p_base;
return *this;
}

View File

@ -38,7 +38,7 @@ static constexpr char PathSeparator = '/';
#ifdef OSTD_PLATFORM_WIN32
namespace detail {
inline time_t filetime_to_time_t(const FILETIME &ft) {
inline time_t filetime_to_time_t(FILETIME const &ft) {
ULARGE_INTEGER ul;
ul.LowPart = ft.dwLowDateTime;
ul.HighPart = ft.dwHighDateTime;
@ -54,7 +54,7 @@ inline void path_normalize(CharRange) {
struct FileInfo {
FileInfo() {}
FileInfo(const FileInfo &i):
FileInfo(FileInfo const &i):
p_slash(i.p_slash), p_dot(i.p_dot), p_type(i.p_type),
p_path(i.p_path), p_atime(i.p_atime), p_mtime(i.p_mtime),
p_ctime(i.p_ctime) {}
@ -72,7 +72,7 @@ struct FileInfo {
init_from_str(path);
}
FileInfo &operator=(const FileInfo &i) {
FileInfo &operator=(FileInfo const &i) {
p_slash = i.p_slash;
p_dot = i.p_dot;
p_type = i.p_type;
@ -215,7 +215,7 @@ struct DirectoryStream {
friend struct DirectoryRange;
DirectoryStream(): p_d(), p_de(), p_dev(), p_path() {}
DirectoryStream(const DirectoryStream &) = delete;
DirectoryStream(DirectoryStream const &) = delete;
DirectoryStream(DirectoryStream &&s): p_d(s.p_d), p_de(s.p_de),
p_dev(s.p_dev),
p_path(move(s.p_path)) {
@ -230,7 +230,7 @@ struct DirectoryStream {
~DirectoryStream() { close(); }
DirectoryStream &operator=(const DirectoryStream &) = delete;
DirectoryStream &operator=(DirectoryStream const &) = delete;
DirectoryStream &operator=(DirectoryStream &&s) {
close();
swap(s);
@ -325,7 +325,7 @@ private:
return FileInfo();
String ap = p_path;
ap += PathSeparator;
ap += (const char *)p_de->d_name;
ap += (char const *)p_de->d_name;
return FileInfo(ap);
}
@ -341,7 +341,7 @@ struct DirectoryStream {
friend struct DirectoryRange;
DirectoryStream(): p_handle(INVALID_HANDLE_VALUE), p_data(), p_path() {}
DirectoryStream(const DirectoryStream &) = delete;
DirectoryStream(DirectoryStream const &) = delete;
DirectoryStream(DirectoryStream &&s): p_handle(s.p_handle),
p_data(s.p_data),
p_path(move(s.p_path)) {
@ -355,7 +355,7 @@ struct DirectoryStream {
~DirectoryStream() { close(); }
DirectoryStream &operator=(const DirectoryStream &) = delete;
DirectoryStream &operator=(DirectoryStream const &) = delete;
DirectoryStream &operator=(DirectoryStream &&s) {
close();
swap(s);
@ -463,7 +463,7 @@ private:
return FileInfo();
String ap = p_path;
ap += PathSeparator;
ap += (const char *)p_data.cFileName;
ap += (char const *)p_data.cFileName;
return FileInfo(ap);
}
@ -478,9 +478,9 @@ struct DirectoryRange: InputRange<
> {
DirectoryRange() = delete;
DirectoryRange(DirectoryStream &s): p_stream(&s) {}
DirectoryRange(const DirectoryRange &r): p_stream(r.p_stream) {}
DirectoryRange(DirectoryRange const &r): p_stream(r.p_stream) {}
DirectoryRange &operator=(const DirectoryRange &r) {
DirectoryRange &operator=(DirectoryRange const &r) {
p_stream = r.p_stream;
return *this;
}
@ -497,7 +497,7 @@ struct DirectoryRange: InputRange<
return p_stream->front();
}
bool equals_front(const DirectoryRange &s) const {
bool equals_front(DirectoryRange const &s) const {
return p_stream == s.p_stream;
}
@ -512,7 +512,7 @@ inline DirectoryRange DirectoryStream::iter() {
namespace detail {
template<Size I> struct PathJoin {
template<typename T, typename ...A>
static void join(String &s, const T &a, const A &...b) {
static void join(String &s, T const &a, A const &...b) {
s += a;
s += PathSeparator;
PathJoin<I - 1>::join(s, b...);
@ -521,14 +521,14 @@ namespace detail {
template<> struct PathJoin<1> {
template<typename T>
static void join(String &s, const T &a) {
static void join(String &s, T const &a) {
s += a;
}
};
}
template<typename ...A>
inline FileInfo path_join(const A &...args) {
inline FileInfo path_join(A const &...args) {
String path;
detail::PathJoin<sizeof...(A)>::join(path, args...);
path_normalize(path.iter());

View File

@ -62,7 +62,7 @@ namespace detail {
* 7 .. string
* 8 .. custom object
*/
static constexpr const byte fmt_specs[] = {
static constexpr byte const fmt_specs[] = {
/* uppercase spec set */
1, 3, 8, 8, /* A B C D */
1, 1, 1, 8, /* E F G H */
@ -88,11 +88,11 @@ namespace detail {
0, 0, 0, 0, 0
};
static constexpr const int fmt_bases[] = {
static constexpr int const fmt_bases[] = {
0, 0, 0, 2, 8, 10, 16, 0
};
static constexpr const char fmt_digits[2][16] = {
static constexpr char fmt_digits[2][16] = {
{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
@ -103,14 +103,14 @@ namespace detail {
}
};
static constexpr const char *fmt_intpfx[2][4] = {
static constexpr char const *fmt_intpfx[2][4] = {
{ "0B", "0", "", "0X" },
{ "0b", "0", "", "0x" }
};
/* retrieve width/precision */
template<typename T>
bool convert_arg_param(const T &val, int &param, EnableIf<
bool convert_arg_param(T const &val, int &param, EnableIf<
IsIntegral<T>, bool
> = true) {
param = int(val);
@ -118,7 +118,7 @@ namespace detail {
}
template<typename T>
bool convert_arg_param(const T &, int &, EnableIf<
bool convert_arg_param(T const &, int &, EnableIf<
!IsIntegral<T>, bool
> = true) {
assert(false && "invalid argument for width/precision");
@ -126,7 +126,7 @@ namespace detail {
}
template<typename T>
bool get_arg_param(Size idx, int &param, const T &val) {
bool get_arg_param(Size idx, int &param, T const &val) {
if (idx) {
assert(false && "not enough format args");
return false;
@ -134,8 +134,7 @@ namespace detail {
return convert_arg_param(val, param);
}
template<typename T, typename ...A>
bool get_arg_param(Size idx, int &param, const T &val,
const A &...args) {
bool get_arg_param(Size idx, int &param, T const &val, A const &...args) {
if (idx) return get_arg_param(idx - 1, param, args...);
return convert_arg_param(val, param);
}
@ -204,12 +203,12 @@ struct FormatSpec {
bool arg_precision() const { return p_arg_precision; }
template<typename ...A>
bool set_width(Size idx, const A &...args) {
bool set_width(Size idx, A const &...args) {
return detail::get_arg_param(idx, p_width, args...);
}
template<typename ...A>
bool set_precision(Size idx, const A &...args) {
bool set_precision(Size idx, A const &...args) {
return detail::get_arg_param(idx, p_precision, args...);
}
@ -399,16 +398,16 @@ protected:
/* for custom container formatting */
template<typename T, typename R, typename = EnableIf<
IsSame<decltype(declval<const T &>()
.to_format(declval<R &>(), declval<const FormatSpec &>())), bool
IsSame<decltype(declval<T const &>()
.to_format(declval<R &>(), declval<FormatSpec const &>())), bool
>
>> inline bool to_format(const T &v, R &writer, const FormatSpec &fs) {
>> inline bool to_format(T const &v, R &writer, FormatSpec const &fs) {
return v.to_format(writer, fs);
}
namespace detail {
template<typename R, typename T>
inline Ptrdiff write_u(R &writer, const FormatSpec *fl, bool neg, T val) {
inline Ptrdiff write_u(R &writer, FormatSpec const *fl, bool neg, T val) {
char buf[20];
Ptrdiff r = 0;
Size n = 0;
@ -434,7 +433,7 @@ namespace detail {
bool sign = neg + lsgn + lsp;
r += sign;
const char *pfx = nullptr;
char const *pfx = nullptr;
int pfxlen = 0;
if (flags & FMT_FLAG_HASH && spec != 'd') {
pfx = detail::fmt_intpfx[spec >= 'a'][specn - 3];
@ -458,7 +457,7 @@ namespace detail {
template<typename R, typename ...A>
static Ptrdiff format_impl(R &writer, Size &fmtn, bool escape,
ConstCharRange fmt, const A &...args);
ConstCharRange fmt, A const &...args);
template<typename T, typename = RangeOf<T>>
static True test_fmt_range(int);
@ -472,8 +471,8 @@ namespace detail {
struct FmtTupleUnpacker {
template<typename R, typename T, typename ...A>
static inline Ptrdiff unpack(R &writer, Size &fmtn, bool esc,
ConstCharRange fmt, const T &item,
const A &...args) {
ConstCharRange fmt, T const &item,
A const &...args) {
return FmtTupleUnpacker<I - 1>::unpack(writer, fmtn, esc, fmt,
item, get<I - 1>(item), args...);
}
@ -483,15 +482,15 @@ namespace detail {
struct FmtTupleUnpacker<0> {
template<typename R, typename T, typename ...A>
static inline Ptrdiff unpack(R &writer, Size &fmtn, bool esc,
ConstCharRange fmt, const T &,
const A &...args) {
ConstCharRange fmt, T const &,
A const &...args) {
return format_impl(writer, fmtn, esc, fmt, args...);
}
};
template<typename R, typename T>
inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc, bool,
ConstCharRange fmt, const T &item,
ConstCharRange fmt, T const &item,
EnableIf<!IsTupleLike<T>, bool>
= true) {
return format_impl(writer, fmtn, esc, fmt, item);
@ -500,7 +499,7 @@ namespace detail {
template<typename R, typename T>
inline Ptrdiff format_ritem(R &writer, Size &fmtn, bool esc,
bool expandval, ConstCharRange fmt,
const T &item,
T const &item,
EnableIf<IsTupleLike<T>, bool>
= true) {
if (expandval) {
@ -511,10 +510,10 @@ namespace detail {
}
template<typename R, typename T>
inline Ptrdiff write_range(R &writer, const FormatSpec *fl,
inline Ptrdiff write_range(R &writer, FormatSpec const *fl,
bool escape, bool expandval,
ConstCharRange sep,
const T &val,
T const &val,
EnableIf<FmtRangeTest<T>, bool>
= true) {
auto range = ostd::iter(val);
@ -542,8 +541,8 @@ namespace detail {
}
template<typename R, typename T>
inline Ptrdiff write_range(R &, const FormatSpec *, bool, bool,
ConstCharRange, const T &,
inline Ptrdiff write_range(R &, FormatSpec const *, bool, bool,
ConstCharRange, T const &,
EnableIf<!FmtRangeTest<T>, bool>
= true) {
assert(false && "invalid value for ranged format");
@ -558,7 +557,7 @@ namespace detail {
constexpr bool FmtTostrTest = decltype(test_fmt_tostr<T>(0))::value;
/* non-printable escapes up to 0x20 (space) */
static constexpr const char *fmt_escapes[] = {
static constexpr char const *fmt_escapes[] = {
"\\0" , "\\x01", "\\x02", "\\x03", "\\x04", "\\x05",
"\\x06", "\\a" , "\\b" , "\\t" , "\\n" , "\\v" ,
"\\f" , "\\r" , "\\x0E", "\\x0F", "\\x10", "\\x11",
@ -570,7 +569,7 @@ namespace detail {
nullptr, "\\\'"
};
inline const char *escape_fmt_char(char v, char quote) {
inline char const *escape_fmt_char(char v, char quote) {
if ((v >= 0 && v < 0x20) || (v == quote)) {
return fmt_escapes[Size(v)];
} else if (v == 0x7F) {
@ -583,7 +582,7 @@ namespace detail {
String ret;
ret.push('"');
while (!val.empty()) {
const char *esc = escape_fmt_char(val.front(), '"');
char const *esc = escape_fmt_char(val.front(), '"');
if (esc)
ret.append(esc);
else
@ -595,9 +594,9 @@ namespace detail {
}
template<typename T, typename R>
static True test_tofmt(decltype(to_format(declval<const T &>(),
static True test_tofmt(decltype(to_format(declval<T const &>(),
declval<R &>(),
declval<const FormatSpec &>())) *);
declval<FormatSpec const &>())) *);
template<typename, typename>
static False test_tofmt(...);
@ -626,8 +625,8 @@ namespace detail {
/* any string value */
template<typename R, typename T>
Ptrdiff write(R &writer, bool escape, const T &val, EnableIf<
IsConstructible<ConstCharRange, const T &>, bool
Ptrdiff write(R &writer, bool escape, T const &val, EnableIf<
IsConstructible<ConstCharRange, T const &>, bool
> = true) {
if (this->spec() != 's') {
assert(false && "cannot print strings with the given spec");
@ -644,14 +643,14 @@ namespace detail {
return -1;
}
if (escape) {
const char *esc = escape_fmt_char(val, '\'');
char const *esc = escape_fmt_char(val, '\'');
if (esc) {
char buf[6];
buf[0] = '\'';
Size elen = strlen(esc);
memcpy(buf + 1, esc, elen);
buf[elen + 1] = '\'';
return write(writer, false, (const char *)buf, elen + 2);
return write(writer, false, (char const *)buf, elen + 2);
}
}
Ptrdiff r = 1 + escape * 2;
@ -738,9 +737,9 @@ namespace detail {
/* generic value */
template<typename R, typename T>
Ptrdiff write(R &writer, bool, const T &val, EnableIf<
Ptrdiff write(R &writer, bool, T const &val, EnableIf<
!IsArithmetic<T> &&
!IsConstructible<ConstCharRange, const T &> &&
!IsConstructible<ConstCharRange, T const &> &&
FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
> = true) {
if (this->spec() != 's') {
@ -752,7 +751,7 @@ namespace detail {
/* custom format case */
template<typename R, typename T>
Ptrdiff write(R &writer, bool, const T &val,
Ptrdiff write(R &writer, bool, T const &val,
EnableIf<FmtTofmtTest<T, TostrRange<R>>, bool
> = true) {
TostrRange<R> sink(writer);
@ -762,9 +761,9 @@ namespace detail {
/* generic failure case */
template<typename R, typename T>
Ptrdiff write(R &, bool, const T &, EnableIf<
Ptrdiff write(R &, bool, T const &, EnableIf<
!IsArithmetic<T> &&
!IsConstructible<ConstCharRange, const T &> &&
!IsConstructible<ConstCharRange, T const &> &&
!FmtTostrTest<T> && !FmtTofmtTest<T, TostrRange<R>>, bool
> = true) {
assert(false && "value cannot be formatted");
@ -773,7 +772,7 @@ namespace detail {
/* actual writer */
template<typename R, typename T>
Ptrdiff write_arg(R &writer, Size idx, const T &val) {
Ptrdiff write_arg(R &writer, Size idx, T const &val) {
if (idx) {
assert(false && "not enough format args");
return -1;
@ -782,8 +781,8 @@ namespace detail {
}
template<typename R, typename T, typename ...A>
Ptrdiff write_arg(R &writer, Size idx, const T &val,
const A &...args) {
Ptrdiff write_arg(R &writer, Size idx, T const &val,
A const &...args) {
if (idx) return write_arg(writer, idx - 1, args...);
return write(writer, this->p_nested_escape, val);
}
@ -791,7 +790,7 @@ namespace detail {
/* range writer */
template<typename R, typename T>
Ptrdiff write_range(R &writer, Size idx, bool expandval,
ConstCharRange sep, const T &val) {
ConstCharRange sep, T const &val) {
if (idx) {
assert(false && "not enough format args");
return -1;
@ -802,8 +801,8 @@ namespace detail {
template<typename R, typename T, typename ...A>
Ptrdiff write_range(R &writer, Size idx, bool expandval,
ConstCharRange sep, const T &val,
const A &...args) {
ConstCharRange sep, T const &val,
A const &...args) {
if (idx) {
return write_range(writer, idx - 1, expandval, sep, args...);
}
@ -814,7 +813,7 @@ namespace detail {
template<typename R, typename ...A>
inline Ptrdiff format_impl(R &writer, Size &fmtn, bool escape,
ConstCharRange fmt, const A &...args) {
ConstCharRange fmt, A const &...args) {
Size argidx = 1, retn = 0, twr = 0;
Ptrdiff written = 0;
detail::WriteSpec spec(fmt, escape);
@ -885,12 +884,12 @@ namespace detail {
template<typename R, typename ...A>
inline Ptrdiff format(R &&writer, Size &fmtn, ConstCharRange fmt,
const A &...args) {
A const &...args) {
return detail::format_impl(writer, fmtn, false, fmt, args...);
}
template<typename R, typename ...A>
Ptrdiff format(R &&writer, ConstCharRange fmt, const A &...args) {
Ptrdiff format(R &&writer, ConstCharRange fmt, A const &...args) {
Size fmtn = 0;
return format(writer, fmtn, fmt, args...);
}

View File

@ -20,7 +20,7 @@ namespace ostd {
#define OSTD_DEFINE_BINARY_OP(name, op, RT) \
template<typename T> struct name { \
RT operator()(const T &x, const T &y) const { \
RT operator()(T const &x, T const &y) const { \
return x op y; \
} \
using FirstArgument = T; \
@ -71,7 +71,7 @@ namespace detail {
template<typename T> struct EqualWithCstr {
using FirstArgument = T;
using SecondArgument = T;
bool operator()(const T &x, const T &y) const {
bool operator()(T const &x, T const &y) const {
return x == y;
}
};
@ -79,13 +79,13 @@ template<typename T> struct EqualWithCstr {
template<typename T> struct EqualWithCstr<T *>: detail::CharEqual<T> {};
template<typename T> struct LogicalNot {
bool operator()(const T &x) const { return !x; }
bool operator()(T const &x) const { return !x; }
using Argument = T;
using Result = bool;
};
template<typename T> struct Negate {
bool operator()(const T &x) const { return -x; }
bool operator()(T const &x) const { return -x; }
using Argument = T;
using Result = T;
};
@ -95,10 +95,10 @@ template<typename T> struct BinaryNegate {
using SecondArgument = typename T::SecondArgument;
using Result = bool;
explicit BinaryNegate(const T &f): p_fn(f) {}
explicit BinaryNegate(T const &f): p_fn(f) {}
bool operator()(const FirstArgument &x,
const SecondArgument &y) {
bool operator()(FirstArgument const &x,
SecondArgument const &y) {
return !p_fn(x, y);
}
private:
@ -109,19 +109,19 @@ template<typename T> struct UnaryNegate {
using Argument = typename T::Argument;
using Result = bool;
explicit UnaryNegate(const T &f): p_fn(f) {}
bool operator()(const Argument &x) {
explicit UnaryNegate(T const &f): p_fn(f) {}
bool operator()(Argument const &x) {
return !p_fn(x);
}
private:
T p_fn;
};
template<typename T> UnaryNegate<T> not1(const T &fn) {
template<typename T> UnaryNegate<T> not1(T const &fn) {
return UnaryNegate<T>(fn);
}
template<typename T> BinaryNegate<T> not2(const T &fn) {
template<typename T> BinaryNegate<T> not2(T const &fn) {
return BinaryNegate<T>(fn);
}
@ -210,7 +210,7 @@ template<typename T> struct ToHash {
using Argument = T;
using Result = Size;
Size operator()(const T &v) const {
Size operator()(T const &v) const {
return v.to_hash();
}
};
@ -262,11 +262,11 @@ namespace detail {
static constexpr Size offset = Size(14695981039346656037u);
};
inline Size mem_hash(const void *p, Size l) {
inline Size mem_hash(void const *p, Size l) {
using Consts = FnvConstants<sizeof(Size)>;
const byte *d = (const byte *)p;
byte const *d = (byte const *)p;
Size h = Consts::offset;
for (const byte *it = d, *end = d + l; it != end; ++it) {
for (byte const *it = d, *end = d + l; it != end; ++it) {
h ^= *it;
h *= Consts::prime;
}
@ -306,7 +306,7 @@ namespace detail {
Size operator()(T v) const {
union { T v; struct { Size h1, h2; }; } u;
u.v = v;
return mem_hash((const void *)&u, sizeof(u));
return mem_hash((void const *)&u, sizeof(u));
}
};
@ -317,7 +317,7 @@ namespace detail {
Size operator()(T v) const {
union { T v; struct { Size h1, h2, h3; }; } u;
u.v = v;
return mem_hash((const void *)&u, sizeof(u));
return mem_hash((void const *)&u, sizeof(u));
}
};
@ -328,7 +328,7 @@ namespace detail {
Size operator()(T v) const {
union { T v; struct { Size h1, h2, h3, h4; }; } u;
u.v = v;
return mem_hash((const void *)&u, sizeof(u));
return mem_hash((void const *)&u, sizeof(u));
}
};
} /* namespace detail */
@ -379,7 +379,7 @@ namespace detail {
Size operator()(T *v) const {
union { T *v; Size h; } u;
u.v = v;
return detail::mem_hash((const void *)&u, sizeof(u));
return detail::mem_hash((void const *)&u, sizeof(u));
}
};
@ -395,7 +395,7 @@ namespace detail {
template<typename T> struct ToHash<T *>: detail::ToHashPtr<T> {};
template<typename T>
typename ToHash<T>::Result to_hash(const T &v) {
typename ToHash<T>::Result to_hash(T const &v) {
return ToHash<T>()(v);
}
@ -406,10 +406,10 @@ struct ReferenceWrapper {
using Type = T;
ReferenceWrapper(T &v): p_ptr(address_of(v)) {}
ReferenceWrapper(const ReferenceWrapper &) = default;
ReferenceWrapper(ReferenceWrapper const &) = default;
ReferenceWrapper(T &&) = delete;
ReferenceWrapper &operator=(const ReferenceWrapper &) = default;
ReferenceWrapper &operator=(ReferenceWrapper const &) = default;
operator T &() const { return *p_ptr; }
T &get() const { return *p_ptr; }
@ -426,17 +426,17 @@ template<typename T>
ReferenceWrapper<T> ref(ReferenceWrapper<T> v) {
return ReferenceWrapper<T>(v);
}
template<typename T> void ref(const T &&) = delete;
template<typename T> void ref(T const &&) = delete;
template<typename T>
ReferenceWrapper<const T> cref(const T &v) {
ReferenceWrapper<T const> cref(T const &v) {
return ReferenceWrapper<T>(v);
}
template<typename T>
ReferenceWrapper<const T> cref(ReferenceWrapper<T> v) {
ReferenceWrapper<T const> cref(ReferenceWrapper<T> v) {
return ReferenceWrapper<T>(v);
}
template<typename T> void cref(const T &&) = delete;
template<typename T> void cref(T const &&) = delete;
/* mem_fn */
@ -456,12 +456,12 @@ namespace detail {
template<typename T, typename R, typename ...A>
struct MemTypes<T, R(A...) const> {
using Result = R;
using Argument = const T;
using Argument = T const;
};
template<typename T, typename R, typename A>
struct MemTypes<T, R(A) const> {
using Result = R;
using FirstArgument = const T;
using FirstArgument = T const;
using SecondArgument = A;
};
@ -476,7 +476,7 @@ namespace detail {
return ((obj).*(p_ptr))(forward<A>(args)...);
}
template<typename... A>
auto operator()(const T &obj, A &&...args) ->
auto operator()(T const &obj, A &&...args) ->
decltype(((obj).*(p_ptr))(forward<A>(args)...)) const {
return ((obj).*(p_ptr))(forward<A>(args)...);
}
@ -486,7 +486,7 @@ namespace detail {
return ((obj)->*(p_ptr))(forward<A>(args)...);
}
template<typename... A>
auto operator()(const T *obj, A &&...args) ->
auto operator()(T const *obj, A &&...args) ->
decltype(((obj)->*(p_ptr))(forward<A>(args)...)) const {
return ((obj)->*(p_ptr))(forward<A>(args)...);
}
@ -518,22 +518,22 @@ namespace detail {
struct FmStorage {
FunctorData data;
const FunctionManager *manager;
FunctionManager const *manager;
template<typename A>
A &get_alloc() {
union {
const FunctionManager **m;
FunctionManager const **m;
A *alloc;
} u;
u.m = &manager;
return *u.alloc;
}
template<typename A>
const A &get_alloc() const {
A const &get_alloc() const {
union {
const FunctionManager * const *m;
const A *alloc;
FunctionManager const * const *m;
A const *alloc;
} u;
u.m = &manager;
return *u.alloc;
@ -543,7 +543,7 @@ namespace detail {
template<typename T, typename A, typename E = void>
struct FunctorDataManager {
template<typename R, typename ...Args>
static R call(const FunctorData &s, Args ...args) {
static R call(FunctorData const &s, Args ...args) {
return ((T &)s)(forward<Args>(args)...);
}
@ -559,9 +559,9 @@ namespace detail {
get_ref(s).~T();
}
static T &get_ref(const FmStorage &s) {
static T &get_ref(FmStorage const &s) {
union {
const FunctorData *data;
FunctorData const *data;
T *ret;
} u;
u.data = &s.data;
@ -572,7 +572,7 @@ namespace detail {
template<typename T, typename A>
struct FunctorDataManager<T, A, EnableIf<!FunctorInPlace<T>>> {
template<typename R, typename ...Args>
static R call(const FunctorData &s, Args ...args) {
static R call(FunctorData const &s, Args ...args) {
return (*(AllocatorPointer<A> &)s)(forward<Args>(args)...);
}
@ -596,7 +596,7 @@ namespace detail {
ptr = nullptr;
}
static T &get_ref(const FmStorage &s) {
static T &get_ref(FmStorage const &s) {
return *get_ptr_ref(s);
}
@ -604,13 +604,13 @@ namespace detail {
return (AllocatorPointer<A> &)(s.data);
}
static AllocatorPointer<A> &get_ptr_ref(const FmStorage &s) {
static AllocatorPointer<A> &get_ptr_ref(FmStorage const &s) {
return (AllocatorPointer<A> &)(s.data);
}
};
template<typename T, typename A>
static const FunctionManager &get_default_fm();
static FunctionManager const &get_default_fm();
template<typename T, typename A>
static void create_fm(FmStorage &s, A &&a) {
@ -632,14 +632,14 @@ namespace detail {
void (* const call_move_and_destroyf)(FmStorage &lhs,
FmStorage &&rhs);
void (* const call_copyf)(FmStorage &lhs,
const FmStorage &rhs);
FmStorage const &rhs);
void (* const call_copyf_fo)(FmStorage &lhs,
const FmStorage &rhs);
FmStorage const &rhs);
void (* const call_destroyf)(FmStorage &s);
template<typename T, typename A>
static void call_move_and_destroy(FmStorage &lhs,
FmStorage &&rhs) {
FmStorage &&rhs) {
using Spec = FunctorDataManager<T, A>;
Spec::move_f(lhs, move(rhs));
Spec::destroy_f(rhs.get_alloc<A>(), rhs);
@ -649,7 +649,7 @@ namespace detail {
template<typename T, typename A>
static void call_copy(FmStorage &lhs,
const FmStorage &rhs) {
FmStorage const &rhs) {
using Spec = FunctorDataManager<T, A>;
create_fm<T, A>(lhs, A(rhs.get_alloc<A>()));
Spec::store_f(lhs, Spec::get_ref(rhs));
@ -657,7 +657,7 @@ namespace detail {
template<typename T, typename A>
static void call_copy_fo(FmStorage &lhs,
const FmStorage &rhs) {
FmStorage const &rhs) {
using Spec = FunctorDataManager<T, A>;
Spec::store_f(lhs, Spec::get_ref(rhs));
}
@ -671,8 +671,8 @@ namespace detail {
};
template<typename T, typename A>
inline static const FunctionManager &get_default_fm() {
static const FunctionManager def_manager
inline static FunctionManager const &get_default_fm() {
static FunctionManager const def_manager
= FunctionManager::create_default_manager<T, A>();
return def_manager;
}
@ -744,7 +744,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
swap(f);
}
Function(const Function &f): p_call(f.p_call) {
Function(Function const &f): p_call(f.p_call) {
f.p_stor.manager->call_copyf(p_stor, f.p_stor);
}
@ -760,21 +760,21 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
}
template<typename A>
Function(AllocatorArg, const A &) { init_empty(); }
Function(AllocatorArg, A const &) { init_empty(); }
template<typename A>
Function(AllocatorArg, const A &, Nullptr) { init_empty(); }
Function(AllocatorArg, A const &, Nullptr) { init_empty(); }
template<typename A>
Function(AllocatorArg, const A &, Function &&f) {
Function(AllocatorArg, A const &, Function &&f) {
init_empty();
swap(f);
}
template<typename A>
Function(AllocatorArg, const A &a, const Function &f):
Function(AllocatorArg, A const &a, Function const &f):
p_call(f.p_call) {
const detail::FunctionManager *mfa
detail::FunctionManager const *mfa
= &detail::get_default_fm<AllocatorValue<A>, A>();
if (f.p_stor.manager == mfa) {
detail::create_fm<AllocatorValue<A>, A>(p_stor, A(a));
@ -783,7 +783,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
}
using AA = AllocatorRebind<A, Function>;
const detail::FunctionManager *mff
detail::FunctionManager const *mff
= &detail::get_default_fm<Function, AA>();
if (f.p_stor.manager == mff) {
detail::create_fm<Function, AA>(p_stor, AA(a));
@ -796,7 +796,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
template<typename A, typename T, typename = EnableIf<
detail::IsValidFunctor<T, R(Args...)>
>> Function(AllocatorArg, const A &a, T f) {
>> Function(AllocatorArg, A const &a, T f) {
if (func_is_null(f)) {
init_empty();
return;
@ -814,7 +814,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
return *this;
}
Function &operator=(const Function &f) {
Function &operator=(Function const &f) {
p_stor.manager->call_destroyf(p_stor);
swap(Function(f));
return *this;
@ -825,7 +825,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
}
template<typename F, typename A>
void assign(F &&f, const A &a) {
void assign(F &&f, A const &a) {
Function(allocator_arg, a, forward<F>(f)).swap(*this);
}
@ -841,7 +841,7 @@ struct Function<R(Args...)>: detail::FunctionBase<R, Args...> {
private:
detail::FmStorage p_stor;
R (*p_call)(const detail::FunctorData &, Args...);
R (*p_call)(detail::FunctorData const &, Args...);
template<typename T, typename A>
void initialize(T &&f, A &&a) {
@ -860,7 +860,7 @@ private:
}
template<typename T>
static bool func_is_null(const T &) { return false; }
static bool func_is_null(T const &) { return false; }
static bool func_is_null(R (* const &fptr)(Args...)) {
return fptr == nullptr;
@ -878,16 +878,16 @@ private:
};
template<typename T>
bool operator==(Nullptr, const Function<T> &rhs) { return !rhs; }
bool operator==(Nullptr, Function<T> const &rhs) { return !rhs; }
template<typename T>
bool operator==(const Function<T> &lhs, Nullptr) { return !lhs; }
bool operator==(Function<T> const &lhs, Nullptr) { return !lhs; }
template<typename T>
bool operator!=(Nullptr, const Function<T> &rhs) { return rhs; }
bool operator!=(Nullptr, Function<T> const &rhs) { return rhs; }
template<typename T>
bool operator!=(const Function<T> &lhs, Nullptr) { return lhs; }
bool operator!=(Function<T> const &lhs, Nullptr) { return lhs; }
namespace detail {
template<typename F>

View File

@ -16,17 +16,17 @@ namespace std {
template<typename T>
class initializer_list {
const T *p_buf;
T const *p_buf;
ostd::Size p_len;
constexpr initializer_list(const T *v, ostd::Size n): p_buf(v), p_len(n) {}
constexpr initializer_list(T const *v, ostd::Size n): p_buf(v), p_len(n) {}
public:
constexpr initializer_list(): p_buf(nullptr), p_len(0) {}
constexpr ostd::Size size() const { return p_len; }
constexpr const T *begin() const { return p_buf; }
constexpr const T *end() const { return p_buf + p_len; }
constexpr T const *begin() const { return p_buf; }
constexpr T const *end() const { return p_buf + p_len; }
};
}
@ -39,13 +39,13 @@ namespace ostd {
template<typename T> using InitializerList = std::initializer_list<T>;
template<typename T>
PointerRange<const T> iter(std::initializer_list<T> init) {
return PointerRange<const T>(init.begin(), init.end());
PointerRange<T const> iter(std::initializer_list<T> init) {
return PointerRange<T const>(init.begin(), init.end());
}
template<typename T>
PointerRange<const T> citer(std::initializer_list<T> init) {
return PointerRange<const T>(init.begin(), init.end());
PointerRange<T const> citer(std::initializer_list<T> init) {
return PointerRange<T const>(init.begin(), init.end());
}
}

View File

@ -20,14 +20,14 @@ enum class StreamMode {
};
namespace detail {
static const char *filemodes[] = {
static char const *filemodes[] = {
"rb", "wb", "ab", "rb+", "wb+", "ab+"
};
}
struct FileStream: Stream {
FileStream(): p_f(), p_owned(false) {}
FileStream(const FileStream &) = delete;
FileStream(FileStream const &) = delete;
FileStream(FileStream &&s): p_f(s.p_f), p_owned(s.p_owned) {
s.p_f = nullptr;
s.p_owned = false;
@ -41,7 +41,7 @@ struct FileStream: Stream {
~FileStream() { close(); }
FileStream &operator=(const FileStream &) = delete;
FileStream &operator=(FileStream const &) = delete;
FileStream &operator=(FileStream &&s) {
close();
swap(s);
@ -100,7 +100,7 @@ struct FileStream: Stream {
return fread(buf, 1, count, p_f);
}
Size write_bytes(const void *buf, Size count) {
Size write_bytes(void const *buf, Size count) {
return fwrite(buf, 1, count, p_f);
}
@ -138,39 +138,39 @@ namespace detail {
}
template<typename T>
inline void write_impl(const T &v, EnableIf<
!IsConstructible<ConstCharRange, const T &>, IoNat
inline void write_impl(T const &v, EnableIf<
!IsConstructible<ConstCharRange, T const &>, IoNat
> = IoNat()) {
write(ostd::to_string(v));
}
}
template<typename T>
inline void write(const T &v) {
inline void write(T const &v) {
detail::write_impl(v);
}
template<typename T, typename ...A>
inline void write(const T &v, const A &...args) {
inline void write(T const &v, A const &...args) {
write(v);
write(args...);
}
template<typename T>
inline void writeln(const T &v) {
inline void writeln(T const &v) {
write(v);
putc('\n', ::stdout);
}
template<typename T, typename ...A>
inline void writeln(const T &v, const A &...args) {
inline void writeln(T const &v, A const &...args) {
write(v);
write(args...);
putc('\n', ::stdout);
}
template<typename ...A>
inline void writef(ConstCharRange fmt, const A &...args) {
inline void writef(ConstCharRange fmt, A const &...args) {
char buf[512];
Ptrdiff need = format(detail::FormatOutRange<sizeof(buf)>(buf),
fmt, args...);
@ -186,7 +186,7 @@ inline void writef(ConstCharRange fmt, const A &...args) {
}
template<typename ...A>
inline void writefln(ConstCharRange fmt, const A &...args) {
inline void writefln(ConstCharRange fmt, A const &...args) {
writef(fmt, args...);
putc('\n', ::stdout);
}

View File

@ -19,22 +19,22 @@ namespace ostd {
namespace detail {
template<typename T>
using KeysetKeyRet = decltype(declval<const T &>().get_key());
using KeysetKeyRet = decltype(declval<T const &>().get_key());
template<typename T>
using KeysetKey = const Decay<KeysetKeyRet<T>>;
using KeysetKey = Decay<KeysetKeyRet<T>> const;
template<typename T, typename A> struct KeysetBase {
using Key = KeysetKey<T>;
using RetKey = Conditional<IsReference<KeysetKeyRet<T>>, Key &, Key>;
static inline RetKey get_key(const T &e) {
static inline RetKey get_key(T const &e) {
return e.get_key();
}
static inline T &get_data(T &e) {
return e;
}
template<typename U>
static inline void set_key(T &, const U &, A &) {}
static inline void set_key(T &, U const &, A &) {}
static inline void swap_elem(T &a, T &b) { swap_adl(a, b); }
};
@ -60,35 +60,35 @@ namespace detail {
using Pointer = AllocatorPointer<A>;
using ConstPointer = AllocatorConstPointer<A>;
using Range = HashRange<T>;
using ConstRange = HashRange<const T>;
using ConstRange = HashRange<T const>;
using LocalRange = BucketRange<T>;
using ConstLocalRange = BucketRange<const T>;
using ConstLocalRange = BucketRange<T const>;
using Allocator = A;
explicit KeysetImpl(Size size, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
explicit KeysetImpl(Size size, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size, hf, eqf, alloc) {}
KeysetImpl(): KeysetImpl(0) {}
explicit KeysetImpl(const A &alloc): KeysetImpl(0, H(), C(), alloc) {}
explicit KeysetImpl(A const &alloc): KeysetImpl(0, H(), C(), alloc) {}
KeysetImpl(Size size, const A &alloc):
KeysetImpl(Size size, A const &alloc):
KeysetImpl(size, H(), C(), alloc) {}
KeysetImpl(Size size, const H &hf, const A &alloc):
KeysetImpl(Size size, H const &hf, A const &alloc):
KeysetImpl(size, hf, C(), alloc) {}
KeysetImpl(const KeysetImpl &m): Base(m,
KeysetImpl(KeysetImpl const &m): Base(m,
allocator_container_copy(m.get_alloc())) {}
KeysetImpl(const KeysetImpl &m, const A &alloc): Base(m, alloc) {}
KeysetImpl(KeysetImpl const &m, A const &alloc): Base(m, alloc) {}
KeysetImpl(KeysetImpl &&m): Base(move(m)) {}
KeysetImpl(KeysetImpl &&m, const A &alloc): Base(move(m), alloc) {}
KeysetImpl(KeysetImpl &&m, A const &alloc): Base(move(m), alloc) {}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> KeysetImpl(R range, Size size = 0, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
>> KeysetImpl(R range, Size size = 0, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size ? size : detail::estimate_hrsize(range),
hf, eqf, alloc) {
for (; !range.empty(); range.pop_front())
@ -97,25 +97,25 @@ namespace detail {
}
template<typename R>
KeysetImpl(R range, Size size, const A &alloc)
KeysetImpl(R range, Size size, A const &alloc)
: KeysetImpl(range, size, H(), C(), alloc) {}
template<typename R>
KeysetImpl(R range, Size size, const H &hf, const A &alloc)
KeysetImpl(R range, Size size, H const &hf, A const &alloc)
: KeysetImpl(range, size, hf, C(), alloc) {}
KeysetImpl(InitializerList<Value> init, Size size = 0,
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
H const &hf = H(), C const &eqf = C(), A const &alloc = A()
): KeysetImpl(iter(init), size, hf, eqf, alloc) {}
KeysetImpl(InitializerList<Value> init, Size size, const A &alloc)
KeysetImpl(InitializerList<Value> init, Size size, A const &alloc)
: KeysetImpl(iter(init), size, H(), C(), alloc) {}
KeysetImpl(InitializerList<Value> init, Size size, const H &hf,
const A &alloc
KeysetImpl(InitializerList<Value> init, Size size, H const &hf,
A const &alloc
): KeysetImpl(iter(init), size, hf, C(), alloc) {}
KeysetImpl &operator=(const KeysetImpl &m) {
KeysetImpl &operator=(KeysetImpl const &m) {
Base::operator=(m);
return *this;
}
@ -137,16 +137,16 @@ namespace detail {
return *this;
}
T *at(const Key &key) {
T *at(Key const &key) {
static_assert(!IsMultihash, "at() only allowed on regular keysets");
return Base::access(key);
}
const T *at(const Key &key) const {
T const *at(Key const &key) const {
static_assert(!IsMultihash, "at() only allowed on regular keysets");
return Base::access(key);
}
T &operator[](const Key &key) {
T &operator[](Key const &key) {
static_assert(!IsMultihash, "operator[] only allowed on regular keysets");
return Base::access_or_insert(key);
}

View File

@ -18,9 +18,9 @@ namespace ostd {
namespace detail {
template<typename K, typename T, typename A> struct MapBase {
using Element = Pair<const K, T>;
using Element = Pair<K const, T>;
static inline const K &get_key(Element &e) {
static inline K const &get_key(Element &e) {
return e.first;
}
static inline T &get_data(Element &e) {
@ -41,11 +41,11 @@ namespace detail {
typename K, typename T, typename H,
typename C, typename A, bool IsMultihash
> struct MapImpl: detail::Hashtable<detail::MapBase<K, T, A>,
Pair<const K, T>, K, T, H, C, A, IsMultihash
Pair<K const, T>, K, T, H, C, A, IsMultihash
> {
private:
using Base = detail::Hashtable<detail::MapBase<K, T, A>,
Pair<const K, T>, K, T, H, C, A, IsMultihash
Pair<K const, T>, K, T, H, C, A, IsMultihash
>;
public:
@ -55,40 +55,40 @@ namespace detail {
using Difference = Ptrdiff;
using Hasher = H;
using KeyEqual = C;
using Value = Pair<const K, T>;
using Value = Pair<K const, T>;
using Reference = Value &;
using Pointer = AllocatorPointer<A>;
using ConstPointer = AllocatorConstPointer<A>;
using Range = HashRange<Pair<const K, T>>;
using ConstRange = HashRange<const Pair<const K, T>>;
using LocalRange = BucketRange<Pair<const K, T>>;
using ConstLocalRange = BucketRange<const Pair<const K, T>>;
using Range = HashRange<Pair<K const, T>>;
using ConstRange = HashRange<Pair<K const, T> const>;
using LocalRange = BucketRange<Pair<K const, T>>;
using ConstLocalRange = BucketRange<Pair<K const, T> const>;
using Allocator = A;
explicit MapImpl(Size size, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
explicit MapImpl(Size size, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size, hf, eqf, alloc) {}
MapImpl(): MapImpl(0) {}
explicit MapImpl(const A &alloc): MapImpl(0, H(), C(), alloc) {}
explicit MapImpl(A const &alloc): MapImpl(0, H(), C(), alloc) {}
MapImpl(Size size, const A &alloc):
MapImpl(Size size, A const &alloc):
MapImpl(size, H(), C(), alloc) {}
MapImpl(Size size, const H &hf, const A &alloc):
MapImpl(Size size, H const &hf, A const &alloc):
MapImpl(size, hf, C(), alloc) {}
MapImpl(const MapImpl &m): Base(m,
MapImpl(MapImpl const &m): Base(m,
allocator_container_copy(m.get_alloc())) {}
MapImpl(const MapImpl &m, const A &alloc): Base(m, alloc) {}
MapImpl(MapImpl const &m, A const &alloc): Base(m, alloc) {}
MapImpl(MapImpl &&m): Base(move(m)) {}
MapImpl(MapImpl &&m, const A &alloc): Base(move(m), alloc) {}
MapImpl(MapImpl &&m, A const &alloc): Base(move(m), alloc) {}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> MapImpl(R range, Size size = 0, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
>> MapImpl(R range, Size size = 0, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size ? size : detail::estimate_hrsize(range),
hf, eqf, alloc) {
for (; !range.empty(); range.pop_front())
@ -97,25 +97,25 @@ namespace detail {
}
template<typename R>
MapImpl(R range, Size size, const A &alloc)
MapImpl(R range, Size size, A const &alloc)
: MapImpl(range, size, H(), C(), alloc) {}
template<typename R>
MapImpl(R range, Size size, const H &hf, const A &alloc)
MapImpl(R range, Size size, H const &hf, A const &alloc)
: MapImpl(range, size, hf, C(), alloc) {}
MapImpl(InitializerList<Value> init, Size size = 0,
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
H const &hf = H(), C const &eqf = C(), A const &alloc = A()
): MapImpl(iter(init), size, hf, eqf, alloc) {}
MapImpl(InitializerList<Value> init, Size size, const A &alloc)
MapImpl(InitializerList<Value> init, Size size, A const &alloc)
: MapImpl(iter(init), size, H(), C(), alloc) {}
MapImpl(InitializerList<Value> init, Size size, const H &hf,
const A &alloc
MapImpl(InitializerList<Value> init, Size size, H const &hf,
A const &alloc
): MapImpl(iter(init), size, hf, C(), alloc) {}
MapImpl &operator=(const MapImpl &m) {
MapImpl &operator=(MapImpl const &m) {
Base::operator=(m);
return *this;
}
@ -137,16 +137,16 @@ namespace detail {
return *this;
}
T *at(const K &key) {
T *at(K const &key) {
static_assert(!IsMultihash, "at() only allowed on regular maps");
return Base::access(key);
}
const T *at(const K &key) const {
T const *at(K const &key) const {
static_assert(!IsMultihash, "at() only allowed on regular maps");
return Base::access(key);
}
T &operator[](const K &key) {
T &operator[](K const &key) {
static_assert(!IsMultihash, "operator[] only allowed on regular maps");
return Base::access_or_insert(key);
}
@ -165,14 +165,14 @@ template<
typename K, typename T,
typename H = ToHash<K>,
typename C = EqualWithCstr<K>,
typename A = Allocator<Pair<const K, T>>
typename A = Allocator<Pair<K const, T>>
> using Map = detail::MapImpl<K, T, H, C, A, false>;
template<
typename K, typename T,
typename H = ToHash<K>,
typename C = EqualWithCstr<K>,
typename A = Allocator<Pair<const K, T>>
typename A = Allocator<Pair<K const, T>>
> using Multimap = detail::MapImpl<K, T, H, C, A, true>;
} /* namespace ostd */

View File

@ -36,7 +36,7 @@ namespace detail {
constexpr MaybeStorage(): p_null_state('\0') {}
MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) {
MaybeStorage(MaybeStorage const &v): p_engaged(v.p_engaged) {
if (p_engaged) ::new(address_of(p_value)) Value(v.p_value);
}
@ -45,7 +45,7 @@ namespace detail {
::new(address_of(p_value)) Value(move(v.p_value));
}
constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {}
constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {}
constexpr MaybeStorage(Value &&v): p_value(move(v)), p_engaged(true) {}
template<typename ...A> constexpr MaybeStorage(InPlace, A &&...args):
@ -68,7 +68,7 @@ namespace detail {
constexpr MaybeStorage(): p_null_state('\0') {}
MaybeStorage(const MaybeStorage &v): p_engaged(v.p_engaged) {
MaybeStorage(MaybeStorage const &v): p_engaged(v.p_engaged) {
if (p_engaged) ::new(address_of(p_value)) Value(v.p_value);
}
@ -77,7 +77,7 @@ namespace detail {
::new(address_of(p_value)) Value(move(v.p_value));
}
constexpr MaybeStorage(const Value &v): p_value(v), p_engaged(true) {}
constexpr MaybeStorage(Value const &v): p_value(v), p_engaged(true) {}
constexpr MaybeStorage(Value &&v):
p_value(move(v)), p_engaged(true) {}
@ -105,10 +105,10 @@ public:
"Initialization of Maybe with a non-destructible object is not allowed.");
constexpr Maybe() {}
Maybe(const Maybe &) = default;
Maybe(Maybe const &) = default;
Maybe(Maybe &&) = default;
constexpr Maybe(Nothing) {}
constexpr Maybe(const Value &v): Base(v) {}
constexpr Maybe(Value const &v): Base(v) {}
constexpr Maybe(Value &&v): Base(move(v)) {}
template<typename ...A, typename = EnableIf<IsConstructible<T, A...>>>
@ -131,7 +131,7 @@ public:
return *this;
}
Maybe &operator=(const Maybe &v) {
Maybe &operator=(Maybe const &v) {
if (this->p_engaged == v.p_engaged) {
if (this->p_engaged) this->p_value = v.p_value;
} else {
@ -189,7 +189,7 @@ public:
this->p_engaged = true;
}
constexpr const Value *operator->() const {
constexpr Value const *operator->() const {
return address_of(this->p_value);
}
@ -197,7 +197,7 @@ public:
return address_of(this->p_value);
}
constexpr const Value &operator*() const {
constexpr Value const &operator*() const {
return this->p_value;
}
@ -207,7 +207,7 @@ public:
constexpr explicit operator bool() const { return this->p_engaged; }
constexpr const Value &value() const {
constexpr Value const &value() const {
return this->p_value;
}
@ -257,156 +257,156 @@ public:
/* maybe vs maybe */
template<typename T>
inline constexpr bool operator==(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator==(Maybe<T> const &a, Maybe<T> const &b) {
return (bool(a) != bool(b)) ? false : (!bool(a) ? true : (*a == *b));
}
template<typename T>
inline constexpr bool operator!=(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator!=(Maybe<T> const &a, Maybe<T> const &b) {
return !(a == b);
}
template<typename T>
inline constexpr bool operator<(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator<(Maybe<T> const &a, Maybe<T> const &b) {
return !bool(b) ? false : (!bool(a) ? true : (*a < *b));
}
template<typename T>
inline constexpr bool operator>(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator>(Maybe<T> const &a, Maybe<T> const &b) {
return b < a;
}
template<typename T>
inline constexpr bool operator<=(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator<=(Maybe<T> const &a, Maybe<T> const &b) {
return !(b < a);
}
template<typename T>
inline constexpr bool operator>=(const Maybe<T> &a, const Maybe<T> &b) {
inline constexpr bool operator>=(Maybe<T> const &a, Maybe<T> const &b) {
return !(a < b);
}
/* maybe vs nothing */
template<typename T>
inline constexpr bool operator==(const Maybe<T> &v, Nothing) {
inline constexpr bool operator==(Maybe<T> const &v, Nothing) {
return !bool(v);
}
template<typename T>
inline constexpr bool operator==(Nothing, const Maybe<T> &v) {
inline constexpr bool operator==(Nothing, Maybe<T> const &v) {
return !bool(v);
}
template<typename T>
inline constexpr bool operator!=(const Maybe<T> &v, Nothing) {
inline constexpr bool operator!=(Maybe<T> const &v, Nothing) {
return bool(v);
}
template<typename T>
inline constexpr bool operator!=(Nothing, const Maybe<T> &v) {
inline constexpr bool operator!=(Nothing, Maybe<T> const &v) {
return bool(v);
}
template<typename T>
inline constexpr bool operator<(const Maybe<T> &, Nothing) {
inline constexpr bool operator<(Maybe<T> const &, Nothing) {
return false;
}
template<typename T>
inline constexpr bool operator<(Nothing, const Maybe<T> &v) {
inline constexpr bool operator<(Nothing, Maybe<T> const &v) {
return bool(v);
}
template<typename T>
inline constexpr bool operator<=(const Maybe<T> &v, Nothing) {
inline constexpr bool operator<=(Maybe<T> const &v, Nothing) {
return !bool(v);
}
template<typename T>
inline constexpr bool operator<=(Nothing, const Maybe<T> &) {
inline constexpr bool operator<=(Nothing, Maybe<T> const &) {
return true;
}
template<typename T>
inline constexpr bool operator>(const Maybe<T> &v, Nothing) {
inline constexpr bool operator>(Maybe<T> const &v, Nothing) {
return bool(v);
}
template<typename T>
inline constexpr bool operator>(Nothing, const Maybe<T> &) {
inline constexpr bool operator>(Nothing, Maybe<T> const &) {
return false;
}
template<typename T>
inline constexpr bool operator>=(const Maybe<T> &, Nothing) {
inline constexpr bool operator>=(Maybe<T> const &, Nothing) {
return true;
}
template<typename T>
inline constexpr bool operator>=(Nothing, const Maybe<T> &v) {
inline constexpr bool operator>=(Nothing, Maybe<T> const &v) {
return !bool(v);
}
/* maybe vs T */
template<typename T>
inline constexpr bool operator==(const Maybe<T> &a, const T &b) {
inline constexpr bool operator==(Maybe<T> const &a, T const &b) {
return bool(a) ? (*a == b) : false;
}
template<typename T>
inline constexpr bool operator==(const T &b, const Maybe<T> &a) {
inline constexpr bool operator==(T const &b, Maybe<T> const &a) {
return bool(a) ? (*a == b) : false;
}
template<typename T>
inline constexpr bool operator!=(const Maybe<T> &a, const T &b) {
inline constexpr bool operator!=(Maybe<T> const &a, T const &b) {
return bool(a) ? !(*a == b) : true;
}
template<typename T>
inline constexpr bool operator!=(const T &b, const Maybe<T> &a) {
inline constexpr bool operator!=(T const &b, Maybe<T> const &a) {
return bool(a) ? !(*a == b) : true;
}
template<typename T>
inline constexpr bool operator<(const Maybe<T> &a, const T &b) {
inline constexpr bool operator<(Maybe<T> const &a, T const &b) {
return bool(a) ? Less<T>()(*a, b) : true;
}
template<typename T>
inline constexpr bool operator<(const T &b, const Maybe<T> &a) {
inline constexpr bool operator<(T const &b, Maybe<T> const &a) {
return bool(a) ? Less<T>()(b, *a) : false;
}
template<typename T>
inline constexpr bool operator<=(const Maybe<T> &a, const T &b) {
inline constexpr bool operator<=(Maybe<T> const &a, T const &b) {
return !(a > b);
}
template<typename T>
inline constexpr bool operator<=(const T &b, const Maybe<T> &a) {
inline constexpr bool operator<=(T const &b, Maybe<T> const &a) {
return !(b > a);
}
template<typename T>
inline constexpr bool operator>(const Maybe<T> &a, const T &b) {
inline constexpr bool operator>(Maybe<T> const &a, T const &b) {
return bool(a) ? (b < a) : true;
}
template<typename T>
inline constexpr bool operator>(const T &b, const Maybe<T> &a) {
inline constexpr bool operator>(T const &b, Maybe<T> const &a) {
return bool(a) ? (a < b) : true;
}
template<typename T>
inline constexpr bool operator>=(const Maybe<T> &a, const T &b) {
inline constexpr bool operator>=(Maybe<T> const &a, T const &b) {
return !(a < b);
}
template<typename T>
inline constexpr bool operator>=(const T &b, const Maybe<T> &a) {
inline constexpr bool operator>=(T const &b, Maybe<T> const &a) {
return !(b < a);
}

View File

@ -17,7 +17,7 @@ namespace ostd {
template<typename T> constexpr T *address_of(T &v) {
return reinterpret_cast<T *>(&const_cast<char &>
(reinterpret_cast<const volatile char &>(v)));
(reinterpret_cast<char const volatile &>(v)));
}
/* pointer traits */
@ -181,7 +181,7 @@ template<typename T>
struct DefaultDelete {
constexpr DefaultDelete() = default;
template<typename U> DefaultDelete(const DefaultDelete<U> &) {};
template<typename U> DefaultDelete(DefaultDelete<U> const &) {};
void operator()(T *p) const {
delete p;
@ -192,7 +192,7 @@ template<typename T>
struct DefaultDelete<T[]> {
constexpr DefaultDelete() = default;
template<typename U> DefaultDelete(const DefaultDelete<U[]> &) {};
template<typename U> DefaultDelete(DefaultDelete<U[]> const &) {};
void operator()(T *p) const {
delete[] p;
@ -234,7 +234,7 @@ private:
struct Nat { int x; };
using Dref = RemoveReference<D> &;
using Dcref = const RemoveReference<D> &;
using Dcref = RemoveReference<D> const &;
public:
constexpr Box(): p_stor(nullptr, D()) {
@ -248,7 +248,7 @@ public:
static_assert(!IsPointer<D>, "Box constructed with null fptr deleter");
}
Box(Pointer p, Conditional<IsReference<D>, D, AddLvalueReference<const D>> d):
Box(Pointer p, Conditional<IsReference<D>, D, AddLvalueReference<D const>> d):
p_stor(p, d) {}
Box(Pointer p, RemoveReference<D> &&d):
@ -347,7 +347,7 @@ private:
struct Nat { int x; };
using Dref = RemoveReference<D> &;
using Dcref = const RemoveReference<D> &;
using Dcref = RemoveReference<D> const &;
public:
constexpr Box(): p_stor(nullptr, D()) {
@ -364,11 +364,11 @@ public:
}
template<typename U> Box(U p, Conditional<
IsReference<D>, D, AddLvalueReference<const D>
IsReference<D>, D, AddLvalueReference<D const>
> d, EnableIf<detail::SameOrLessCvQualified<U, Pointer>, Nat> = Nat()):
p_stor(p, d) {}
Box(Nullptr, Conditional<IsReference<D>, D, AddLvalueReference<const D>> d):
Box(Nullptr, Conditional<IsReference<D>, D, AddLvalueReference<D const>> d):
p_stor(nullptr, d) {}
template<typename U> Box(U p, RemoveReference<D> &&d,
@ -495,15 +495,15 @@ template<typename> struct Allocator;
template<> struct Allocator<void> {
using Value = void;
using Pointer = void *;
using ConstPointer = const void *;
using ConstPointer = void const *;
template<typename U> using Rebind = Allocator<U>;
};
template<> struct Allocator<const void> {
using Value = const void;
using Pointer = const void *;
using ConstPointer = const void *;
template<> struct Allocator<void const> {
using Value = void const;
using Pointer = void const *;
using ConstPointer = void const *;
template<typename U> using Rebind = Allocator<U>;
};
@ -513,14 +513,14 @@ template<typename T> struct Allocator {
using Difference = Ptrdiff;
using Value = T;
using Reference = T &;
using ConstReference = const T &;
using ConstReference = T const &;
using Pointer = T *;
using ConstPointer = const T *;
using ConstPointer = T const *;
template<typename U> using Rebind = Allocator<U>;
Allocator() {}
template<typename U> Allocator(const Allocator<U> &) {}
template<typename U> Allocator(Allocator<U> const &) {}
Pointer address(Reference v) const {
return address_of(v);
@ -545,19 +545,19 @@ template<typename T> struct Allocator {
void destroy(Pointer p) { p->~T(); }
};
template<typename T> struct Allocator<const T> {
template<typename T> struct Allocator<T const> {
using Size = ostd::Size;
using Difference = Ptrdiff;
using Value = const T;
using Reference = const T &;
using ConstReference = const T &;
using Pointer = const T *;
using ConstPointer = const T *;
using Value = T const;
using Reference = T const &;
using ConstReference = T const &;
using Pointer = T const *;
using ConstPointer = T const *;
template<typename U> using Rebind = Allocator<U>;
Allocator() {}
template<typename U> Allocator(const Allocator<U> &) {}
template<typename U> Allocator(Allocator<U> const &) {}
ConstPointer address(ConstReference v) const {
return address_of(v);
@ -580,12 +580,12 @@ template<typename T> struct Allocator<const T> {
};
template<typename T, typename U>
bool operator==(const Allocator<T> &, const Allocator<U> &) {
bool operator==(Allocator<T> const &, Allocator<U> const &) {
return true;
}
template<typename T, typename U>
bool operator!=(const Allocator<T> &, const Allocator<U> &) {
bool operator!=(Allocator<T> const &, Allocator<U> const &) {
return false;
}
@ -608,7 +608,7 @@ namespace detail {
template<typename T, typename P, typename A>
struct ConstPointer<T, P, A, false> {
using Type = PointerRebind<P, const T>;
using Type = PointerRebind<P, T const>;
};
template<typename T>
@ -644,7 +644,7 @@ namespace detail {
template<typename P, typename A>
struct ConstVoidPointer<P, A, false> {
using Type = PointerRebind<P, const void>;
using Type = PointerRebind<P, void const>;
};
template<typename T>
@ -859,7 +859,7 @@ namespace detail {
-> decltype(a.allocate(sz, p), True());
template<typename A, typename S, typename CVP>
auto allocate_hint_test(const A &, S &&, CVP &&)
auto allocate_hint_test(A const &, S &&, CVP &&)
-> False;
template<typename A, typename S, typename CVP>
@ -910,7 +910,7 @@ namespace detail {
True());
template<typename A, typename T, typename ...Args>
auto construct_test(const A &, T *, Args &&...)
auto construct_test(A const &, T *, Args &&...)
-> False;
template<typename A, typename T, typename ...Args>
@ -944,7 +944,7 @@ namespace detail {
auto destroy_test(A &&a, P &&p) -> decltype(a.destroy(p), True());
template<typename A, typename P>
auto destroy_test(const A &, P &&) -> False;
auto destroy_test(A const &, P &&) -> False;
template<typename A, typename P>
constexpr bool DestroyTest
@ -973,27 +973,27 @@ namespace detail {
auto alloc_max_size_test(A &&a) -> decltype(a.max_size(), True());
template<typename A>
auto alloc_max_size_test(const A &) -> False;
auto alloc_max_size_test(A const &) -> False;
template<typename A>
constexpr bool AllocMaxSizeTest
= IsSame<decltype(alloc_max_size_test(declval<A &>())), True>;
template<typename A>
inline AllocatorSize<A> alloc_max_size(True, const A &a) {
inline AllocatorSize<A> alloc_max_size(True, A const &a) {
return a.max_size();
}
template<typename A>
inline AllocatorSize<A> alloc_max_size(False, const A &) {
inline AllocatorSize<A> alloc_max_size(False, A const &) {
return AllocatorSize<A>(~0);
}
} /* namespace detail */
template<typename A>
inline AllocatorSize<A> allocator_max_size(const A &a) {
inline AllocatorSize<A> allocator_max_size(A const &a) {
return detail::alloc_max_size(BoolConstant<
detail::AllocMaxSizeTest<const A>
detail::AllocMaxSizeTest<A const>
>(), a);
}
@ -1004,27 +1004,27 @@ namespace detail {
auto alloc_copy_test(A &&a) -> decltype(a.container_copy(), True());
template<typename A>
auto alloc_copy_test(const A &) -> False;
auto alloc_copy_test(A const &) -> False;
template<typename A>
constexpr bool AllocCopyTest
= IsSame<decltype(alloc_copy_test(declval<A &>())), True>;
template<typename A>
inline AllocatorType<A> alloc_container_copy(True, const A &a) {
inline AllocatorType<A> alloc_container_copy(True, A const &a) {
return a.container_copy();
}
template<typename A>
inline AllocatorType<A> alloc_container_copy(False, const A &a) {
inline AllocatorType<A> alloc_container_copy(False, A const &a) {
return a;
}
} /* namespace detail */
template<typename A>
inline AllocatorType<A> allocator_container_copy(const A &a) {
inline AllocatorType<A> allocator_container_copy(A const &a) {
return detail::alloc_container_copy(BoolConstant<
detail::AllocCopyTest<const A>
detail::AllocCopyTest<A const>
>(), a);
}

View File

@ -186,9 +186,9 @@ namespace detail {
template<typename T> constexpr bool IsOutputRangeCore
= IsConvertible<RangeCategory<T>, OutputRangeTag> ||
(IsInputRange<T> &&
(detail::OutputRangeTest<T, const RangeValue<T> &>::value ||
detail::OutputRangeTest<T, RangeValue<T> &&>::value ||
detail::OutputRangeTest<T, RangeValue<T> >::value));
(detail::OutputRangeTest<T, RangeValue<T> const &>::value ||
detail::OutputRangeTest<T, RangeValue<T> &&>::value ||
detail::OutputRangeTest<T, RangeValue<T> >::value));
template<typename T, bool = detail::IsRangeTest<T>>
constexpr bool IsOutputRangeBase = false;
@ -205,7 +205,7 @@ namespace detail {
template<typename T>
struct RangeIterator {
RangeIterator(): p_range() {}
explicit RangeIterator(const T &range) {
explicit RangeIterator(T const &range) {
::new(&get_ref()) T(range);
}
explicit RangeIterator(T &&range) {
@ -221,7 +221,7 @@ namespace detail {
bool operator!=(RangeIterator) const { return !get_ref().empty(); }
private:
T &get_ref() { return *((T *)&p_range); }
const T &get_ref() const { return *((T *)&p_range); }
T const &get_ref() const { return *((T *)&p_range); }
AlignedStorage<sizeof(T), alignof(T)> p_range;
};
}
@ -271,15 +271,15 @@ public:
using Range = T;
RangeHalf() = delete;
RangeHalf(const T &range): p_range(range) {}
RangeHalf(T const &range): p_range(range) {}
template<typename U, typename = EnableIf<IsConvertible<U, T>>>
RangeHalf(const RangeHalf<U> &half): p_range(half.p_range) {}
RangeHalf(RangeHalf<U> const &half): p_range(half.p_range) {}
RangeHalf(const RangeHalf &half): p_range(half.p_range) {}
RangeHalf(RangeHalf const &half): p_range(half.p_range) {}
RangeHalf(RangeHalf &&half): p_range(move(half.p_range)) {}
RangeHalf &operator=(const RangeHalf &half) {
RangeHalf &operator=(RangeHalf const &half) {
p_range = half.p_range;
return *this;
}
@ -310,18 +310,18 @@ public:
return p_range.front();
}
RangeDifference<T> distance(const RangeHalf &half) const {
RangeDifference<T> distance(RangeHalf const &half) const {
return p_range.distance_front(half.p_range);
}
bool equals(const RangeHalf &half) const {
bool equals(RangeHalf const &half) const {
return p_range.equals_front(half.p_range);
}
bool operator==(const RangeHalf &half) const {
bool operator==(RangeHalf const &half) const {
return equals(half);
}
bool operator!=(const RangeHalf &half) const {
bool operator!=(RangeHalf const &half) const {
return !equals(half);
}
@ -377,16 +377,16 @@ public:
T iter() const { return p_range; }
HalfRange<RangeHalf> iter(const RangeHalf &other) const {
HalfRange<RangeHalf> iter(RangeHalf const &other) const {
return HalfRange<RangeHalf>(*this, other);
}
RangeValue<T> *data() { return p_range.data(); }
const RangeValue<T> *data() const { return p_range.data(); }
RangeValue<T> const *data() const { return p_range.data(); }
};
template<typename R>
inline RangeDifference<R> operator-(const R &lhs, const R &rhs) {
inline RangeDifference<R> operator-(R const &lhs, R const &rhs) {
return rhs.distance(lhs);
}
@ -438,7 +438,7 @@ template<typename B, typename C, typename V, typename R = V &,
using Reference = R;
detail::RangeIterator<B> begin() const {
return detail::RangeIterator<B>((const B &)*this);
return detail::RangeIterator<B>((B const &)*this);
}
detail::RangeIterator<B> end() const {
return detail::RangeIterator<B>();
@ -498,7 +498,7 @@ template<typename B, typename C, typename V, typename R = V &,
return RangeHalf<B>(iter());
}
Size put_n(const Value *p, Size n) {
Size put_n(Value const *p, Size n) {
B &r = *((B *)this);
Size on = n;
for (; n && r.put(*p++); --n);
@ -539,7 +539,7 @@ template<typename B, typename C, typename V, typename R = V &,
return *((B *)this);
}
B operator++(int) {
B tmp(*((const B *)this));
B tmp(*((B const *)this));
((B *)this)->pop_front();
return tmp;
}
@ -549,18 +549,18 @@ template<typename B, typename C, typename V, typename R = V &,
return *((B *)this);
}
B operator--(int) {
B tmp(*((const B *)this));
B tmp(*((B const *)this));
((B *)this)->push_front();
return tmp;
}
B operator+(Difference n) const {
B tmp(*((const B *)this));
B tmp(*((B const *)this));
tmp.pop_front_n(n);
return tmp;
}
B operator-(Difference n) const {
B tmp(*((const B *)this));
B tmp(*((B const *)this));
tmp.push_front_n(n);
return tmp;
}
@ -658,12 +658,12 @@ inline auto iter(T &r) -> decltype(r.iter()) {
}
template<typename T>
inline auto iter(const T &r) -> decltype(r.iter()) {
inline auto iter(T const &r) -> decltype(r.iter()) {
return r.iter();
}
template<typename T>
inline auto citer(const T &r) -> decltype(r.iter()) {
inline auto citer(T const &r) -> decltype(r.iter()) {
return r.iter();
}
@ -676,7 +676,7 @@ template<typename B, typename V, typename R = V &,
using Value = V;
using Reference = R;
Size put_n(const Value *p, Size n) {
Size put_n(Value const *p, Size n) {
B &r = *((B *)this);
Size on = n;
for (; n && r.put(*p++); --n);
@ -698,16 +698,16 @@ private:
T p_end;
public:
HalfRange() = delete;
HalfRange(const HalfRange &range): p_beg(range.p_beg),
HalfRange(HalfRange const &range): p_beg(range.p_beg),
p_end(range.p_end) {}
HalfRange(HalfRange &&range): p_beg(move(range.p_beg)),
p_end(move(range.p_end)) {}
HalfRange(const T &beg, const T &end): p_beg(beg),
HalfRange(T const &beg, T const &end): p_beg(beg),
p_end(end) {}
HalfRange(T &&beg, T &&end): p_beg(move(beg)),
p_end(move(end)) {}
HalfRange &operator=(const HalfRange &range) {
HalfRange &operator=(HalfRange const &range) {
p_beg = range.p_beg;
p_end = range.p_end;
return *this;
@ -739,17 +739,17 @@ public:
RangeReference<Rtype> front() const { return *p_beg; }
RangeReference<Rtype> back() const { return *(p_end - 1); }
bool equals_front(const HalfRange &range) const {
bool equals_front(HalfRange const &range) const {
return p_beg == range.p_beg;
}
bool equals_back(const HalfRange &range) const {
bool equals_back(HalfRange const &range) const {
return p_end == range.p_end;
}
RangeDifference<Rtype> distance_front(const HalfRange &range) const {
RangeDifference<Rtype> distance_front(HalfRange const &range) const {
return range.p_beg - p_beg;
}
RangeDifference<Rtype> distance_back(const HalfRange &range) const {
RangeDifference<Rtype> distance_back(HalfRange const &range) const {
return range.p_end - p_end;
}
@ -764,7 +764,7 @@ public:
return p_beg[idx];
}
bool put(const RangeValue<Rtype> &v) {
bool put(RangeValue<Rtype> const &v) {
return p_beg.range().put(v);
}
bool put(RangeValue<Rtype> &&v) {
@ -772,7 +772,7 @@ public:
}
RangeValue<Rtype> *data() { return p_beg.data(); }
const RangeValue<Rtype> *data() const { return p_beg.data(); }
RangeValue<Rtype> const *data() const { return p_beg.data(); }
};
template<typename T>
@ -788,11 +788,11 @@ private:
public:
ReverseRange() = delete;
ReverseRange(const T &range): p_range(range) {}
ReverseRange(const ReverseRange &it): p_range(it.p_range) {}
ReverseRange(T const &range): p_range(range) {}
ReverseRange(ReverseRange const &it): p_range(it.p_range) {}
ReverseRange(ReverseRange &&it): p_range(move(it.p_range)) {}
ReverseRange &operator=(const ReverseRange &v) {
ReverseRange &operator=(ReverseRange const &v) {
p_range = v.p_range;
return *this;
}
@ -800,7 +800,7 @@ public:
p_range = move(v.p_range);
return *this;
}
ReverseRange &operator=(const T &v) {
ReverseRange &operator=(T const &v) {
p_range = v;
return *this;
}
@ -812,17 +812,17 @@ public:
bool empty() const { return p_range.empty(); }
Rsize size() const { return p_range.size(); }
bool equals_front(const ReverseRange &r) const {
bool equals_front(ReverseRange const &r) const {
return p_range.equals_back(r.p_range);
}
bool equals_back(const ReverseRange &r) const {
bool equals_back(ReverseRange const &r) const {
return p_range.equals_front(r.p_range);
}
RangeDifference<T> distance_front(const ReverseRange &r) const {
RangeDifference<T> distance_front(ReverseRange const &r) const {
return -p_range.distance_back(r.p_range);
}
RangeDifference<T> distance_back(const ReverseRange &r) const {
RangeDifference<T> distance_back(ReverseRange const &r) const {
return -p_range.distance_front(r.p_range);
}
@ -863,11 +863,11 @@ private:
public:
MoveRange() = delete;
MoveRange(const T &range): p_range(range) {}
MoveRange(const MoveRange &it): p_range(it.p_range) {}
MoveRange(T const &range): p_range(range) {}
MoveRange(MoveRange const &it): p_range(it.p_range) {}
MoveRange(MoveRange &&it): p_range(move(it.p_range)) {}
MoveRange &operator=(const MoveRange &v) {
MoveRange &operator=(MoveRange const &v) {
p_range = v.p_range;
return *this;
}
@ -875,7 +875,7 @@ public:
p_range = move(v.p_range);
return *this;
}
MoveRange &operator=(const T &v) {
MoveRange &operator=(T const &v) {
p_range = v;
return *this;
}
@ -887,17 +887,17 @@ public:
bool empty() const { return p_range.empty(); }
Rsize size() const { return p_range.size(); }
bool equals_front(const MoveRange &r) const {
bool equals_front(MoveRange const &r) const {
return p_range.equals_front(r.p_range);
}
bool equals_back(const MoveRange &r) const {
bool equals_back(MoveRange const &r) const {
return p_range.equals_back(r.p_range);
}
RangeDifference<T> distance_front(const MoveRange &r) const {
RangeDifference<T> distance_front(MoveRange const &r) const {
return p_range.distance_front(r.p_range);
}
RangeDifference<T> distance_back(const MoveRange &r) const {
RangeDifference<T> distance_back(MoveRange const &r) const {
return p_range.distance_back(r.p_range);
}
@ -922,14 +922,14 @@ public:
return MoveRange<T>(p_range.slice(start, end));
}
bool put(const Rval &v) { return p_range.put(v); }
bool put(Rval const &v) { return p_range.put(v); }
bool put(Rval &&v) { return p_range.put(move(v)); }
};
template<typename T>
struct NumberRange: InputRange<NumberRange<T>, ForwardRangeTag, T, T> {
NumberRange() = delete;
NumberRange(const NumberRange &it): p_a(it.p_a), p_b(it.p_b),
NumberRange(NumberRange const &it): p_a(it.p_a), p_b(it.p_b),
p_step(it.p_step) {}
NumberRange(T a, T b, T step = T(1)): p_a(a), p_b(b),
p_step(step) {}
@ -937,7 +937,7 @@ struct NumberRange: InputRange<NumberRange<T>, ForwardRangeTag, T, T> {
bool empty() const { return p_a * p_step >= p_b * p_step; }
bool equals_front(const NumberRange &range) const {
bool equals_front(NumberRange const &range) const {
return p_a == range.p_a;
}
@ -974,9 +974,9 @@ public:
PointerRange(T *beg, Size n): p_beg(beg), p_end(beg + n) {}
template<typename U, typename = EnableIf<IsConvertible<U *, T *>>>
PointerRange(const PointerRange<U> &v): p_beg(&v[0]), p_end(&v[v.size()]) {}
PointerRange(PointerRange<U> const &v): p_beg(&v[0]), p_end(&v[v.size()]) {}
PointerRange &operator=(const PointerRange &v) {
PointerRange &operator=(PointerRange const &v) {
p_beg = v.p_beg;
p_end = v.p_end;
return *this;
@ -1010,11 +1010,11 @@ public:
T &front() const { return *p_beg; }
bool equals_front(const PointerRange &range) const {
bool equals_front(PointerRange const &range) const {
return p_beg == range.p_beg;
}
Ptrdiff distance_front(const PointerRange &range) const {
Ptrdiff distance_front(PointerRange const &range) const {
return range.p_beg - p_beg;
}
@ -1044,11 +1044,11 @@ public:
T &back() const { return *(p_end - 1); }
bool equals_back(const PointerRange &range) const {
bool equals_back(PointerRange const &range) const {
return p_end == range.p_end;
}
Ptrdiff distance_back(const PointerRange &range) const {
Ptrdiff distance_back(PointerRange const &range) const {
return range.p_end - p_end;
}
@ -1062,7 +1062,7 @@ public:
T &operator[](Size i) const { return p_beg[i]; }
/* satisfy OutputRange */
bool put(const T &v) {
bool put(T const &v) {
if (empty()) return false;
*(p_beg++) = v;
return true;
@ -1073,7 +1073,7 @@ public:
return true;
}
Size put_n(const T *p, Size n) {
Size put_n(T const *p, Size n) {
Size ret = size();
if (n < ret) ret = n;
if (IsPod<T>) {
@ -1104,7 +1104,7 @@ public:
}
T *data() { return p_beg; }
const T *data() const { return p_beg; }
T const *data() const { return p_beg; }
private:
T *p_beg, *p_end;
@ -1116,8 +1116,8 @@ inline PointerRange<T> iter(T (&array)[N]) {
}
template<typename T, Size N>
inline PointerRange<const T> iter(const T (&array)[N]) {
return PointerRange<const T>(array, N);
inline PointerRange<T const> iter(T const (&array)[N]) {
return PointerRange<T const>(array, N);
}
namespace detail {
@ -1158,15 +1158,15 @@ private:
public:
EnumeratedRange() = delete;
EnumeratedRange(const T &range): p_range(range), p_index(0) {}
EnumeratedRange(T const &range): p_range(range), p_index(0) {}
EnumeratedRange(const EnumeratedRange &it):
EnumeratedRange(EnumeratedRange const &it):
p_range(it.p_range), p_index(it.p_index) {}
EnumeratedRange(EnumeratedRange &&it):
p_range(move(it.p_range)), p_index(it.p_index) {}
EnumeratedRange &operator=(const EnumeratedRange &v) {
EnumeratedRange &operator=(EnumeratedRange const &v) {
p_range = v.p_range;
p_index = v.p_index;
return *this;
@ -1176,7 +1176,7 @@ public:
p_index = v.p_index;
return *this;
}
EnumeratedRange &operator=(const T &v) {
EnumeratedRange &operator=(T const &v) {
p_range = v;
p_index = 0;
return *this;
@ -1189,7 +1189,7 @@ public:
bool empty() const { return p_range.empty(); }
bool equals_front(const EnumeratedRange &r) const {
bool equals_front(EnumeratedRange const &r) const {
return p_range.equals_front(r.p_range);
}
@ -1222,14 +1222,14 @@ private:
RangeSize<T> p_remaining;
public:
TakeRange() = delete;
TakeRange(const T &range, RangeSize<T> rem): p_range(range),
TakeRange(T const &range, RangeSize<T> rem): p_range(range),
p_remaining(rem) {}
TakeRange(const TakeRange &it): p_range(it.p_range),
TakeRange(TakeRange const &it): p_range(it.p_range),
p_remaining(it.p_remaining) {}
TakeRange(TakeRange &&it): p_range(move(it.p_range)),
p_remaining(it.p_remaining) {}
TakeRange &operator=(const TakeRange &v) {
TakeRange &operator=(TakeRange const &v) {
p_range = v.p_range; p_remaining = v.p_remaining; return *this;
}
TakeRange &operator=(TakeRange &&v) {
@ -1256,7 +1256,7 @@ public:
RangeReference<T> front() const { return p_range.front(); }
bool equals_front(const TakeRange &r) const {
bool equals_front(TakeRange const &r) const {
return p_range.equals_front(r.p_range);
}
};
@ -1271,14 +1271,14 @@ private:
RangeSize<T> p_chunksize;
public:
ChunksRange() = delete;
ChunksRange(const T &range, RangeSize<T> chs): p_range(range),
ChunksRange(T const &range, RangeSize<T> chs): p_range(range),
p_chunksize(chs) {}
ChunksRange(const ChunksRange &it): p_range(it.p_range),
ChunksRange(ChunksRange const &it): p_range(it.p_range),
p_chunksize(it.p_chunksize) {}
ChunksRange(ChunksRange &&it): p_range(move(it.p_range)),
p_chunksize(it.p_chunksize) {}
ChunksRange &operator=(const ChunksRange &v) {
ChunksRange &operator=(ChunksRange const &v) {
p_range = v.p_range; p_chunksize = v.p_chunksize; return *this;
}
ChunksRange &operator=(ChunksRange &&v) {
@ -1289,7 +1289,7 @@ public:
bool empty() const { return p_range.empty(); }
bool equals_front(const ChunksRange &r) const {
bool equals_front(ChunksRange const &r) const {
return p_range.equals_front(r.p_range);
}
@ -1305,7 +1305,7 @@ namespace detail {
template<Size I, Size N>
struct JoinRangeEmpty {
template<typename T>
static bool empty(const T &tup) {
static bool empty(T const &tup) {
if (!ostd::get<I>(tup).empty())
return false;
return JoinRangeEmpty<I + 1, N>::empty(tup);
@ -1315,7 +1315,7 @@ namespace detail {
template<Size N>
struct JoinRangeEmpty<N, N> {
template<typename T>
static bool empty(const T &) {
static bool empty(T const &) {
return true;
}
};
@ -1323,7 +1323,7 @@ namespace detail {
template<Size I, Size N>
struct TupleRangeEqual {
template<typename T>
static bool equal(const T &tup1, const T &tup2) {
static bool equal(T const &tup1, T const &tup2) {
if (!ostd::get<I>(tup1).equals_front(ostd::get<I>(tup2)))
return false;
return TupleRangeEqual<I + 1, N>::equal(tup1, tup2);
@ -1333,7 +1333,7 @@ namespace detail {
template<Size N>
struct TupleRangeEqual<N, N> {
template<typename T>
static bool equal(const T &, const T &) {
static bool equal(T const &, T const &) {
return true;
}
};
@ -1360,7 +1360,7 @@ namespace detail {
template<Size I, Size N, typename T>
struct JoinRangeFront {
template<typename U>
static T front(const U &tup) {
static T front(U const &tup) {
if (!ostd::get<I>(tup).empty()) {
return ostd::get<I>(tup).front();
}
@ -1371,7 +1371,7 @@ namespace detail {
template<Size N, typename T>
struct JoinRangeFront<N, N, T> {
template<typename U>
static T front(const U &tup) {
static T front(U const &tup) {
return ostd::get<0>(tup).front();
}
};
@ -1386,12 +1386,12 @@ private:
Tuple<R...> p_ranges;
public:
JoinRange() = delete;
JoinRange(const R &...ranges): p_ranges(ranges...) {}
JoinRange(R const &...ranges): p_ranges(ranges...) {}
JoinRange(R &&...ranges): p_ranges(forward<R>(ranges)...) {}
JoinRange(const JoinRange &v): p_ranges(v.p_ranges) {}
JoinRange(JoinRange const &v): p_ranges(v.p_ranges) {}
JoinRange(JoinRange &&v): p_ranges(move(v.p_ranges)) {}
JoinRange &operator=(const JoinRange &v) {
JoinRange &operator=(JoinRange const &v) {
p_ranges = v.p_ranges;
return *this;
}
@ -1405,7 +1405,7 @@ public:
return detail::JoinRangeEmpty<0, sizeof...(R)>::empty(p_ranges);
}
bool equals_front(const JoinRange &r) const {
bool equals_front(JoinRange const &r) const {
return detail::TupleRangeEqual<0, sizeof...(R)>::equal(p_ranges,
r.p_ranges);
}
@ -1437,7 +1437,7 @@ namespace detail {
template<Size I, Size N>
struct ZipRangeEmpty {
template<typename T>
static bool empty(const T &tup) {
static bool empty(T const &tup) {
if (ostd::get<I>(tup).empty())
return true;
return ZipRangeEmpty<I + 1, N>::empty(tup);
@ -1447,7 +1447,7 @@ namespace detail {
template<Size N>
struct ZipRangeEmpty<N, N> {
template<typename T>
static bool empty(const T &) {
static bool empty(T const &) {
return false;
}
};
@ -1472,12 +1472,12 @@ namespace detail {
template<typename ...T>
struct ZipRangeFront {
template<typename U, Size ...I>
static ZipValue<T...> tup_get(const U &tup, detail::TupleIndices<I...>) {
static ZipValue<T...> tup_get(U const &tup, detail::TupleIndices<I...>) {
return ZipValue<T...>(ostd::get<I>(tup).front()...);
}
template<typename U>
static ZipValue<T...> front(const U &tup) {
static ZipValue<T...> front(U const &tup) {
using Index = detail::MakeTupleIndices<sizeof...(T)>;
return ZipRangeFront<T...>::tup_get(tup, Index());
}
@ -1494,12 +1494,12 @@ private:
Tuple<R...> p_ranges;
public:
ZipRange() = delete;
ZipRange(const R &...ranges): p_ranges(ranges...) {}
ZipRange(R const &...ranges): p_ranges(ranges...) {}
ZipRange(R &&...ranges): p_ranges(forward<R>(ranges)...) {}
ZipRange(const ZipRange &v): p_ranges(v.p_ranges) {}
ZipRange(ZipRange const &v): p_ranges(v.p_ranges) {}
ZipRange(ZipRange &&v): p_ranges(move(v.p_ranges)) {}
ZipRange &operator=(const ZipRange &v) {
ZipRange &operator=(ZipRange const &v) {
p_ranges = v.p_ranges;
return *this;
}
@ -1513,7 +1513,7 @@ public:
return detail::ZipRangeEmpty<0, sizeof...(R)>::empty(p_ranges);
}
bool equals_front(const ZipRange &r) const {
bool equals_front(ZipRange const &r) const {
return detail::TupleRangeEqual<0, sizeof...(R)>::equal(p_ranges,
r.p_ranges);
}
@ -1531,12 +1531,12 @@ template<typename T>
struct AppenderRange: OutputRange<AppenderRange<T>, typename T::Value,
typename T::Reference, typename T::Size, typename T::Difference> {
AppenderRange(): p_data() {}
AppenderRange(const T &v): p_data(v) {}
AppenderRange(T const &v): p_data(v) {}
AppenderRange(T &&v): p_data(move(v)) {}
AppenderRange(const AppenderRange &v): p_data(v.p_data) {}
AppenderRange(AppenderRange const &v): p_data(v.p_data) {}
AppenderRange(AppenderRange &&v): p_data(move(v.p_data)) {}
AppenderRange &operator=(const AppenderRange &v) {
AppenderRange &operator=(AppenderRange const &v) {
p_data = v.p_data;
return *this;
}
@ -1546,7 +1546,7 @@ struct AppenderRange: OutputRange<AppenderRange<T>, typename T::Value,
return *this;
}
AppenderRange &operator=(const T &v) {
AppenderRange &operator=(T const &v) {
p_data = v;
return *this;
}

View File

@ -18,14 +18,14 @@ namespace ostd {
namespace detail {
template<typename T, typename A> struct SetBase {
static inline const T &get_key(const T &e) {
static inline T const &get_key(T const &e) {
return e;
}
static inline T &get_data(T &e) {
return e;
}
template<typename U>
static inline void set_key(T &, const U &, A &) {}
static inline void set_key(T &, U const &, A &) {}
static inline void swap_elem(T &a, T &b) { swap_adl(a, b); }
};
@ -49,35 +49,35 @@ namespace detail {
using Pointer = AllocatorPointer<A>;
using ConstPointer = AllocatorConstPointer<A>;
using Range = HashRange<T>;
using ConstRange = HashRange<const T>;
using ConstRange = HashRange<T const>;
using LocalRange = BucketRange<T>;
using ConstLocalRange = BucketRange<const T>;
using ConstLocalRange = BucketRange<T const>;
using Allocator = A;
explicit SetImpl(Size size, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
explicit SetImpl(Size size, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size, hf, eqf, alloc) {}
SetImpl(): SetImpl(0) {}
explicit SetImpl(const A &alloc): SetImpl(0, H(), C(), alloc) {}
explicit SetImpl(A const &alloc): SetImpl(0, H(), C(), alloc) {}
SetImpl(Size size, const A &alloc):
SetImpl(Size size, A const &alloc):
SetImpl(size, H(), C(), alloc) {}
SetImpl(Size size, const H &hf, const A &alloc):
SetImpl(Size size, H const &hf, A const &alloc):
SetImpl(size, hf, C(), alloc) {}
SetImpl(const SetImpl &m): Base(m,
SetImpl(SetImpl const &m): Base(m,
allocator_container_copy(m.get_alloc())) {}
SetImpl(const SetImpl &m, const A &alloc): Base(m, alloc) {}
SetImpl(SetImpl const &m, A const &alloc): Base(m, alloc) {}
SetImpl(SetImpl &&m): Base(move(m)) {}
SetImpl(SetImpl &&m, const A &alloc): Base(move(m), alloc) {}
SetImpl(SetImpl &&m, A const &alloc): Base(move(m), alloc) {}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> SetImpl(R range, Size size = 0, const H &hf = H(),
const C &eqf = C(), const A &alloc = A()
>> SetImpl(R range, Size size = 0, H const &hf = H(),
C const &eqf = C(), A const &alloc = A()
): Base(size ? size : detail::estimate_hrsize(range),
hf, eqf, alloc) {
for (; !range.empty(); range.pop_front())
@ -86,25 +86,25 @@ namespace detail {
}
template<typename R>
SetImpl(R range, Size size, const A &alloc)
SetImpl(R range, Size size, A const &alloc)
: SetImpl(range, size, H(), C(), alloc) {}
template<typename R>
SetImpl(R range, Size size, const H &hf, const A &alloc)
SetImpl(R range, Size size, H const &hf, A const &alloc)
: SetImpl(range, size, hf, C(), alloc) {}
SetImpl(InitializerList<Value> init, Size size = 0,
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
H const &hf = H(), C const &eqf = C(), A const &alloc = A()
): SetImpl(iter(init), size, hf, eqf, alloc) {}
SetImpl(InitializerList<Value> init, Size size, const A &alloc)
SetImpl(InitializerList<Value> init, Size size, A const &alloc)
: SetImpl(iter(init), size, H(), C(), alloc) {}
SetImpl(InitializerList<Value> init, Size size, const H &hf,
const A &alloc
SetImpl(InitializerList<Value> init, Size size, H const &hf,
A const &alloc
): SetImpl(iter(init), size, hf, C(), alloc) {}
SetImpl &operator=(const SetImpl &m) {
SetImpl &operator=(SetImpl const &m) {
Base::operator=(m);
return *this;
}

View File

@ -37,7 +37,7 @@ namespace detail {
template<Size N>
struct FormatOutRange: OutputRange<FormatOutRange<N>, char> {
FormatOutRange(char *ibuf): buf(ibuf), idx(0) {}
FormatOutRange(const FormatOutRange &r): buf(r.buf), idx(r.idx) {}
FormatOutRange(FormatOutRange const &r): buf(r.buf), idx(r.idx) {}
char *buf;
Size idx;
bool put(char v) {
@ -68,8 +68,8 @@ private:
}
template<typename T>
inline bool write_impl(const T &v, EnableIf<
!IsConstructible<ConstCharRange, const T &>, StNat
inline bool write_impl(T const &v, EnableIf<
!IsConstructible<ConstCharRange, T const &>, StNat
> = StNat()) {
return write(ostd::to_string(v));
}
@ -99,7 +99,7 @@ public:
virtual bool flush() { return true; }
virtual Size read_bytes(void *, Size) { return 0; }
virtual Size write_bytes(const void *, Size) { return 0; }
virtual Size write_bytes(void const *, Size) { return 0; }
virtual int getchar() {
byte c;
@ -112,27 +112,27 @@ public:
}
template<typename T>
bool write(const T &v) {
bool write(T const &v) {
return write_impl(v);
}
template<typename T, typename ...A>
bool write(const T &v, const A &...args) {
bool write(T const &v, A const &...args) {
return write(v) && write(args...);
}
template<typename T>
bool writeln(const T &v) {
bool writeln(T const &v) {
return write(v) && putchar('\n');
}
template<typename T, typename ...A>
bool writeln(const T &v, const A &...args) {
bool writeln(T const &v, A const &...args) {
return write(v) && write(args...) && putchar('\n');
}
template<typename ...A>
bool writef(ConstCharRange fmt, const A &...args) {
bool writef(ConstCharRange fmt, A const &...args) {
char buf[512];
Ptrdiff need = format(detail::FormatOutRange<sizeof(buf)>(buf),
fmt, args...);
@ -147,14 +147,14 @@ public:
}
template<typename ...A>
bool writefln(ConstCharRange fmt, const A &...args) {
bool writefln(ConstCharRange fmt, A const &...args) {
return writef(fmt, args...) && putchar('\n');
}
template<typename T = char>
StreamRange<T> iter();
template<typename T> Size put(const T *v, Size count) {
template<typename T> Size put(T const *v, Size count) {
return write_bytes(v, count * sizeof(T)) / sizeof(T);
}
@ -182,7 +182,7 @@ struct StreamRange<T, true>: InputRange<
> {
StreamRange() = delete;
StreamRange(Stream &s): p_stream(&s), p_size(s.size()) {}
StreamRange(const StreamRange &r): p_stream(r.p_stream), p_size(r.p_size) {}
StreamRange(StreamRange const &r): p_stream(r.p_stream), p_size(r.p_size) {}
bool empty() const {
return (p_size - p_stream->tell()) < StreamOffset(sizeof(T));
@ -200,7 +200,7 @@ struct StreamRange<T, true>: InputRange<
return val;
}
bool equals_front(const StreamRange &s) const {
bool equals_front(StreamRange const &s) const {
return p_stream->tell() == s.p_stream->tell();
}
@ -210,7 +210,7 @@ struct StreamRange<T, true>: InputRange<
return (v == sizeof(T));
}
Size put_n(const T *p, Size n) {
Size put_n(T const *p, Size n) {
return p_stream->put(p, n);
}

View File

@ -49,21 +49,21 @@ public:
p_beg(beg), p_end(beg + N - (beg[N - 1] == '\0')) {}
template<typename U, typename A>
CharRangeBase(const StringBase<U, A> &s, EnableIf<
CharRangeBase(StringBase<U, A> const &s, EnableIf<
IsConvertible<U *, T *>, Nat
> = Nat()): p_beg(s.data()),
p_end(s.data() + s.size()) {}
template<typename U, typename = EnableIf<IsConvertible<U *, T *>>>
CharRangeBase(const CharRangeBase<U> &v):
CharRangeBase(CharRangeBase<U> const &v):
p_beg(&v[0]), p_end(&v[v.size()]) {}
CharRangeBase &operator=(const CharRangeBase &v) {
CharRangeBase &operator=(CharRangeBase const &v) {
p_beg = v.p_beg; p_end = v.p_end; return *this;
}
template<typename A>
CharRangeBase &operator=(const StringBase<T, A> &s) {
CharRangeBase &operator=(StringBase<T, A> const &s) {
p_beg = s.data(); p_end = s.data() + s.size(); return *this;
}
/* TODO: traits for utf-16/utf-32 string lengths, for now assume char */
@ -94,11 +94,11 @@ public:
T &front() const { return *p_beg; }
bool equals_front(const CharRangeBase &range) const {
bool equals_front(CharRangeBase const &range) const {
return p_beg == range.p_beg;
}
Ptrdiff distance_front(const CharRangeBase &range) const {
Ptrdiff distance_front(CharRangeBase const &range) const {
return range.p_beg - p_beg;
}
@ -123,11 +123,11 @@ public:
T &back() const { return *(p_end - 1); }
bool equals_back(const CharRangeBase &range) const {
bool equals_back(CharRangeBase const &range) const {
return p_end == range.p_end;
}
Ptrdiff distance_back(const CharRangeBase &range) const {
Ptrdiff distance_back(CharRangeBase const &range) const {
return range.p_end - p_end;
}
@ -145,7 +145,7 @@ public:
return true;
}
Size put_n(const T *p, Size n) {
Size put_n(T const *p, Size n) {
Size an = ostd::min(n, size());
memcpy(p_beg, p, an * sizeof(T));
p_beg += an;
@ -153,14 +153,14 @@ public:
}
T *data() { return p_beg; }
const T *data() const { return p_beg; }
T const *data() const { return p_beg; }
Size to_hash() const {
return detail::mem_hash(data(), size());
}
/* non-range */
int compare(CharRangeBase<const T> s) const {
int compare(CharRangeBase<T const> s) const {
int ret = memcmp(data(), s.data(), ostd::min(size(), s.size()));
return ret ? ret : (size() - s.size());
}
@ -181,7 +181,7 @@ private:
};
using CharRange = CharRangeBase<char>;
using ConstCharRange = CharRangeBase<const char>;
using ConstCharRange = CharRangeBase<char const>;
inline bool operator==(ConstCharRange lhs, ConstCharRange rhs) {
return !lhs.compare(rhs);
@ -254,17 +254,17 @@ public:
using Difference = Ptrdiff;
using Value = T;
using Reference = T &;
using ConstReference = const T &;
using ConstReference = T const &;
using Pointer = AllocatorPointer<A>;
using ConstPointer = AllocatorConstPointer<A>;
using Range = CharRangeBase<T>;
using ConstRange = CharRangeBase<const T>;
using ConstRange = CharRangeBase<T const>;
using Allocator = A;
StringBase(const A &a = A()): p_len(0), p_cap(0),
StringBase(A const &a = A()): p_len(0), p_cap(0),
p_buf((Pointer)&p_len, a) {}
explicit StringBase(Size n, T val = T(), const A &al = A()):
explicit StringBase(Size n, T val = T(), A const &al = A()):
StringBase(al) {
if (!n) return;
p_buf.first() = allocator_allocate(p_buf.second(), n + 1);
@ -274,14 +274,14 @@ public:
*cur = '\0';
}
StringBase(const StringBase &s): p_len(0), p_cap(0),
StringBase(StringBase const &s): p_len(0), p_cap(0),
p_buf((Pointer)&p_len, allocator_container_copy(s.p_buf.second())) {
if (!s.p_len) return;
reserve(s.p_len);
p_len = s.p_len;
memcpy(p_buf.first(), s.p_buf.first(), (p_len + 1) * sizeof(T));
}
StringBase(const StringBase &s, const A &a): p_len(0), p_cap(0),
StringBase(StringBase const &s, A const &a): p_len(0), p_cap(0),
p_buf((Pointer)&p_len, a) {
if (!s.p_len) return;
reserve(s.p_len);
@ -293,7 +293,7 @@ public:
s.p_len = s.p_cap = 0;
s.p_buf.first() = (Pointer)&s.p_len;
}
StringBase(StringBase &&s, const A &a): p_len(0), p_cap(0),
StringBase(StringBase &&s, A const &a): p_len(0), p_cap(0),
p_buf((Pointer)&p_len, a) {
if (!s.p_len) return;
if (a != s.p_buf.second()) {
@ -309,8 +309,8 @@ public:
s.p_buf.first() = &s.p_cap;
}
StringBase(const StringBase &s, Size pos, Size len = npos,
const A &a = A()): StringBase(a) {
StringBase(StringBase const &s, Size pos, Size len = npos,
A const &a = A()): StringBase(a) {
Size end = (len == npos) ? s.size() : (pos + len);
Size nch = (end - pos);
reserve(nch);
@ -320,7 +320,7 @@ public:
}
/* TODO: traits for utf-16/utf-32 string lengths, for now assume char */
StringBase(ConstRange v, const A &a = A()): StringBase(a) {
StringBase(ConstRange v, A const &a = A()): StringBase(a) {
if (!v.size()) return;
reserve(v.size());
memcpy(p_buf.first(), &v[0], v.size());
@ -329,18 +329,18 @@ public:
}
template<typename U>
StringBase(U v, const EnableIf<
IsConvertible<U, const Value *> && !IsArray<U>, A
> &a = A()): StringBase(ConstRange(v), a) {}
StringBase(U v, EnableIf<
IsConvertible<U, Value const *> && !IsArray<U>, A
> const &a = A()): StringBase(ConstRange(v), a) {}
template<typename U, Size N>
StringBase(U (&v)[N], const EnableIf<
IsConvertible<U *, const Value *>, A
> &a = A()): StringBase(ConstRange(v), a) {}
StringBase(U (&v)[N], EnableIf<
IsConvertible<U *, Value const *>, A
> const &a = A()): StringBase(ConstRange(v), a) {}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> StringBase(R range, const A &a = A()): StringBase(a) {
>> StringBase(R range, A const &a = A()): StringBase(a) {
ctor_from_range(range);
}
@ -355,7 +355,7 @@ public:
*p_buf.first() = '\0';
}
StringBase &operator=(const StringBase &v) {
StringBase &operator=(StringBase const &v) {
if (this == &v) return *this;
clear();
if (AllocatorPropagateOnContainerCopyAssignment<A>) {
@ -397,20 +397,20 @@ public:
}
template<typename U>
EnableIf<IsConvertible<U, const Value *> && !IsArray<U>, StringBase &>
EnableIf<IsConvertible<U, Value const *> && !IsArray<U>, StringBase &>
operator=(U v) {
return operator=(ConstRange(v));
}
template<typename U, Size N>
EnableIf<IsConvertible<U *, const Value *>, StringBase &>
EnableIf<IsConvertible<U *, Value const *>, StringBase &>
operator=(U (&v)[N]) {
return operator=(ConstRange(v));
}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> StringBase &operator=(const R &r) {
>> StringBase &operator=(R const &r) {
clear();
ctor_from_range(r);
return *this;
@ -448,19 +448,19 @@ public:
}
T &operator[](Size i) { return p_buf.first()[i]; }
const T &operator[](Size i) const { return p_buf.first()[i]; }
T const &operator[](Size i) const { return p_buf.first()[i]; }
T &at(Size i) { return p_buf.first()[i]; }
const T &at(Size i) const { return p_buf.first()[i]; }
T const &at(Size i) const { return p_buf.first()[i]; }
T &front() { return p_buf.first()[0]; }
const T &front() const { return p_buf.first()[0]; };
T const &front() const { return p_buf.first()[0]; };
T &back() { return p_buf.first()[size() - 1]; }
const T &back() const { return p_buf.first()[size() - 1]; }
T const &back() const { return p_buf.first()[size() - 1]; }
Value *data() { return p_buf.first(); }
const Value *data() const { return p_buf.first(); }
Value const *data() const { return p_buf.first(); }
Size size() const {
return p_len;
@ -531,7 +531,7 @@ public:
return append(1, c);
}
template<typename R>
StringBase &operator+=(const R &v) {
StringBase &operator+=(R const &v) {
return append(v);
}
@ -575,11 +575,11 @@ using String = StringBase<char>;
/* string literals */
inline namespace literals { inline namespace string_literals {
inline String operator "" _s(const char *str, Size len) {
inline String operator "" _s(char const *str, Size len) {
return String(ConstCharRange(str, len));
}
inline ConstCharRange operator "" _S(const char *str, Size len) {
inline ConstCharRange operator "" _S(char const *str, Size len) {
return ConstCharRange(str, len);
}
} }
@ -607,7 +607,7 @@ namespace detail {
}
template<typename R, typename T, typename F>
bool concat(R &&sink, const T &v, ConstCharRange sep, F func) {
bool concat(R &&sink, T const &v, ConstCharRange sep, F func) {
auto range = ostd::iter(v);
if (range.empty()) return true;
for (;;) {
@ -623,7 +623,7 @@ bool concat(R &&sink, const T &v, ConstCharRange sep, F func) {
}
template<typename R, typename T>
bool concat(R &&sink, const T &v, ConstCharRange sep = " ") {
bool concat(R &&sink, T const &v, ConstCharRange sep = " ") {
auto range = ostd::iter(v);
if (range.empty()) return true;
for (;;) {
@ -657,7 +657,7 @@ namespace detail {
p_written += ret;
return ret;
}
Size put_n(const char *v, Size n) {
Size put_n(char const *v, Size n) {
Size ret = p_out.put_n(v, n);
p_written += ret;
return ret;
@ -676,7 +676,7 @@ namespace detail {
BoolConstant<IsSame<decltype(declval<T>().stringify()), String>>;
template<typename T, typename R>
static True test_stringify(decltype(declval<const T &>().to_string
static True test_stringify(decltype(declval<T const &>().to_string
(declval<R &>())) *);
template<typename, typename>
@ -701,7 +701,7 @@ struct ToString<T, EnableIf<detail::IterableTest<T>>> {
using Argument = RemoveCv<RemoveReference<T>>;
using Result = String;
String operator()(const T &v) const {
String operator()(T const &v) const {
String ret("{");
auto x = appender<String>();
if (concat(x, ostd::iter(v), ", ", ToString<
@ -721,7 +721,7 @@ struct ToString<T, EnableIf<
using Argument = RemoveCv<RemoveReference<T>>;
using Result = String;
String operator()(const T &v) const {
String operator()(T const &v) const {
auto app = appender<String>();
detail::TostrRange<AppenderRange<String>> sink(app);
if (!v.to_string(sink)) return String();
@ -731,7 +731,7 @@ struct ToString<T, EnableIf<
namespace detail {
template<typename T>
void str_printf(String &s, const char *fmt, T v) {
void str_printf(String &s, char const *fmt, T v) {
char buf[256];
int n = snprintf(buf, sizeof(buf), fmt, v);
s.clear();
@ -802,10 +802,10 @@ template<typename T> struct ToString<T *> {
}
};
template<> struct ToString<const char *> {
using Argument = const char *;
template<> struct ToString<char const *> {
using Argument = char const *;
using Result = String;
String operator()(const char *s) {
String operator()(char const *s) {
return String(s);
}
};
@ -821,7 +821,7 @@ template<> struct ToString<char *> {
template<> struct ToString<String> {
using Argument = String;
using Result = String;
String operator()(const Argument &s) {
String operator()(Argument const &s) {
return s;
}
};
@ -829,7 +829,7 @@ template<> struct ToString<String> {
template<> struct ToString<CharRange> {
using Argument = CharRange;
using Result = String;
String operator()(const Argument &s) {
String operator()(Argument const &s) {
return String(s);
}
};
@ -837,7 +837,7 @@ template<> struct ToString<CharRange> {
template<> struct ToString<ConstCharRange> {
using Argument = ConstCharRange;
using Result = String;
String operator()(const Argument &s) {
String operator()(Argument const &s) {
return String(s);
}
};
@ -845,7 +845,7 @@ template<> struct ToString<ConstCharRange> {
template<typename T, typename U> struct ToString<Pair<T, U>> {
using Argument = Pair<T, U>;
using Result = String;
String operator()(const Argument &v) {
String operator()(Argument const &v) {
String ret("{");
ret += ToString<RemoveCv<RemoveReference<T>>>()(v.first);
ret += ", ";
@ -859,7 +859,7 @@ namespace detail {
template<Size I, Size N>
struct TupleToString {
template<typename T>
static void append(String &ret, const T &tup) {
static void append(String &ret, T const &tup) {
ret += ", ";
ret += ToString<RemoveCv<RemoveReference<
decltype(ostd::get<I>(tup))>>>()(ostd::get<I>(tup));
@ -870,13 +870,13 @@ namespace detail {
template<Size N>
struct TupleToString<N, N> {
template<typename T>
static void append(String &, const T &) {}
static void append(String &, T const &) {}
};
template<Size N>
struct TupleToString<0, N> {
template<typename T>
static void append(String &ret, const T &tup) {
static void append(String &ret, T const &tup) {
ret += ToString<RemoveCv<RemoveReference<
decltype(ostd::get<0>(tup))>>>()(ostd::get<0>(tup));
TupleToString<1, N>::append(ret, tup);
@ -887,7 +887,7 @@ namespace detail {
template<typename ...T> struct ToString<Tuple<T...>> {
using Argument = Tuple<T...>;
using Result = String;
String operator()(const Argument &v) {
String operator()(Argument const &v) {
String ret("{");
detail::TupleToString<0, sizeof...(T)>::append(ret, v);
ret += "}";
@ -896,7 +896,7 @@ template<typename ...T> struct ToString<Tuple<T...>> {
};
template<typename T>
typename ToString<T>::Result to_string(const T &v) {
typename ToString<T>::Result to_string(T const &v) {
return ToString<RemoveCv<RemoveReference<T>>>()(v);
}
@ -907,19 +907,19 @@ String to_string(std::initializer_list<T> init) {
/* TODO: rvalue ref versions for rhs when we have efficient prepend */
inline String operator+(const String &lhs, ConstCharRange rhs) {
inline String operator+(String const &lhs, ConstCharRange rhs) {
String ret(lhs); ret += rhs; return ret;
}
inline String operator+(ConstCharRange lhs, const String &rhs) {
inline String operator+(ConstCharRange lhs, String const &rhs) {
String ret(lhs); ret += rhs; return ret;
}
inline String operator+(const String &lhs, char rhs) {
inline String operator+(String const &lhs, char rhs) {
String ret(lhs); ret += rhs; return ret;
}
inline String operator+(char lhs, const String &rhs) {
inline String operator+(char lhs, String const &rhs) {
String ret(lhs); ret += rhs; return ret;
}
@ -939,7 +939,7 @@ private:
public:
TempCString() = delete;
TempCString(const TempCString &) = delete;
TempCString(TempCString const &) = delete;
TempCString(TempCString &&s): p_buf(s.p_buf), p_allocated(s.p_allocated) {
s.p_buf = nullptr;
s.p_allocated = false;
@ -957,14 +957,14 @@ public:
if (p_allocated) delete[] p_buf;
}
TempCString &operator=(const TempCString &) = delete;
TempCString &operator=(TempCString const &) = delete;
TempCString &operator=(TempCString &&s) {
swap(s);
return *this;
}
operator const RemoveCv<RangeValue<R>> *() const { return p_buf; }
const RemoveCv<RangeValue<R>> *get() const { return p_buf; }
operator RemoveCv<RangeValue<R>> const *() const { return p_buf; }
RemoveCv<RangeValue<R>> const *get() const { return p_buf; }
void swap(TempCString &s) {
detail::swap_adl(p_buf, s.p_buf);

View File

@ -37,17 +37,17 @@ namespace detail {
}
template<typename A>
TupleLeaf(Constant<int, 0>, const A &): p_value() {
TupleLeaf(Constant<int, 0>, A const &): p_value() {
static_assert(!IsReference<H>,
"attempt to default construct a reference element in a tuple");
}
template<typename A>
TupleLeaf(Constant<int, 1>, const A &a): p_value(allocator_arg, a) {
TupleLeaf(Constant<int, 1>, A const &a): p_value(allocator_arg, a) {
static_assert(!IsReference<H>,
"attempt to default construct a reference element in a tuple");
}
template<typename A>
TupleLeaf(Constant<int, 2>, const A &a): p_value(a) {
TupleLeaf(Constant<int, 2>, A const &a): p_value(a) {
static_assert(!IsReference<H>,
"attempt to default construct a reference element in a tuple");
}
@ -67,7 +67,7 @@ namespace detail {
}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 0>, const A &, T &&t):
explicit TupleLeaf(Constant<int, 0>, A const &, T &&t):
p_value(forward<T>(t)) {
static_assert(!IsLvalueReference<H> ||
(IsLvalueReference<H> &&
@ -78,7 +78,7 @@ namespace detail {
}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 1>, const A &a, T &&t):
explicit TupleLeaf(Constant<int, 1>, A const &a, T &&t):
p_value(allocator_arg, a, forward<T>(t)) {
static_assert(!IsLvalueReference<H> ||
(IsLvalueReference<H> &&
@ -89,7 +89,7 @@ namespace detail {
}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 2>, const A &a, T &&t):
explicit TupleLeaf(Constant<int, 2>, A const &a, T &&t):
p_value(forward<T>(t), a) {
static_assert(!IsLvalueReference<H> ||
(IsLvalueReference<H> &&
@ -99,7 +99,7 @@ namespace detail {
"attempt to construct a reference element in a tuple with an rvalue");
}
TupleLeaf(const TupleLeaf &) = default;
TupleLeaf(TupleLeaf const &) = default;
TupleLeaf(TupleLeaf &&) = default;
template<typename T>
@ -113,10 +113,10 @@ namespace detail {
}
H &get() { return p_value; }
const H &get() const { return p_value; }
H const &get() const { return p_value; }
private:
TupleLeaf &operator=(const TupleLeaf &);
TupleLeaf &operator=(TupleLeaf const &);
H p_value;
};
@ -125,32 +125,32 @@ namespace detail {
constexpr TupleLeaf() {}
template<typename A>
TupleLeaf(Constant<int, 0>, const A &) {}
TupleLeaf(Constant<int, 0>, A const &) {}
template<typename A>
TupleLeaf(Constant<int, 1>, const A &a):
TupleLeaf(Constant<int, 1>, A const &a):
H(allocator_arg, a) {}
template<typename A>
TupleLeaf(Constant<int, 2>, const A &a): H(a) {}
TupleLeaf(Constant<int, 2>, A const &a): H(a) {}
template<typename T, typename = EnableIf<
!IsSame<Decay<T>, TupleLeaf> && IsConstructible<H, T>
>> explicit TupleLeaf(T &&t): H(forward<T>(t)) {}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 0>, const A &, T &&t):
explicit TupleLeaf(Constant<int, 0>, A const &, T &&t):
H(forward<T>(t)) {}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 1>, const A &a, T &&t):
explicit TupleLeaf(Constant<int, 1>, A const &a, T &&t):
H(allocator_arg, a, forward<T>(t)) {}
template<typename T, typename A>
explicit TupleLeaf(Constant<int, 2>, const A &a, T &&t):
explicit TupleLeaf(Constant<int, 2>, A const &a, T &&t):
H(forward<T>(t), a) {}
TupleLeaf(const TupleLeaf &) = default;
TupleLeaf(TupleLeaf const &) = default;
TupleLeaf(TupleLeaf &&) = default;
template<typename T>
@ -164,10 +164,10 @@ namespace detail {
}
H &get() { return (H &)*this; }
const H &get() const { return (const H &)*this; }
H const &get() const { return (H const &)*this; }
private:
TupleLeaf &operator=(const TupleLeaf &);
TupleLeaf &operator=(TupleLeaf const &);
};
} /* namespace detail */
@ -210,7 +210,7 @@ namespace detail {
template<typename Alloc, Size ...Ia, typename ...Aa,
Size ...Ib, typename ...Ab, typename ...T>
explicit TupleBase(AllocatorArg, const Alloc &a,
explicit TupleBase(AllocatorArg, Alloc const &a,
TupleIndices<Ia...>, TupleTypes<Aa...>,
TupleIndices<Ib...>, TupleTypes<Ab...>,
T &&...t):
@ -227,7 +227,7 @@ namespace detail {
template<typename Alloc, typename T, typename = EnableIf<
TupleConvertible<T, Tuple<A...>>
>> TupleBase(AllocatorArg, const Alloc &a, T &&t):
>> TupleBase(AllocatorArg, Alloc const &a, T &&t):
TupleLeaf<I, A>(UsesAllocatorConstructor<
A, Alloc, TupleElement<I, MakeTupleTypes<T>>
>, a, forward<TupleElement<I, MakeTupleTypes<T>>>(get<I>(t)))...
@ -242,18 +242,18 @@ namespace detail {
return *this;
}
TupleBase(const TupleBase &) = default;
TupleBase(TupleBase const &) = default;
TupleBase(TupleBase &&) = default;
TupleBase &operator=(const TupleBase &t) {
tuple_swallow(TupleLeaf<I, A>::operator=(((const TupleLeaf<I,
A> &)t).get())...);
TupleBase &operator=(TupleBase const &t) {
tuple_swallow(TupleLeaf<I, A>::operator=(((TupleLeaf<I,A>
const &)t).get())...);
return *this;
}
TupleBase &operator=(TupleBase &&t) {
tuple_swallow(TupleLeaf<I, A>::operator=(forward<A>
(((const TupleLeaf<I, A> &)t).get()))...);
(((TupleLeaf<I, A> const &)t).get()))...);
return *this;
}
@ -272,27 +272,27 @@ class Tuple {
friend TupleElement<I, Tuple<T...>> &get(Tuple<T...> &);
template<Size I, typename ...T>
friend const TupleElement<I, Tuple<T...>> &get(const Tuple<T...> &);
friend TupleElement<I, Tuple<T...>> const &get(Tuple<T...> const &);
template<Size I, typename ...T>
friend TupleElement<I, Tuple<T...>> &&get(Tuple<T...> &&);
template<Size I, typename ...T>
friend const TupleElement<I, Tuple<T...>> &&get(const Tuple<T...> &&);
friend TupleElement<I, Tuple<T...>> const &&get(Tuple<T...> const &&);
public:
template<bool D = true, typename = EnableIf<
detail::TupleAll<(D && IsDefaultConstructible<A>)...>
>> Tuple() {}
explicit Tuple(const A &...t):
explicit Tuple(A const &...t):
p_base(detail::MakeTupleIndices<sizeof...(A)>(),
detail::MakeTupleTypes<Tuple, sizeof...(A)>(),
detail::MakeTupleIndices<0>(),
detail::MakeTupleTypes<Tuple, 0>(), t...) {}
template<typename Alloc>
Tuple(AllocatorArg, const Alloc &a, const A &...t):
Tuple(AllocatorArg, Alloc const &a, A const &...t):
p_base(allocator_arg, a,
detail::MakeTupleIndices<sizeof...(A)>(),
detail::MakeTupleTypes<Tuple, sizeof...(A)>(),
@ -367,7 +367,7 @@ public:
: sizeof...(A)
>
>
>> Tuple(AllocatorArg, const Alloc &a, T &&...t):
>> Tuple(AllocatorArg, Alloc const &a, T &&...t):
p_base(allocator_arg, a, detail::MakeTupleIndices<sizeof...(T)>(),
detail::MakeTupleTypes<Tuple, sizeof...(T)>(),
detail::MakeTupleIndices<sizeof...(A), sizeof...(T)>(),
@ -385,7 +385,7 @@ public:
template<typename Alloc, typename T, typename = EnableIf<
detail::TupleConvertible<T, Tuple>
>> Tuple(AllocatorArg, const Alloc &a, T &&t):
>> Tuple(AllocatorArg, Alloc const &a, T &&t):
p_base(allocator_arg, a, forward<T>(t)) {}
template<typename T, typename = EnableIf<detail::TupleAssignable<T, Tuple>>>
@ -402,8 +402,8 @@ public:
template<> class Tuple<> {
public:
constexpr Tuple() {}
template<typename A> Tuple(AllocatorArg, const A &) {}
template<typename A> Tuple(AllocatorArg, const A &, const Tuple &) {}
template<typename A> Tuple(AllocatorArg, A const &) {}
template<typename A> Tuple(AllocatorArg, A const &, Tuple const &) {}
void swap(Tuple &) {}
};
@ -416,9 +416,9 @@ inline TupleElement<I, Tuple<A...>> &get(Tuple<A...> &t) {
}
template<Size I, typename ...A>
inline const TupleElement<I, Tuple<A...>> &get(const Tuple<A...> &t) {
inline TupleElement<I, Tuple<A...>> const &get(Tuple<A...> const &t) {
using Type = TupleElement<I, Tuple<A...>>;
return ((const detail::TupleLeaf<I, Type> &)t.p_base).get();
return ((detail::TupleLeaf<I, Type> const &)t.p_base).get();
}
template<Size I, typename ...A>
@ -428,9 +428,9 @@ inline TupleElement<I, Tuple<A...>> &&get(Tuple<A...> &&t) {
}
template<Size I, typename ...A>
inline const TupleElement<I, Tuple<A...>> &&get(const Tuple<A...> &&t) {
inline TupleElement<I, Tuple<A...>> const &&get(Tuple<A...> const &&t) {
using Type = TupleElement<I, Tuple<A...>>;
return (const Type &&)(((const detail::TupleLeaf<I, Type> &&)t.p_base).get());
return (Type const &&)(((detail::TupleLeaf<I, Type> const &&)t.p_base).get());
}
/* tie */
@ -445,11 +445,11 @@ inline Tuple<T &...> tie(T &...t) {
namespace detail {
struct Ignore {
template<typename T>
const Ignore &operator=(T &&) const { return *this; }
Ignore const &operator=(T &&) const { return *this; }
};
}
static const detail::Ignore ignore = detail::Ignore();
static detail::Ignore const ignore = detail::Ignore();
/* make tuple */
@ -489,7 +489,7 @@ namespace detail {
template<Size I>
struct TupleEqual {
template<typename T, typename U>
bool operator()(const T &x, const U &y) {
bool operator()(T const &x, U const &y) {
return TupleEqual<I - 1>()(x, y) && (get<I>(x) == get<I>(y));
}
};
@ -497,19 +497,19 @@ namespace detail {
template<>
struct TupleEqual<0> {
template<typename T, typename U>
bool operator()(const T &, const U &) {
bool operator()(T const &, U const &) {
return true;
}
};
}
template<typename ...T, typename ...U>
inline bool operator==(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator==(Tuple<T...> const &x, Tuple<U...> const &y) {
return detail::TupleEqual<sizeof...(T)>(x, y);
}
template<typename ...T, typename ...U>
inline bool operator!=(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator!=(Tuple<T...> const &x, Tuple<U...> const &y) {
return !(x == y);
}
@ -517,7 +517,7 @@ namespace detail {
template<Size I>
struct TupleLess {
template<typename T, typename U>
bool operator()(const T &x, const U &y) {
bool operator()(T const &x, U const &y) {
constexpr Size J = TupleSize<T> - I;
if (get<J>(x) < get<J>(y)) return true;
if (get<J>(y) < get<J>(x)) return false;
@ -528,29 +528,29 @@ namespace detail {
template<>
struct TupleLess<0> {
template<typename T, typename U>
bool operator()(const T &, const U &) {
bool operator()(T const &, U const &) {
return true;
}
};
}
template<typename ...T, typename ...U>
inline bool operator<(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator<(Tuple<T...> const &x, Tuple<U...> const &y) {
return detail::TupleLess<sizeof...(T)>(x, y);
}
template<typename ...T, typename ...U>
inline bool operator>(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator>(Tuple<T...> const &x, Tuple<U...> const &y) {
return y < x;
}
template<typename ...T, typename ...U>
inline bool operator<=(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator<=(Tuple<T...> const &x, Tuple<U...> const &y) {
return !(y < x);
}
template<typename ...T, typename ...U>
inline bool operator>=(const Tuple<T...> &x, const Tuple<U...> &y) {
inline bool operator>=(Tuple<T...> const &x, Tuple<U...> const &y) {
return !(x < y);
}

View File

@ -261,12 +261,12 @@ template<typename T> constexpr bool IsAbstract = __is_abstract(T);
/* is const */
template<typename T>
constexpr bool IsConst = IsSame<T, const T>;
constexpr bool IsConst = IsSame<T, T const>;
/* is volatile */
template<typename T>
constexpr bool IsVolatile = IsSame<T, volatile T>;
constexpr bool IsVolatile = IsSame<T, T volatile>;
/* is empty */
@ -473,7 +473,7 @@ constexpr bool IsCopyAssignable = IsAssignable<
template<typename T>
constexpr bool IsMoveAssignable = IsAssignable<
AddLvalueReference<T>,
const AddRvalueReference<T>
AddRvalueReference<T> const
>;
/* is destructible */
@ -532,7 +532,7 @@ namespace detail {
= __has_trivial_copy(T);
template<typename T>
constexpr bool IsTriviallyConstructibleBase<T, const T &>
constexpr bool IsTriviallyConstructibleBase<T, T const &>
= __has_trivial_copy(T);
template<typename T>
@ -552,7 +552,7 @@ template<typename T> constexpr bool IsTriviallyDefaultConstructible
/* is trivially copy constructible */
template<typename T> constexpr bool IsTriviallyCopyConstructible
= IsTriviallyConstructible<T, AddLvalueReference<const T>>;
= IsTriviallyConstructible<T, AddLvalueReference<T const>>;
/* is trivially move constructible */
@ -574,7 +574,7 @@ namespace detail {
= __has_trivial_copy(T);
template<typename T>
constexpr bool IsTriviallyAssignableBase<T, const T &>
constexpr bool IsTriviallyAssignableBase<T, T const &>
= __has_trivial_copy(T);
template<typename T>
@ -589,7 +589,7 @@ constexpr bool IsTriviallyAssignable
/* is trivially copy assignable */
template<typename T> constexpr bool IsTriviallyCopyAssignable
= IsTriviallyAssignable<T, AddLvalueReference<const T>>;
= IsTriviallyAssignable<T, AddLvalueReference<T const>>;
/* is trivially move assignable */
@ -673,12 +673,12 @@ namespace detail {
template<typename T>
struct RemoveConstBase { using Type = T; };
template<typename T>
struct RemoveConstBase<const T> { using Type = T; };
struct RemoveConstBase<T const> { using Type = T; };
template<typename T>
struct RemoveVolatileBase { using Type = T; };
template<typename T>
struct RemoveVolatileBase<volatile T> { using Type = T; };
struct RemoveVolatileBase<T volatile> { using Type = T; };
}
template<typename T>
@ -700,7 +700,7 @@ namespace detail {
struct AddConstCore { using Type = T; };
template<typename T> struct AddConstCore<T, false> {
using Type = const T;
using Type = T const;
};
template<typename T> struct AddConstBase {
@ -711,7 +711,7 @@ namespace detail {
struct AddVolatileCore { using Type = T; };
template<typename T> struct AddVolatileCore<T, false> {
using Type = volatile T;
using Type = T volatile;
};
template<typename T> struct AddVolatileBase {
@ -780,14 +780,14 @@ namespace detail {
template<> struct AddLr<void> {
using Type = void;
};
template<> struct AddLr<const void> {
using Type = const void;
template<> struct AddLr<void const> {
using Type = void const;
};
template<> struct AddLr<volatile void> {
using Type = volatile void;
template<> struct AddLr<void volatile> {
using Type = void volatile;
};
template<> struct AddLr<const volatile void> {
using Type = const volatile void;
template<> struct AddLr<void const volatile> {
using Type = void const volatile;
};
}
@ -798,14 +798,14 @@ namespace detail {
template<> struct AddRr<void> {
using Type = void;
};
template<> struct AddRr<const void> {
using Type = const void;
template<> struct AddRr<void const> {
using Type = void const;
};
template<> struct AddRr<volatile void> {
using Type = volatile void;
template<> struct AddRr<void volatile> {
using Type = void volatile;
};
template<> struct AddRr<const volatile void> {
using Type = const volatile void;
template<> struct AddRr<void const volatile> {
using Type = void const volatile;
};
}
@ -852,8 +852,8 @@ namespace detail {
/* not a type */
struct TlNat {
TlNat() = delete;
TlNat(const TlNat &) = delete;
TlNat &operator=(const TlNat &) = delete;
TlNat(TlNat const &) = delete;
TlNat &operator=(TlNat const &) = delete;
~TlNat() = delete;
};
@ -891,32 +891,32 @@ namespace detail {
template<typename T, typename U>
struct ApplyCv<T, U, true, false> { /* const */
using Type = const U;
using Type = U const;
};
template<typename T, typename U>
struct ApplyCv<T, U, false, true> { /* volatile */
using Type = volatile U;
using Type = U volatile;
};
template<typename T, typename U>
struct ApplyCv<T, U, true, true> { /* const volatile */
using Type = const volatile U;
using Type = U const volatile;
};
template<typename T, typename U>
struct ApplyCv<T &, U, true, false> { /* const */
using Type = const U &;
using Type = U const &;
};
template<typename T, typename U>
struct ApplyCv<T &, U, false, true> { /* volatile */
using Type = volatile U &;
using Type = U volatile &;
};
template<typename T, typename U>
struct ApplyCv<T &, U, true, true> { /* const volatile */
using Type = const volatile U &;
using Type = U const volatile &;
};
template<typename T, bool = IsIntegral<T> || IsEnum<T>>

View File

@ -96,30 +96,30 @@ struct Pair {
Pair() = default;
~Pair() = default;
Pair(const Pair &) = default;
Pair(Pair const &) = default;
Pair(Pair &&) = default;
Pair(const T &x, const U &y): first(x), second(y) {}
Pair(T const &x, U const &y): first(x), second(y) {}
template<typename TT, typename UU>
Pair(TT &&x, UU &&y):
first(forward<TT>(x)), second(forward<UU>(y)) {}
template<typename TT, typename UU>
Pair(const Pair<TT, UU> &v): first(v.first), second(v.second) {}
Pair(Pair<TT, UU> const &v): first(v.first), second(v.second) {}
template<typename TT, typename UU>
Pair(Pair<TT, UU> &&v):
first(move(v.first)), second(move(v.second)) {}
Pair &operator=(const Pair &v) {
Pair &operator=(Pair const &v) {
first = v.first;
second = v.second;
return *this;
}
template<typename TT, typename UU>
Pair &operator=(const Pair<TT, UU> &v) {
Pair &operator=(Pair<TT, UU> const &v) {
first = v.first;
second = v.second;
return *this;
@ -173,17 +173,17 @@ inline Pair<typename detail::MakePairRet<T>::Type,
}
template<typename T, typename U>
inline constexpr bool operator==(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator==(Pair<T, U> const &x, Pair<T, U> const &y) {
return (x.first == y.first) && (x.second == y.second);
}
template<typename T, typename U>
inline constexpr bool operator!=(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator!=(Pair<T, U> const &x, Pair<T, U> const &y) {
return (x.first != y.first) || (x.second != y.second);
}
template<typename T, typename U>
inline constexpr bool operator<(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator<(Pair<T, U> const &x, Pair<T, U> const &y) {
return (x.first < y.first)
? true
: ((y.first < x.first)
@ -194,17 +194,17 @@ inline constexpr bool operator<(const Pair<T, U> &x, const Pair<T, U> &y) {
}
template<typename T, typename U>
inline constexpr bool operator>(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator>(Pair<T, U> const &x, Pair<T, U> const &y) {
return (y < x);
}
template<typename T, typename U>
inline constexpr bool operator<=(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator<=(Pair<T, U> const &x, Pair<T, U> const &y) {
return !(y < x);
}
template<typename T, typename U>
inline constexpr bool operator>=(const Pair<T, U> &x, const Pair<T, U> &y) {
inline constexpr bool operator>=(Pair<T, U> const &x, Pair<T, U> const &y) {
return !(x < y);
}
@ -228,12 +228,12 @@ namespace detail {
template<typename T, typename U>
static T &get(Pair<T, U> &p) { return p.first; }
template<typename T, typename U>
static const T &get(const Pair<T, U> &p) { return p.first; }
static T const &get(Pair<T, U> const &p) { return p.first; }
template<typename T, typename U>
static T &&get(Pair<T, U> &&p) { return forward<T>(p.first); }
template<typename T, typename U>
static const T &&get(const Pair<T, U> &&p) {
return forward<const T>(p.first);
static T const &&get(Pair<T, U> const &&p) {
return forward<T const>(p.first);
}
};
@ -241,12 +241,12 @@ namespace detail {
template<typename T, typename U>
static U &get(Pair<T, U> &p) { return p.second; }
template<typename T, typename U>
static const U &get(const Pair<T, U> &p) { return p.second; }
static U const &get(Pair<T, U> const &p) { return p.second; }
template<typename T, typename U>
static U &&get(Pair<T, U> &&p) { return forward<U>(p.second); }
template<typename T, typename U>
static const T &&get(const Pair<T, U> &&p) {
return forward<const T>(p.second);
static T const &&get(Pair<T, U> const &&p) {
return forward<T const>(p.second);
}
};
}
@ -257,7 +257,7 @@ inline TupleElement<I, Pair<T, U>> &get(Pair<T, U> &p) {
}
template<Size I, typename T, typename U>
inline const TupleElement<I, Pair<T, U>> &get(const Pair<T, U> &p) {
inline TupleElement<I, Pair<T, U>> const &get(Pair<T, U> const &p) {
return detail::GetPair<I>::get(p);
}
@ -267,7 +267,7 @@ inline TupleElement<I, Pair<T, U>> &&get(Pair<T, U> &&p) {
}
template<Size I, typename T, typename U>
inline const TupleElement<I, Pair<T, U>> &&get(const Pair<T, U> &&p) {
inline TupleElement<I, Pair<T, U>> const &&get(Pair<T, U> const &&p) {
return detail::GetPair<I>::get(move(p));
}
@ -310,10 +310,10 @@ namespace detail {
p_second(forward<UU>(b)) {}
T &first() { return p_first; }
const T &first() const { return p_first; }
T const &first() const { return p_first; }
U &second() { return p_second; }
const U &second() const { return p_second; }
U const &second() const { return p_second; }
void swap(CompressedPairBase &v) {
swap_adl(p_first, v.p_first);
@ -330,10 +330,10 @@ namespace detail {
p_second(forward<UU>(b)) {}
T &first() { return *this; }
const T &first() const { return *this; }
T const &first() const { return *this; }
U &second() { return p_second; }
const U &second() const { return p_second; }
U const &second() const { return p_second; }
void swap(CompressedPairBase &v) {
swap_adl(p_second, v.p_second);
@ -349,10 +349,10 @@ namespace detail {
p_first(forward<TT>(a)) {}
T &first() { return p_first; }
const T &first() const { return p_first; }
T const &first() const { return p_first; }
U &second() { return *this; }
const U &second() const { return *this; }
U const &second() const { return *this; }
void swap(CompressedPairBase &v) {
swap_adl(p_first, v.p_first);
@ -366,10 +366,10 @@ namespace detail {
U(forward<UU>(b)) {}
T &first() { return *this; }
const T &first() const { return *this; }
T const &first() const { return *this; }
U &second() { return *this; }
const U &second() const { return *this; }
U const &second() const { return *this; }
void swap(CompressedPairBase &) {}
};
@ -383,10 +383,10 @@ namespace detail {
forward<UU>(b)) {}
T &first() { return Base::first(); }
const T &first() const { return Base::first(); }
T const &first() const { return Base::first(); }
U &second() { return Base::second(); }
const U &second() const { return Base::second(); }
U const &second() const { return Base::second(); }
void swap(CompressedPair &v) {
Base::swap(v);

View File

@ -18,7 +18,7 @@ struct Vec2 {
};
Vec2(): x(0), y(0) {}
Vec2(const Vec2 &v): x(v.x), y(v.y) {}
Vec2(Vec2 const &v): x(v.x), y(v.y) {}
Vec2(T v): x(v), y(v) {}
Vec2(T x, T y): x(x), y(y) {}
@ -29,7 +29,7 @@ struct Vec2 {
x += v; y += v;
return *this;
}
Vec2 &add(const Vec2 &o) {
Vec2 &add(Vec2 const &o) {
x += o.x; y += o.y;
return *this;
}
@ -38,7 +38,7 @@ struct Vec2 {
x -= v; y -= v;
return *this;
}
Vec2 &sub(const Vec2 &o) {
Vec2 &sub(Vec2 const &o) {
x -= o.x; y -= o.y;
return *this;
}
@ -47,7 +47,7 @@ struct Vec2 {
x *= v; y *= v;
return *this;
}
Vec2 &mul(const Vec2 &o) {
Vec2 &mul(Vec2 const &o) {
x *= o.x; y *= o.y;
return *this;
}
@ -56,7 +56,7 @@ struct Vec2 {
x /= v; y /= v;
return *this;
}
Vec2 &div(const Vec2 &o) {
Vec2 &div(Vec2 const &o) {
x /= o.x; y /= o.y;
return *this;
}
@ -70,63 +70,63 @@ struct Vec2 {
return (x == 0) && (y == 0);
}
T dot(const Vec2<T> &o) const {
T dot(Vec2<T> const &o) const {
return (x * o.x) + (y * o.y);
}
};
template<typename T>
inline bool operator==(const Vec2<T> &a, const Vec2<T> &b) {
inline bool operator==(Vec2<T> const &a, Vec2<T> const &b) {
return (a.x == b.x) && (a.y == b.y);
}
template<typename T>
inline bool operator!=(const Vec2<T> &a, const Vec2<T> &b) {
inline bool operator!=(Vec2<T> const &a, Vec2<T> const &b) {
return (a.x != b.x) || (a.y != b.y);
}
template<typename T>
inline Vec2<T> operator+(const Vec2<T> &a, const Vec2<T> &b) {
inline Vec2<T> operator+(Vec2<T> const &a, Vec2<T> const &b) {
return Vec2<T>(a).add(b);
}
template<typename T>
inline Vec2<T> operator+(const Vec2<T> &a, T b) {
inline Vec2<T> operator+(Vec2<T> const &a, T b) {
return Vec2<T>(a).add(b);
}
template<typename T>
inline Vec2<T> operator-(const Vec2<T> &a, const Vec2<T> &b) {
inline Vec2<T> operator-(Vec2<T> const &a, Vec2<T> const &b) {
return Vec2<T>(a).sub(b);
}
template<typename T>
inline Vec2<T> operator-(const Vec2<T> &a, T b) {
inline Vec2<T> operator-(Vec2<T> const &a, T b) {
return Vec2<T>(a).sub(b);
}
template<typename T>
inline Vec2<T> operator*(const Vec2<T> &a, const Vec2<T> &b) {
inline Vec2<T> operator*(Vec2<T> const &a, Vec2<T> const &b) {
return Vec2<T>(a).mul(b);
}
template<typename T>
inline Vec2<T> operator*(const Vec2<T> &a, T b) {
inline Vec2<T> operator*(Vec2<T> const &a, T b) {
return Vec2<T>(a).mul(b);
}
template<typename T>
inline Vec2<T> operator/(const Vec2<T> &a, const Vec2<T> &b) {
inline Vec2<T> operator/(Vec2<T> const &a, Vec2<T> const &b) {
return Vec2<T>(a).div(b);
}
template<typename T>
inline Vec2<T> operator/(const Vec2<T> &a, T b) {
inline Vec2<T> operator/(Vec2<T> const &a, T b) {
return Vec2<T>(a).div(b);
}
template<typename T>
inline Vec2<T> operator-(const Vec2<T> &a) {
inline Vec2<T> operator-(Vec2<T> const &a) {
return Vec2<T>(a).neg();
}
@ -144,7 +144,7 @@ struct Vec3 {
};
Vec3(): x(0), y(0), z(0) {}
Vec3(const Vec3 &v): x(v.x), y(v.y), z(v.z) {}
Vec3(Vec3 const &v): x(v.x), y(v.y), z(v.z) {}
Vec3(T v): x(v), y(v), z(v) {}
Vec3(T x, T y, T z): x(x), y(y), z(z) {}
@ -155,7 +155,7 @@ struct Vec3 {
x += v; y += v; z += v;
return *this;
}
Vec3 &add(const Vec3 &o) {
Vec3 &add(Vec3 const &o) {
x += o.x; y += o.y; z += o.z;
return *this;
}
@ -164,7 +164,7 @@ struct Vec3 {
x -= v; y -= v; z -= v;
return *this;
}
Vec3 &sub(const Vec3 &o) {
Vec3 &sub(Vec3 const &o) {
x -= o.x; y -= o.y; z -= o.z;
return *this;
}
@ -173,7 +173,7 @@ struct Vec3 {
x *= v; y *= v; z *= v;
return *this;
}
Vec3 &mul(const Vec3 &o) {
Vec3 &mul(Vec3 const &o) {
x *= o.x; y *= o.y; z *= o.z;
return *this;
}
@ -182,7 +182,7 @@ struct Vec3 {
x /= v; y /= v; z /= v;
return *this;
}
Vec3 &div(const Vec3 &o) {
Vec3 &div(Vec3 const &o) {
x /= o.x; y /= o.y; z /= o.z;
return *this;
}
@ -196,63 +196,63 @@ struct Vec3 {
return (x == 0) && (y == 0) && (z == 0);
}
T dot(const Vec3<T> &o) const {
T dot(Vec3<T> const &o) const {
return (x * o.x) + (y * o.y) + (z * o.z);
}
};
template<typename T>
inline bool operator==(const Vec3<T> &a, const Vec3<T> &b) {
inline bool operator==(Vec3<T> const &a, Vec3<T> const &b) {
return (a.x == b.x) && (a.y == b.y) && (a.z == b.z);
}
template<typename T>
inline bool operator!=(const Vec3<T> &a, const Vec3<T> &b) {
inline bool operator!=(Vec3<T> const &a, Vec3<T> const &b) {
return (a.x != b.x) || (a.y != b.y) || (a.z != b.z);
}
template<typename T>
inline Vec3<T> operator+(const Vec3<T> &a, const Vec3<T> &b) {
inline Vec3<T> operator+(Vec3<T> const &a, Vec3<T> const &b) {
return Vec3<T>(a).add(b);
}
template<typename T>
inline Vec3<T> operator+(const Vec3<T> &a, T b) {
inline Vec3<T> operator+(Vec3<T> const &a, T b) {
return Vec3<T>(a).add(b);
}
template<typename T>
inline Vec3<T> operator-(const Vec3<T> &a, const Vec3<T> &b) {
inline Vec3<T> operator-(Vec3<T> const &a, Vec3<T> const &b) {
return Vec3<T>(a).sub(b);
}
template<typename T>
inline Vec3<T> operator-(const Vec3<T> &a, T b) {
inline Vec3<T> operator-(Vec3<T> const &a, T b) {
return Vec3<T>(a).sub(b);
}
template<typename T>
inline Vec3<T> operator*(const Vec3<T> &a, const Vec3<T> &b) {
inline Vec3<T> operator*(Vec3<T> const &a, Vec3<T> const &b) {
return Vec3<T>(a).mul(b);
}
template<typename T>
inline Vec3<T> operator*(const Vec3<T> &a, T b) {
inline Vec3<T> operator*(Vec3<T> const &a, T b) {
return Vec3<T>(a).mul(b);
}
template<typename T>
inline Vec3<T> operator/(const Vec3<T> &a, const Vec3<T> &b) {
inline Vec3<T> operator/(Vec3<T> const &a, Vec3<T> const &b) {
return Vec3<T>(a).div(b);
}
template<typename T>
inline Vec3<T> operator/(const Vec3<T> &a, T b) {
inline Vec3<T> operator/(Vec3<T> const &a, T b) {
return Vec3<T>(a).div(b);
}
template<typename T>
inline Vec3<T> operator-(const Vec3<T> &a) {
inline Vec3<T> operator-(Vec3<T> const &a) {
return Vec3<T>(a).neg();
}
@ -270,7 +270,7 @@ struct Vec4 {
};
Vec4(): x(0), y(0), z(0), w(0) {}
Vec4(const Vec4 &v): x(v.x), y(v.y), z(v.z), w(v.w) {}
Vec4(Vec4 const &v): x(v.x), y(v.y), z(v.z), w(v.w) {}
Vec4(T v): x(v), y(v), z(v), w(v) {}
Vec4(T x, T y, T z, T w): x(x), y(y), z(z), w(w) {}
@ -281,7 +281,7 @@ struct Vec4 {
x += v; y += v; z += v; w += v;
return *this;
}
Vec4 &add(const Vec4 &o) {
Vec4 &add(Vec4 const &o) {
x += o.x; y += o.y; z += o.z; w += o.w;
return *this;
}
@ -290,7 +290,7 @@ struct Vec4 {
x -= v; y -= v; z -= v; w -= v;
return *this;
}
Vec4 &sub(const Vec4 &o) {
Vec4 &sub(Vec4 const &o) {
x -= o.x; y -= o.y; z -= o.z; w -= o.w;
return *this;
}
@ -299,7 +299,7 @@ struct Vec4 {
x *= v; y *= v; z *= v; w *= v;
return *this;
}
Vec4 &mul(const Vec4 &o) {
Vec4 &mul(Vec4 const &o) {
x *= o.x; y *= o.y; z *= o.z; w *= o.w;
return *this;
}
@ -308,7 +308,7 @@ struct Vec4 {
x /= v; y /= v; z /= v; w /= v;
return *this;
}
Vec4 &div(const Vec4 &o) {
Vec4 &div(Vec4 const &o) {
x /= o.x; y /= o.y; z /= o.z; w /= o.w;
return *this;
}
@ -322,63 +322,63 @@ struct Vec4 {
return (x == 0) && (y == 0) && (z == 0) && (w == 0);
}
T dot(const Vec4<T> &o) const {
T dot(Vec4<T> const &o) const {
return (x * o.x) + (y * o.y) + (z * o.z) + (w * o.w);
}
};
template<typename T>
inline bool operator==(const Vec4<T> &a, const Vec4<T> &b) {
inline bool operator==(Vec4<T> const &a, Vec4<T> const &b) {
return (a.x == b.x) && (a.y == b.y) && (a.z == b.z) && (a.w == b.w);
}
template<typename T>
inline bool operator!=(const Vec4<T> &a, const Vec4<T> &b) {
inline bool operator!=(Vec4<T> const &a, Vec4<T> const &b) {
return (a.x != b.x) || (a.y != b.y) || (a.z != b.z) || (a.w != b.w);
}
template<typename T>
inline Vec4<T> operator+(const Vec4<T> &a, const Vec4<T> &b) {
inline Vec4<T> operator+(Vec4<T> const &a, Vec4<T> const &b) {
return Vec4<T>(a).add(b);
}
template<typename T>
inline Vec4<T> operator+(const Vec4<T> &a, T b) {
inline Vec4<T> operator+(Vec4<T> const &a, T b) {
return Vec4<T>(a).add(b);
}
template<typename T>
inline Vec4<T> operator-(const Vec4<T> &a, const Vec4<T> &b) {
inline Vec4<T> operator-(Vec4<T> const &a, Vec4<T> const &b) {
return Vec4<T>(a).sub(b);
}
template<typename T>
inline Vec4<T> operator-(const Vec4<T> &a, T b) {
inline Vec4<T> operator-(Vec4<T> const &a, T b) {
return Vec4<T>(a).sub(b);
}
template<typename T>
inline Vec4<T> operator*(const Vec4<T> &a, const Vec4<T> &b) {
inline Vec4<T> operator*(Vec4<T> const &a, Vec4<T> const &b) {
return Vec4<T>(a).mul(b);
}
template<typename T>
inline Vec4<T> operator*(const Vec4<T> &a, T b) {
inline Vec4<T> operator*(Vec4<T> const &a, T b) {
return Vec4<T>(a).mul(b);
}
template<typename T>
inline Vec4<T> operator/(const Vec4<T> &a, const Vec4<T> &b) {
inline Vec4<T> operator/(Vec4<T> const &a, Vec4<T> const &b) {
return Vec4<T>(a).div(b);
}
template<typename T>
inline Vec4<T> operator/(const Vec4<T> &a, T b) {
inline Vec4<T> operator/(Vec4<T> const &a, T b) {
return Vec4<T>(a).div(b);
}
template<typename T>
inline Vec4<T> operator-(const Vec4<T> &a) {
inline Vec4<T> operator-(Vec4<T> const &a) {
return Vec4<T>(a).neg();
}

View File

@ -59,7 +59,7 @@ class Vector {
}
}
void copy_contents(const Vector &v) {
void copy_contents(Vector const &v) {
if (IsPod<T>) {
memcpy(p_buf.first(), v.p_buf.first(), p_len * sizeof(T));
} else {
@ -76,17 +76,16 @@ public:
using Difference = Ptrdiff;
using Value = T;
using Reference = T &;
using ConstReference = const T &;
using ConstReference = T const &;
using Pointer = AllocatorPointer<A>;
using ConstPointer = AllocatorConstPointer<A>;
using Range = PointerRange<T>;
using ConstRange = PointerRange<const T>;
using ConstRange = PointerRange<T const>;
using Allocator = A;
Vector(const A &a = A()): p_len(0), p_cap(0), p_buf(nullptr, a) {}
Vector(A const &a = A()): p_len(0), p_cap(0), p_buf(nullptr, a) {}
explicit Vector(Size n, const T &val = T(),
const A &al = A()): Vector(al) {
explicit Vector(Size n, T const &val = T(), A const &al = A()): Vector(al) {
if (!n) return;
p_buf.first() = allocator_allocate(p_buf.second(), n);
p_len = p_cap = n;
@ -95,14 +94,14 @@ public:
allocator_construct(p_buf.second(), cur++, val);
}
Vector(const Vector &v): p_len(0), p_cap(0), p_buf(nullptr,
Vector(Vector const &v): p_len(0), p_cap(0), p_buf(nullptr,
allocator_container_copy(v.p_buf.second())) {
reserve(v.p_cap);
p_len = v.p_len;
copy_contents(v);
}
Vector(const Vector &v, const A &a): p_len(0), p_cap(0), p_buf(nullptr, a) {
Vector(Vector const &v, A const &a): p_len(0), p_cap(0), p_buf(nullptr, a) {
reserve(v.p_cap);
p_len = v.p_len;
copy_contents(v);
@ -114,7 +113,7 @@ public:
v.p_len = v.p_cap = 0;
}
Vector(Vector &&v, const A &a): p_len(0), p_cap(0), p_buf(nullptr, a) {
Vector(Vector &&v, A const &a): p_len(0), p_cap(0), p_buf(nullptr, a) {
if (a != v.p_buf.second()) {
reserve(v.p_cap);
p_len = v.p_len;
@ -136,7 +135,7 @@ public:
v.p_len = v.p_cap = 0;
}
Vector(ConstRange r, const A &a = A()): Vector(a) {
Vector(ConstRange r, A const &a = A()): Vector(a) {
reserve(r.size());
if (IsPod<T>) {
memcpy(p_buf.first(), &r[0], r.size() * sizeof(T));
@ -147,12 +146,12 @@ public:
p_len = r.size();
}
Vector(InitializerList<T> v, const A &a = A()):
Vector(InitializerList<T> v, A const &a = A()):
Vector(ConstRange(v.begin(), v.size()), a) {}
template<typename R, typename = EnableIf<
IsInputRange<R> && IsConvertible<RangeReference<R>, Value>
>> Vector(R range, const A &a = A()): Vector(a) {
>> Vector(R range, A const &a = A()): Vector(a) {
ctor_from_range(range);
}
@ -170,7 +169,7 @@ public:
p_len = 0;
}
Vector &operator=(const Vector &v) {
Vector &operator=(Vector const &v) {
if (this == &v) return *this;
clear();
if (AllocatorPropagateOnContainerCopyAssignment<A>) {
@ -225,7 +224,7 @@ public:
return *this;
}
void resize(Size n, const T &v = T()) {
void resize(Size n, T const &v = T()) {
if (!n) {
clear();
return;
@ -272,18 +271,18 @@ public:
}
T &operator[](Size i) { return p_buf.first()[i]; }
const T &operator[](Size i) const { return p_buf.first()[i]; }
T const &operator[](Size i) const { return p_buf.first()[i]; }
T *at(Size i) {
if (!in_range(i)) return nullptr;
return &p_buf.first()[i];
}
const T *at(Size i) const {
T const *at(Size i) const {
if (!in_range(i)) return nullptr;
return &p_buf.first()[i];
}
T &push(const T &v) {
T &push(T const &v) {
if (p_len == p_cap) reserve(p_len + 1);
allocator_construct(p_buf.second(), &p_buf.first()[p_len], v);
return p_buf.first()[p_len++];
@ -301,7 +300,7 @@ public:
return p_buf.first()[p_len++];
}
Range push_n(const T *v, Size n) {
Range push_n(T const *v, Size n) {
reserve(p_len + n);
if (IsPod<T>) {
memcpy(p_buf.first() + p_len, v, n * sizeof(T));
@ -331,13 +330,13 @@ public:
}
T &front() { return p_buf.first()[0]; }
const T &front() const { return p_buf.first()[0]; }
T const &front() const { return p_buf.first()[0]; }
T &back() { return p_buf.first()[p_len - 1]; }
const T &back() const { return p_buf.first()[p_len - 1]; }
T const &back() const { return p_buf.first()[p_len - 1]; }
Value *data() { return (Value *)p_buf.first(); }
const Value *data() const { return (const Value *)p_buf.first(); }
Value const *data() const { return (Value const *)p_buf.first(); }
Size size() const { return p_len; }
Size capacity() const { return p_cap; }
@ -350,7 +349,7 @@ public:
bool in_range(Size idx) { return idx < p_len; }
bool in_range(int idx) { return idx >= 0 && Size(idx) < p_len; }
bool in_range(const Value *ptr) {
bool in_range(Value const *ptr) {
return ptr >= p_buf.first() && ptr < &p_buf.first()[p_len];
}
@ -367,13 +366,13 @@ public:
return Range(&p_buf.first()[idx], &p_buf.first()[p_len]);
}
Range insert(Size idx, const T &v) {
Range insert(Size idx, T const &v) {
insert_base(idx, 1);
p_buf.first()[idx] = v;
return Range(&p_buf.first()[idx], &p_buf.first()[p_len]);
}
Range insert(Size idx, Size n, const T &v) {
Range insert(Size idx, Size n, T const &v) {
insert_base(idx, n);
for (Size i = 0; i < n; ++i) {
p_buf.first()[idx + i] = v;
@ -424,17 +423,17 @@ public:
};
template<typename T, typename A>
inline bool operator==(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator==(Vector<T, A> const &x, Vector<T, A> const &y) {
return equal(x.iter(), y.iter());
}
template<typename T, typename A>
inline bool operator!=(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator!=(Vector<T, A> const &x, Vector<T, A> const &y) {
return !(x == y);
}
template<typename T, typename A>
inline bool operator<(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator<(Vector<T, A> const &x, Vector<T, A> const &y) {
using Range = typename Vector<T, A>::Range;
Range range1 = x.iter(), range2 = y.iter();
while (!range1.empty() && !range2.empty()) {
@ -447,17 +446,17 @@ inline bool operator<(const Vector<T, A> &x, const Vector<T, A> &y) {
}
template<typename T, typename A>
inline bool operator>(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator>(Vector<T, A> const &x, Vector<T, A> const &y) {
return (y < x);
}
template<typename T, typename A>
inline bool operator<=(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator<=(Vector<T, A> const &x, Vector<T, A> const &y) {
return !(y < x);
}
template<typename T, typename A>
inline bool operator>=(const Vector<T, A> &x, const Vector<T, A> &y) {
inline bool operator>=(Vector<T, A> const &x, Vector<T, A> const &y) {
return !(x < y);
}