40#ifndef GEOGRAM_BASIC_RANGE
41#define GEOGRAM_BASIC_RANGE
66 class index_as_iterator {
68 index_as_iterator(
index_t val) : val_(val) {
75 bool operator==(index_as_iterator rhs)
const {
76 return val_ == rhs.val_;
79 bool operator!=(index_as_iterator rhs)
const {
80 return val_ != rhs.val_;
83 bool operator<(index_as_iterator rhs)
const {
84 return val_ < rhs.val_;
91 index_t operator-(index_as_iterator it)
const {
92 return val_ - it.val_;
95 index_as_iterator operator+(
index_t i)
const {
96 return index_as_iterator(val_ + i);
119 ) : begin_(b), end_(e) {
143 return end_ - begin_;
153 return *(begin_ + i);
167 class const_index_ptr_in_array {
169 const_index_ptr_in_array(
185 bool operator==(const_index_ptr_in_array rhs)
const {
186 return ptr_ == rhs.ptr_;
189 bool operator!=(const_index_ptr_in_array rhs)
const {
190 return ptr_ != rhs.ptr_;
193 bool operator<(const_index_ptr_in_array rhs)
const {
194 return ptr_ < rhs.ptr_;
197 const index_t& operator*()
const {
202 index_t operator-(const_index_ptr_in_array it)
const {
203 return index_t(ptr_ - it.ptr_);
206 const_index_ptr_in_array operator+(
index_t i)
const {
208 return const_index_ptr_in_array(ptr_ + i, begin_, end_);
210 return const_index_ptr_in_array(ptr_ + i,
nullptr,
nullptr);
228 class index_ptr_in_array {
246 bool operator==(index_ptr_in_array rhs)
const {
247 return ptr_ == rhs.ptr_;
250 bool operator!=(index_ptr_in_array rhs)
const {
251 return ptr_ != rhs.ptr_;
254 bool operator<(index_ptr_in_array rhs)
const {
255 return ptr_ < rhs.ptr_;
258 const index_t& operator*()
const {
268 index_t operator-(index_ptr_in_array it)
const {
269 return index_t(ptr_ - it.ptr_);
272 index_ptr_in_array operator+(
index_t i)
const {
274 return index_ptr_in_array(ptr_ + i, begin_, end_);
276 return index_ptr_in_array(ptr_ + i,
nullptr,
nullptr);
298 class index_ptr_range {
304 begin_(begin, begin, end),
305 end_(end,begin,end) {
321 const_iterator begin()
const {
325 const_iterator end()
const {
336 class const_index_ptr_range {
342 begin_(begin, begin, end),
343 end_(end,begin,end) {
351 const_iterator begin()
const {
355 const_iterator end()
const {
360 const_iterator begin_;
376 template<
class IT,
typename XFORM>
class transformed_iterator {
378 typedef transformed_iterator<IT, XFORM> thisclass;
380 transformed_iterator(
const IT& it, XFORM xform) :
381 wrapped_(it), xform_(xform) {
384 auto operator*()
const {
385 return xform_(*wrapped_);
388 bool operator==(
const thisclass& rhs)
const {
389 return wrapped_ == rhs.wrapped_;
392 bool operator!=(
const thisclass& rhs)
const {
393 return wrapped_ != rhs.wrapped_;
396 bool operator<(
const thisclass& rhs)
const {
397 return wrapped_ < rhs.wrapped_;
416 template<
class IT,
typename XFORM>
class transformed_iterator_ref {
418 typedef transformed_iterator_ref<IT, XFORM> thisclass;
420 transformed_iterator_ref(
const IT& it, XFORM xform) :
421 wrapped_(it), xform_(xform) {
425 return xform_(*wrapped_);
428 const auto& operator*()
const {
429 return xform_(*wrapped_);
432 bool operator==(
const thisclass& rhs)
const {
433 return wrapped_ == rhs.wrapped_;
436 bool operator!=(
const thisclass& rhs)
const {
437 return wrapped_ != rhs.wrapped_;
440 bool operator<(
const thisclass& rhs)
const {
441 return wrapped_ < rhs.wrapped_;
461 template<
class RANGE,
typename XFORM>
class transformed_range {
466 typename RANGE::const_iterator, XFORM
469 transformed_range(
const RANGE& range, XFORM xform) :
470 wrapped_(range), xform_(xform) {
474 return iterator(wrapped_.begin(), xform_);
478 return iterator(wrapped_.end(), xform_);
481 const_iterator begin()
const {
482 return const_iterator(wrapped_.begin(), xform_);
485 const_iterator end()
const {
486 return const_iterator(wrapped_.end(), xform_);
504 template<
class RANGE,
typename XFORM>
class transformed_range_ref {
507 typename RANGE::iterator, XFORM
511 typename RANGE::const_iterator, XFORM
514 transformed_range_ref(
const RANGE& range, XFORM xform) :
515 wrapped_(range), xform_(xform) {
519 return iterator(wrapped_.begin(), xform_);
523 return iterator(wrapped_.end(), xform_);
526 const_iterator begin()
const {
527 return const_iterator(wrapped_.begin(), xform_);
530 const_iterator end()
const {
531 return const_iterator(wrapped_.end(), xform_);
551 template <
class RANGE,
typename XFORM>
inline auto
568 template <
class RANGE,
typename XFORM>
inline auto
A function to suppress unused parameters compilation warnings.
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Encapsulates a const pointer to an element in an index_t array.
Wraps an integer to be used with the range-based for construct.
Encapsulates a pointer to an element in an index_t array.
index_t nb() const
gets the number of elements in the index_range
index_as_iterator end() const
gets one position past the last index
index_range(index_as_iterator b, index_as_iterator e)
index_range constructor
index_t operator[](index_t i) const
direct access to an arbitrary element in the index_range
index_as_iterator begin() const
gets the first index
Vector with aligned memory allocation.
T * data()
Gets a pointer to the array of elements.
Types and functions for memory manipulation.
Global Vorpaline namespace.
auto transform_range_ref(const RANGE &range, XFORM xform)
Creates a range that applies a user-defined function to each element when accessed.
void geo_argused(const T &)
Suppresses compiler warnings about unused parameters.
auto transform_range(const RANGE &range, XFORM xform)
Creates a range that applies a user-defined function to each element when accessed.
geo_index_t index_t
The type for storing and manipulating indices.
Types and functions for numbers manipulation.