each -> iter
parent
29bf4c3b76
commit
9677274b3f
|
@ -185,21 +185,21 @@ inline R max_element(R range, C compare) {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T min(std::initializer_list<T> il) {
|
inline T min(std::initializer_list<T> il) {
|
||||||
return octa::min_element(octa::each(il)).front();
|
return octa::min_element(octa::iter(il)).front();
|
||||||
}
|
}
|
||||||
template<typename T, typename C>
|
template<typename T, typename C>
|
||||||
inline T min(std::initializer_list<T> il, C compare) {
|
inline T min(std::initializer_list<T> il, C compare) {
|
||||||
return octa::min_element(octa::each(il), compare).front();
|
return octa::min_element(octa::iter(il), compare).front();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T max(std::initializer_list<T> il) {
|
inline T max(std::initializer_list<T> il) {
|
||||||
return octa::max_element(octa::each(il)).front();
|
return octa::max_element(octa::iter(il)).front();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename C>
|
template<typename T, typename C>
|
||||||
inline T max(std::initializer_list<T> il, C compare) {
|
inline T max(std::initializer_list<T> il, C compare) {
|
||||||
return octa::max_element(octa::each(il), compare).front();
|
return octa::max_element(octa::iter(il), compare).front();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clamp */
|
/* clamp */
|
||||||
|
|
|
@ -52,18 +52,18 @@ struct Array {
|
||||||
Pointer data() { return p_buf; }
|
Pointer data() { return p_buf; }
|
||||||
ConstPointer data() const { return p_buf; }
|
ConstPointer data() const { return p_buf; }
|
||||||
|
|
||||||
Range each() {
|
Range iter() {
|
||||||
return Range(p_buf, p_buf + N);
|
return Range(p_buf, p_buf + N);
|
||||||
}
|
}
|
||||||
ConstRange each() const {
|
ConstRange iter() const {
|
||||||
return ConstRange(p_buf, p_buf + N);
|
return ConstRange(p_buf, p_buf + N);
|
||||||
}
|
}
|
||||||
ConstRange ceach() const {
|
ConstRange citer() const {
|
||||||
return ConstRange(p_buf, p_buf + N);
|
return ConstRange(p_buf, p_buf + N);
|
||||||
}
|
}
|
||||||
|
|
||||||
void swap(Array &v) {
|
void swap(Array &v) {
|
||||||
octa::swap_ranges(each(), v.each());
|
octa::swap_ranges(iter(), v.iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
T p_buf[(N > 0) ? N : 1];
|
T p_buf[(N > 0) ? N : 1];
|
||||||
|
|
|
@ -39,12 +39,12 @@ namespace octa {
|
||||||
template<typename T> using InitializerList = std::initializer_list<T>;
|
template<typename T> using InitializerList = std::initializer_list<T>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
octa::PointerRange<const T> each(std::initializer_list<T> init) {
|
octa::PointerRange<const T> iter(std::initializer_list<T> init) {
|
||||||
return octa::PointerRange<const T>(init.begin(), init.end());
|
return octa::PointerRange<const T>(init.begin(), init.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
octa::PointerRange<const T> ceach(std::initializer_list<T> init) {
|
octa::PointerRange<const T> citer(std::initializer_list<T> init) {
|
||||||
return octa::PointerRange<const T>(init.begin(), init.end());
|
return octa::PointerRange<const T>(init.begin(), init.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,11 +182,11 @@ private:
|
||||||
|
|
||||||
float p_maxlf;
|
float p_maxlf;
|
||||||
|
|
||||||
Range each_from(Chain *c, octa::Size h) {
|
Range iter_from(Chain *c, octa::Size h) {
|
||||||
return Range(p_data.first() + h + 1,
|
return Range(p_data.first() + h + 1,
|
||||||
p_data.first() + bucket_count(), c);
|
p_data.first() + bucket_count(), c);
|
||||||
}
|
}
|
||||||
ConstRange each_from(Chain *c, octa::Size h) const {
|
ConstRange iter_from(Chain *c, octa::Size h) const {
|
||||||
using RChain = octa::detail::HashChain<const E>;
|
using RChain = octa::detail::HashChain<const E>;
|
||||||
return ConstRange((RChain **)(p_data.first() + h + 1),
|
return ConstRange((RChain **)(p_data.first() + h + 1),
|
||||||
(RChain **)(p_data.first() + bucket_count()),
|
(RChain **)(p_data.first() + bucket_count()),
|
||||||
|
@ -394,7 +394,7 @@ protected:
|
||||||
get_cpalloc() = ht.get_cpalloc();
|
get_cpalloc() = ht.get_cpalloc();
|
||||||
get_challoc() = ht.get_challoc();
|
get_challoc() = ht.get_challoc();
|
||||||
}
|
}
|
||||||
for (ConstRange range = ht.each(); !range.empty(); range.pop_front())
|
for (ConstRange range = ht.iter(); !range.empty(); range.pop_front())
|
||||||
emplace(range.front());
|
emplace(range.front());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -542,14 +542,14 @@ public:
|
||||||
Range find(const K &key) {
|
Range find(const K &key) {
|
||||||
octa::Size h = 0;
|
octa::Size h = 0;
|
||||||
Chain *c;
|
Chain *c;
|
||||||
if (find(key, h, c)) return each_from(c, h);
|
if (find(key, h, c)) return iter_from(c, h);
|
||||||
return Range();
|
return Range();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstRange find(const K &key) const {
|
ConstRange find(const K &key) const {
|
||||||
octa::Size h = 0;
|
octa::Size h = 0;
|
||||||
Chain *c;
|
Chain *c;
|
||||||
if (find(key, h, c)) return each_from(c, h);
|
if (find(key, h, c)) return iter_from(c, h);
|
||||||
return ConstRange();
|
return ConstRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -587,30 +587,30 @@ public:
|
||||||
rehash(octa::Size(ceil(count / max_load_factor())));
|
rehash(octa::Size(ceil(count / max_load_factor())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Range each() {
|
Range iter() {
|
||||||
return Range(p_data.first(), p_data.first() + bucket_count());
|
return Range(p_data.first(), p_data.first() + bucket_count());
|
||||||
}
|
}
|
||||||
ConstRange each() const {
|
ConstRange iter() const {
|
||||||
using Chain = octa::detail::HashChain<const E>;
|
using Chain = octa::detail::HashChain<const E>;
|
||||||
return ConstRange((Chain **)p_data.first(),
|
return ConstRange((Chain **)p_data.first(),
|
||||||
(Chain **)(p_data.first() + bucket_count()));
|
(Chain **)(p_data.first() + bucket_count()));
|
||||||
}
|
}
|
||||||
ConstRange ceach() const {
|
ConstRange citer() const {
|
||||||
using Chain = octa::detail::HashChain<const E>;
|
using Chain = octa::detail::HashChain<const E>;
|
||||||
return ConstRange((Chain **)p_data.first(),
|
return ConstRange((Chain **)p_data.first(),
|
||||||
(Chain **)(p_data.first() + bucket_count()));
|
(Chain **)(p_data.first() + bucket_count()));
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalRange each(octa::Size n) {
|
LocalRange iter(octa::Size n) {
|
||||||
if (n >= p_size) return LocalRange();
|
if (n >= p_size) return LocalRange();
|
||||||
return LocalRange(p_data.first()[n]);
|
return LocalRange(p_data.first()[n]);
|
||||||
}
|
}
|
||||||
ConstLocalRange each(octa::Size n) const {
|
ConstLocalRange iter(octa::Size n) const {
|
||||||
using Chain = octa::detail::HashChain<const E>;
|
using Chain = octa::detail::HashChain<const E>;
|
||||||
if (n >= p_size) return ConstLocalRange();
|
if (n >= p_size) return ConstLocalRange();
|
||||||
return ConstLocalRange((Chain *)p_data.first()[n]);
|
return ConstLocalRange((Chain *)p_data.first()[n]);
|
||||||
}
|
}
|
||||||
ConstLocalRange ceach(octa::Size n) const {
|
ConstLocalRange citer(octa::Size n) const {
|
||||||
using Chain = octa::detail::HashChain<const E>;
|
using Chain = octa::detail::HashChain<const E>;
|
||||||
if (n >= p_size) return ConstLocalRange();
|
if (n >= p_size) return ConstLocalRange();
|
||||||
return ConstLocalRange((Chain *)p_data.first()[n]);
|
return ConstLocalRange((Chain *)p_data.first()[n]);
|
||||||
|
|
|
@ -113,14 +113,14 @@ namespace detail {
|
||||||
|
|
||||||
MapImpl(octa::InitializerList<Value> init, octa::Size size = 0,
|
MapImpl(octa::InitializerList<Value> init, octa::Size size = 0,
|
||||||
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
|
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
|
||||||
): MapImpl(octa::each(init), size, hf, eqf, alloc) {}
|
): MapImpl(octa::iter(init), size, hf, eqf, alloc) {}
|
||||||
|
|
||||||
MapImpl(octa::InitializerList<Value> init, octa::Size size, const A &alloc)
|
MapImpl(octa::InitializerList<Value> init, octa::Size size, const A &alloc)
|
||||||
: MapImpl(octa::each(init), size, H(), C(), alloc) {}
|
: MapImpl(octa::iter(init), size, H(), C(), alloc) {}
|
||||||
|
|
||||||
MapImpl(octa::InitializerList<Value> init, octa::Size size, const H &hf,
|
MapImpl(octa::InitializerList<Value> init, octa::Size size, const H &hf,
|
||||||
const A &alloc
|
const A &alloc
|
||||||
): MapImpl(octa::each(init), size, hf, C(), alloc) {}
|
): MapImpl(octa::iter(init), size, hf, C(), alloc) {}
|
||||||
|
|
||||||
MapImpl &operator=(const MapImpl &m) {
|
MapImpl &operator=(const MapImpl &m) {
|
||||||
Base::operator=(m);
|
Base::operator=(m);
|
||||||
|
|
28
octa/range.h
28
octa/range.h
|
@ -352,9 +352,9 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
T each() const { return p_range; }
|
T iter() const { return p_range; }
|
||||||
|
|
||||||
HalfRange<RangeHalf> each(const RangeHalf &other) const {
|
HalfRange<RangeHalf> iter(const RangeHalf &other) const {
|
||||||
return HalfRange<RangeHalf>(*this, other);
|
return HalfRange<RangeHalf>(*this, other);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -429,36 +429,36 @@ template<typename B, typename C, typename V, typename R = V &,
|
||||||
return octa::detail::push_back_n<B>(*((B *)this), n);
|
return octa::detail::push_back_n<B>(*((B *)this), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
B each() const {
|
B iter() const {
|
||||||
return B(*((B *)this));
|
return B(*((B *)this));
|
||||||
}
|
}
|
||||||
|
|
||||||
ReverseRange<B> reverse() const {
|
ReverseRange<B> reverse() const {
|
||||||
return ReverseRange<B>(each());
|
return ReverseRange<B>(iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
MoveRange<B> movable() const {
|
MoveRange<B> movable() const {
|
||||||
return MoveRange<B>(each());
|
return MoveRange<B>(iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
RangeHalf<B> half() const {
|
RangeHalf<B> half() const {
|
||||||
return RangeHalf<B>(each());
|
return RangeHalf<B>(iter());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto each(T &r) -> decltype(r.each()) {
|
auto iter(T &r) -> decltype(r.iter()) {
|
||||||
return r.each();
|
return r.iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto each(const T &r) -> decltype(r.each()) {
|
auto iter(const T &r) -> decltype(r.iter()) {
|
||||||
return r.each();
|
return r.iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
auto ceach(const T &r) -> decltype(r.each()) {
|
auto citer(const T &r) -> decltype(r.iter()) {
|
||||||
return r.each();
|
return r.iter();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename V, typename R = V &, typename S = octa::Size,
|
template<typename V, typename R = V &, typename S = octa::Size,
|
||||||
|
@ -852,7 +852,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T, octa::Size N>
|
template<typename T, octa::Size N>
|
||||||
PointerRange<T> each(T (&array)[N]) {
|
PointerRange<T> iter(T (&array)[N]) {
|
||||||
return PointerRange<T>(array, N);
|
return PointerRange<T>(array, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1037,7 +1037,7 @@ ChunksRange<T> chunks(const T &it, RangeSize<T> chs) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// range of
|
// range of
|
||||||
template<typename T> using RangeOf = decltype(octa::each(octa::declval<T>()));
|
template<typename T> using RangeOf = decltype(octa::iter(octa::declval<T>()));
|
||||||
|
|
||||||
} /* namespace octa */
|
} /* namespace octa */
|
||||||
|
|
||||||
|
|
|
@ -99,14 +99,14 @@ namespace detail {
|
||||||
|
|
||||||
SetImpl(octa::InitializerList<Value> init, octa::Size size = 0,
|
SetImpl(octa::InitializerList<Value> init, octa::Size size = 0,
|
||||||
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
|
const H &hf = H(), const C &eqf = C(), const A &alloc = A()
|
||||||
): SetImpl(octa::each(init), size, hf, eqf, alloc) {}
|
): SetImpl(octa::iter(init), size, hf, eqf, alloc) {}
|
||||||
|
|
||||||
SetImpl(octa::InitializerList<Value> init, octa::Size size, const A &alloc)
|
SetImpl(octa::InitializerList<Value> init, octa::Size size, const A &alloc)
|
||||||
: SetImpl(octa::each(init), size, H(), C(), alloc) {}
|
: SetImpl(octa::iter(init), size, H(), C(), alloc) {}
|
||||||
|
|
||||||
SetImpl(octa::InitializerList<Value> init, octa::Size size, const H &hf,
|
SetImpl(octa::InitializerList<Value> init, octa::Size size, const H &hf,
|
||||||
const A &alloc
|
const A &alloc
|
||||||
): SetImpl(octa::each(init), size, hf, C(), alloc) {}
|
): SetImpl(octa::iter(init), size, hf, C(), alloc) {}
|
||||||
|
|
||||||
SetImpl &operator=(const SetImpl &m) {
|
SetImpl &operator=(const SetImpl &m) {
|
||||||
Base::operator=(m);
|
Base::operator=(m);
|
||||||
|
|
|
@ -165,7 +165,7 @@ public:
|
||||||
|
|
||||||
StringBase(const StringBase &s, octa::Size pos, octa::Size len = npos,
|
StringBase(const StringBase &s, octa::Size pos, octa::Size len = npos,
|
||||||
const A &a = A()):
|
const A &a = A()):
|
||||||
p_buf(s.p_buf.each().slice(pos,
|
p_buf(s.p_buf.iter().slice(pos,
|
||||||
(len == npos) ? s.p_buf.size() : (pos + len)), a) {
|
(len == npos) ? s.p_buf.size() : (pos + len)), a) {
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ public:
|
||||||
|
|
||||||
StringBase &append(const StringBase &s) {
|
StringBase &append(const StringBase &s) {
|
||||||
p_buf.pop();
|
p_buf.pop();
|
||||||
p_buf.insert_range(p_buf.size(), s.p_buf.each());
|
p_buf.insert_range(p_buf.size(), s.p_buf.iter());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,13 +309,13 @@ public:
|
||||||
return strcmp(p_buf.data(), p);
|
return strcmp(p_buf.data(), p);
|
||||||
}
|
}
|
||||||
|
|
||||||
Range each() {
|
Range iter() {
|
||||||
return Range(p_buf.data(), size());
|
return Range(p_buf.data(), size());
|
||||||
}
|
}
|
||||||
ConstRange each() const {
|
ConstRange iter() const {
|
||||||
return ConstRange(p_buf.data(), size());
|
return ConstRange(p_buf.data(), size());
|
||||||
}
|
}
|
||||||
ConstRange ceach() const {
|
ConstRange citer() const {
|
||||||
return ConstRange(p_buf.data(), size());
|
return ConstRange(p_buf.data(), size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Size to_hash() const {
|
Size to_hash() const {
|
||||||
return each().to_hash();
|
return iter().to_hash();
|
||||||
}
|
}
|
||||||
|
|
||||||
A get_allocator() const {
|
A get_allocator() const {
|
||||||
|
@ -359,7 +359,7 @@ static inline bool operator!=(const char *lhs, const String &rhs) {
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
String concat(const T &v, const String &sep, F func) {
|
String concat(const T &v, const String &sep, F func) {
|
||||||
String ret;
|
String ret;
|
||||||
auto range = octa::each(v);
|
auto range = octa::iter(v);
|
||||||
if (range.empty()) return ret;
|
if (range.empty()) return ret;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ret += func(range.front());
|
ret += func(range.front());
|
||||||
|
@ -373,7 +373,7 @@ String concat(const T &v, const String &sep, F func) {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
String concat(const T &v, const String &sep = " ") {
|
String concat(const T &v, const String &sep = " ") {
|
||||||
String ret;
|
String ret;
|
||||||
auto range = octa::each(v);
|
auto range = octa::iter(v);
|
||||||
if (range.empty()) return ret;
|
if (range.empty()) return ret;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ret += range.front();
|
ret += range.front();
|
||||||
|
@ -386,12 +386,12 @@ String concat(const T &v, const String &sep = " ") {
|
||||||
|
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
String concat(std::initializer_list<T> v, const String &sep, F func) {
|
String concat(std::initializer_list<T> v, const String &sep, F func) {
|
||||||
return concat(octa::each(v), sep, func);
|
return concat(octa::iter(v), sep, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
String concat(std::initializer_list<T> v, const String &sep = " ") {
|
String concat(std::initializer_list<T> v, const String &sep = " ") {
|
||||||
return concat(octa::each(v), sep);
|
return concat(octa::iter(v), sep);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
@ -421,8 +421,8 @@ template<typename T> struct ToString {
|
||||||
!octa::IsScalar<U>::value, bool> = true
|
!octa::IsScalar<U>::value, bool> = true
|
||||||
) {
|
) {
|
||||||
String ret("{");
|
String ret("{");
|
||||||
ret += concat(octa::each(v), ", ", ToString<octa::RangeReference<
|
ret += concat(octa::iter(v), ", ", ToString<octa::RangeReference<
|
||||||
decltype(octa::each(v))
|
decltype(octa::iter(v))
|
||||||
>>());
|
>>());
|
||||||
ret += "}";
|
ret += "}";
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -382,16 +382,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Range insert(Size idx, InitializerList<T> il) {
|
Range insert(Size idx, InitializerList<T> il) {
|
||||||
return insert_range(idx, octa::each(il));
|
return insert_range(idx, octa::iter(il));
|
||||||
}
|
}
|
||||||
|
|
||||||
Range each() {
|
Range iter() {
|
||||||
return Range(p_buf.first(), p_buf.first() + p_len);
|
return Range(p_buf.first(), p_buf.first() + p_len);
|
||||||
}
|
}
|
||||||
ConstRange each() const {
|
ConstRange iter() const {
|
||||||
return ConstRange(p_buf.first(), p_buf.first() + p_len);
|
return ConstRange(p_buf.first(), p_buf.first() + p_len);
|
||||||
}
|
}
|
||||||
ConstRange ceach() const {
|
ConstRange citer() const {
|
||||||
return ConstRange(p_buf.first(), p_buf.first() + p_len);
|
return ConstRange(p_buf.first(), p_buf.first() + p_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ int main() {
|
||||||
|
|
||||||
assert(x.data()[0] == x[0]);
|
assert(x.data()[0] == x[0]);
|
||||||
|
|
||||||
auto r = x.each();
|
auto r = x.iter();
|
||||||
assert(r.front() == 2);
|
assert(r.front() == 2);
|
||||||
assert(r.back() == 32);
|
assert(r.back() == 32);
|
||||||
|
|
||||||
|
|
|
@ -69,12 +69,12 @@ int main() {
|
||||||
assert(z[3] == 5);
|
assert(z[3] == 5);
|
||||||
assert(z.size() == 11);
|
assert(z.size() == 11);
|
||||||
|
|
||||||
auto r = z.each();
|
auto r = z.iter();
|
||||||
assert(r.front() == 5);
|
assert(r.front() == 5);
|
||||||
assert(r.back() == 5);
|
assert(r.back() == 5);
|
||||||
assert(r[2] == 4);
|
assert(r[2] == 4);
|
||||||
|
|
||||||
auto r2 = each(z);
|
auto r2 = iter(z);
|
||||||
assert(r.front() == r2.front());
|
assert(r.front() == r2.front());
|
||||||
|
|
||||||
Vector<int> w;
|
Vector<int> w;
|
||||||
|
|
Loading…
Reference in New Issue