each -> iter

master
Daniel Kolesa 2015-06-26 21:01:16 +01:00
parent 29bf4c3b76
commit 9677274b3f
11 changed files with 60 additions and 60 deletions

View File

@ -185,21 +185,21 @@ inline R max_element(R range, C compare) {
template<typename T>
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>
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>
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>
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 */

View File

@ -52,18 +52,18 @@ struct Array {
Pointer data() { return p_buf; }
ConstPointer data() const { return p_buf; }
Range each() {
Range iter() {
return Range(p_buf, p_buf + N);
}
ConstRange each() const {
ConstRange iter() const {
return ConstRange(p_buf, p_buf + N);
}
ConstRange ceach() const {
ConstRange citer() const {
return ConstRange(p_buf, p_buf + N);
}
void swap(Array &v) {
octa::swap_ranges(each(), v.each());
octa::swap_ranges(iter(), v.iter());
}
T p_buf[(N > 0) ? N : 1];

View File

@ -39,12 +39,12 @@ namespace octa {
template<typename T> using InitializerList = std::initializer_list<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());
}
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());
}

View File

@ -182,11 +182,11 @@ private:
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,
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>;
return ConstRange((RChain **)(p_data.first() + h + 1),
(RChain **)(p_data.first() + bucket_count()),
@ -394,7 +394,7 @@ protected:
get_cpalloc() = ht.get_cpalloc();
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());
return *this;
}
@ -542,14 +542,14 @@ public:
Range find(const K &key) {
octa::Size h = 0;
Chain *c;
if (find(key, h, c)) return each_from(c, h);
if (find(key, h, c)) return iter_from(c, h);
return Range();
}
ConstRange find(const K &key) const {
octa::Size h = 0;
Chain *c;
if (find(key, h, c)) return each_from(c, h);
if (find(key, h, c)) return iter_from(c, h);
return ConstRange();
}
@ -587,30 +587,30 @@ public:
rehash(octa::Size(ceil(count / max_load_factor())));
}
Range each() {
Range iter() {
return Range(p_data.first(), p_data.first() + bucket_count());
}
ConstRange each() const {
ConstRange iter() const {
using Chain = octa::detail::HashChain<const E>;
return ConstRange((Chain **)p_data.first(),
(Chain **)(p_data.first() + bucket_count()));
}
ConstRange ceach() const {
ConstRange citer() const {
using Chain = octa::detail::HashChain<const E>;
return ConstRange((Chain **)p_data.first(),
(Chain **)(p_data.first() + bucket_count()));
}
LocalRange each(octa::Size n) {
LocalRange iter(octa::Size n) {
if (n >= p_size) return LocalRange();
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>;
if (n >= p_size) return ConstLocalRange();
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>;
if (n >= p_size) return ConstLocalRange();
return ConstLocalRange((Chain *)p_data.first()[n]);

View File

@ -113,14 +113,14 @@ namespace detail {
MapImpl(octa::InitializerList<Value> init, octa::Size size = 0,
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::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,
const A &alloc
): MapImpl(octa::each(init), size, hf, C(), alloc) {}
): MapImpl(octa::iter(init), size, hf, C(), alloc) {}
MapImpl &operator=(const MapImpl &m) {
Base::operator=(m);

View File

@ -352,9 +352,9 @@ public:
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);
}
};
@ -429,36 +429,36 @@ template<typename B, typename C, typename V, typename R = V &,
return octa::detail::push_back_n<B>(*((B *)this), n);
}
B each() const {
B iter() const {
return B(*((B *)this));
}
ReverseRange<B> reverse() const {
return ReverseRange<B>(each());
return ReverseRange<B>(iter());
}
MoveRange<B> movable() const {
return MoveRange<B>(each());
return MoveRange<B>(iter());
}
RangeHalf<B> half() const {
return RangeHalf<B>(each());
return RangeHalf<B>(iter());
}
};
template<typename T>
auto each(T &r) -> decltype(r.each()) {
return r.each();
auto iter(T &r) -> decltype(r.iter()) {
return r.iter();
}
template<typename T>
auto each(const T &r) -> decltype(r.each()) {
return r.each();
auto iter(const T &r) -> decltype(r.iter()) {
return r.iter();
}
template<typename T>
auto ceach(const T &r) -> decltype(r.each()) {
return r.each();
auto citer(const T &r) -> decltype(r.iter()) {
return r.iter();
}
template<typename V, typename R = V &, typename S = octa::Size,
@ -852,7 +852,7 @@ private:
};
template<typename T, octa::Size N>
PointerRange<T> each(T (&array)[N]) {
PointerRange<T> iter(T (&array)[N]) {
return PointerRange<T>(array, N);
}
@ -1037,7 +1037,7 @@ ChunksRange<T> chunks(const T &it, RangeSize<T> chs) {
}
// 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 */

View File

@ -99,14 +99,14 @@ namespace detail {
SetImpl(octa::InitializerList<Value> init, octa::Size size = 0,
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::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,
const A &alloc
): SetImpl(octa::each(init), size, hf, C(), alloc) {}
): SetImpl(octa::iter(init), size, hf, C(), alloc) {}
SetImpl &operator=(const SetImpl &m) {
Base::operator=(m);

View File

@ -165,7 +165,7 @@ public:
StringBase(const StringBase &s, octa::Size pos, octa::Size len = npos,
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) {
terminate();
}
@ -254,7 +254,7 @@ public:
StringBase &append(const StringBase &s) {
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;
}
@ -309,13 +309,13 @@ public:
return strcmp(p_buf.data(), p);
}
Range each() {
Range iter() {
return Range(p_buf.data(), size());
}
ConstRange each() const {
ConstRange iter() const {
return ConstRange(p_buf.data(), size());
}
ConstRange ceach() const {
ConstRange citer() const {
return ConstRange(p_buf.data(), size());
}
@ -324,7 +324,7 @@ public:
}
Size to_hash() const {
return each().to_hash();
return iter().to_hash();
}
A get_allocator() const {
@ -359,7 +359,7 @@ static inline bool operator!=(const char *lhs, const String &rhs) {
template<typename T, typename F>
String concat(const T &v, const String &sep, F func) {
String ret;
auto range = octa::each(v);
auto range = octa::iter(v);
if (range.empty()) return ret;
for (;;) {
ret += func(range.front());
@ -373,7 +373,7 @@ String concat(const T &v, const String &sep, F func) {
template<typename T>
String concat(const T &v, const String &sep = " ") {
String ret;
auto range = octa::each(v);
auto range = octa::iter(v);
if (range.empty()) return ret;
for (;;) {
ret += range.front();
@ -386,12 +386,12 @@ String concat(const T &v, const String &sep = " ") {
template<typename T, typename F>
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>
String concat(std::initializer_list<T> v, const String &sep = " ") {
return concat(octa::each(v), sep);
return concat(octa::iter(v), sep);
}
namespace detail {
@ -421,8 +421,8 @@ template<typename T> struct ToString {
!octa::IsScalar<U>::value, bool> = true
) {
String ret("{");
ret += concat(octa::each(v), ", ", ToString<octa::RangeReference<
decltype(octa::each(v))
ret += concat(octa::iter(v), ", ", ToString<octa::RangeReference<
decltype(octa::iter(v))
>>());
ret += "}";
return ret;

View File

@ -382,16 +382,16 @@ public:
}
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);
}
ConstRange each() const {
ConstRange iter() const {
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);
}

View File

@ -27,7 +27,7 @@ int main() {
assert(x.data()[0] == x[0]);
auto r = x.each();
auto r = x.iter();
assert(r.front() == 2);
assert(r.back() == 32);

View File

@ -69,12 +69,12 @@ int main() {
assert(z[3] == 5);
assert(z.size() == 11);
auto r = z.each();
auto r = z.iter();
assert(r.front() == 5);
assert(r.back() == 5);
assert(r[2] == 4);
auto r2 = each(z);
auto r2 = iter(z);
assert(r.front() == r2.front());
Vector<int> w;