bsnes/nall/range.hpp
Tim Allen 213879771e Update to v094r41 release (open beta).
byuu says:

Changelog (since the last open beta):
- icarus is now included. icarus is used to import game files/archives
  into game paks (folders)
- SNES: mid-scanline BGMODE changes now emulated correctly (used only by
  atx2.smc Anthrox Demo)
- GBA: fixed a CPU bug that was causing dozens of games to have
  distorted audio
- GBA: fixed default FlashROM ID; should allow much higher compatibility
- GBA: now using Cydrak's new, much improved, GBA color emulation filter
  (still a work-in-progress)
- re-added command-line loading support for game paks (not for game
  files/archives, sorry!)
- Qt port now compiles and runs again (may be a little buggy;
  Windows/GTK+ ports preferred)
- SNES performance profile now compiles and runs again
- much more
2015-08-21 20:57:03 +10:00

54 lines
1.3 KiB
C++

#ifndef NALL_RANGE_HPP
#define NALL_RANGE_HPP
namespace nall {
struct range_t {
struct iterator {
iterator(signed position, signed step = 0) : position(position), step(step) {}
auto operator*() const -> signed { return position; }
auto operator!=(const iterator& source) const -> bool { return step > 0 ? position < source.position : position > source.position; }
auto operator++() -> iterator& { position += step; return *this; }
private:
signed position;
const signed step;
};
auto begin() const -> const iterator { return iterator(origin, stride); }
auto end() const -> const iterator { return iterator(target); }
signed origin;
signed target;
signed stride;
};
inline auto range(signed size) {
return range_t{0, size, 1};
}
inline auto range(signed offset, signed size) {
return range_t{offset, size, 1};
}
inline auto range(signed offset, signed size, signed step) {
return range_t{offset, size, step};
}
//reverse-range
inline auto rrange(signed size) {
return range_t{size - 1, -1, -1};
}
template<typename T> inline auto range(const vector<T>& container) {
return range_t{0, (signed)container.size(), 1};
}
template<typename T> inline auto rrange(const vector<T>& container) {
return range_t{(signed)container.size() - 1, -1, -1};
}
}
#endif