Medusa  1.1
Coordinate Free Mehless Method implementation
mm::Range< T, Allocator > Class Template Reference

#include <Range_fwd.hpp>

Detailed Description

template<class T, class Allocator = std::allocator<T>>
class mm::Range< T, Allocator >

An extension of std::vector<T> to support additional useful operations.

It only adds new methods, no new members, so destructing via base pointer is still safe (even though this usage is not intended).

Usage example:

Range<int> v = Range<int>::seq(100); // numbers from 0 to 99, inclusive
v[v.filter([](int x) { return x % 2 == 0; })] = 0; // set even to 0
v.remove(v > 80); // remove greater than 80
std::cout << v << std::endl;
Range<int> u(100, 4);
v.append(u); // append one range to another
std::cout << v + u << std::endl; // join two ranges and return result
Examples
test/spatial_search/KDTreeMutable_test.cpp.

Definition at line 30 of file Range_fwd.hpp.

+ Inheritance diagram for mm::Range< T, Allocator >:
+ Collaboration diagram for mm::Range< T, Allocator >:

Public Member Functions

 Range (const Range &o)=default
 Default copy constructor. More...
 
 Range (Range &&o) noexcept=default
 Default move constructor. More...
 
Rangeoperator= (const Range &o)=default
 Default copy assignment. More...
 
Rangeoperator= (Range &&o) noexcept=default
 Default move assignment. More...
 
 Range (const std::vector< T, Allocator > &o)
 Copy construct from std::vector. More...
 
 Range (std::vector< T, Allocator > &&o) noexcept
 Move Construct from std::vector. More...
 
 Range (const Range::RangeView &o)
 Construct from RangeView. More...
 
 Range (const Range::ConstRangeView &o)
 Construct from ConstRangeView. More...
 
Rangeoperator= (std::initializer_list< value_type > lst)
 Assign from initializer list: a = {1, 2, 3};. More...
 
Rangeoperator= (const value_type &x)
 Assign a single value to all elements: a = 4;. More...
 
reference operator[] (size_type i)
 Overload vector's [] to assert parameter. More...
 
const_reference operator[] (size_type i) const
 Overload vector's [] to assert parameter. More...
 
RangeView operator[] (const indexes_t &indexes)
 Multi-indexed access for writing. More...
 
ConstRangeView operator[] (const indexes_t &indexes) const
 Multi-indexed access for reading. More...
 
int size () const
 Returns number of elements. More...
 
Rangeappend (const Range &rng)
 Append all elements of rng to self. More...
 
Rangeoperator+= (const Range &rng)
 Operator version of Range::append. More...
 
Range join (const Range &rng) const
 Return new copy containing this range's elements followed by all elements of rng. More...
 
void remove (indexes_t indexes)
 Remove elements wih given indexes. More...
 
template<class Predicate >
indexes_t filter (const Predicate &predicate) const
 Returns list of indexes for which predicate returns true. More...
 
template<typename UnaryOp >
auto map (UnaryOp op) -> Range< decltype(op(this->operator[](0)))> const
 Returns a new range, obtained by applying op to all elements of this Range. More...
 
indexes_t operator< (const value_type &v) const
 Returns list of indexes of elements that are less than v. More...
 
indexes_t operator> (const value_type &v) const
 Returns list of indexes of elements that are greater than v. More...
 
indexes_t operator<= (const value_type &v) const
 Returns list of indexes of elements that are less or equal to v. More...
 
indexes_t operator>= (const value_type &v) const
 Returns list of indexes of elements that are greater or equal to v. More...
 
indexes_t operator== (const value_type &v) const
 Returns list of indexes of elements that are equal to v. More...
 
indexes_t operator!= (const value_type &v) const
 Returns list of indexes of elements that are not equal to v. More...
 

Static Public Member Functions

template<typename V >
static Range seq (V n)
 Returns range {0, ..., n-1}. More...
 
template<typename V >
static Range seq (V start, V stop)
 Returns range with integers in interval [start, stop). More...
 
template<typename V , typename D >
static Range seq (V start, V stop, D step)
 Returns range with integers in interval [start, stop) with step step. More...
 

Public Types

typedef std::vector< T, Allocator >::value_type value_type
 This container's value type. More...
 
typedef std::vector< T, Allocator >::reference reference
 This container's reference to value type. More...
 
typedef std::vector< T, Allocator >::const_reference const_reference
 This container's const reference to value type. More...
 
typedef int size_type
 This container's size type. More...
 

Classes

class  ConstRangeView
 This class represents a non contiguous view to a Range, allowing for read-only operations. More...
 
class  RangeView
 This class represents a non contiguous view to a Range, allowing for read and write operations. More...
 

Constructor & Destructor Documentation

◆ Range() [1/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( const Range< T, Allocator > &  o)
default

Default copy constructor.

◆ Range() [2/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( Range< T, Allocator > &&  o)
defaultnoexcept

Default move constructor.

◆ Range() [3/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( const std::vector< T, Allocator > &  o)
inline

Copy construct from std::vector.

Definition at line 147 of file Range_fwd.hpp.

◆ Range() [4/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( std::vector< T, Allocator > &&  o)
inlinenoexcept

Move Construct from std::vector.

Definition at line 149 of file Range_fwd.hpp.

◆ Range() [5/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( const Range< T, Allocator >::RangeView o)
inline

Construct from RangeView.

Definition at line 151 of file Range_fwd.hpp.

◆ Range() [6/6]

template<class T , class Allocator = std::allocator<T>>
mm::Range< T, Allocator >::Range ( const Range< T, Allocator >::ConstRangeView o)
inline

Construct from ConstRangeView.

Definition at line 153 of file Range_fwd.hpp.

Member Function Documentation

◆ append()

template<class T , class Allocator >
Range< T, Allocator > & mm::Range< T, Allocator >::append ( const Range< T, Allocator > &  rng)

Append all elements of rng to self.

Definition at line 66 of file Range.hpp.

◆ filter()

template<class T , class Allocator >
template<class Predicate >
indexes_t mm::Range< T, Allocator >::filter ( const Predicate &  predicate) const

Returns list of indexes for which predicate returns true.

Template Parameters
PredicateAny callable object, e.g. lambda func, functional, class with operator() defined. Example:
auto idxs = a.filter([](double v){ return 2.3 < v && v < 6.4; })];
returns all elements of a that are between 2.3 and 6.4.

Definition at line 101 of file Range.hpp.

◆ join()

template<class T , class Allocator >
Range< T, Allocator > mm::Range< T, Allocator >::join ( const Range< T, Allocator > &  rng) const

Return new copy containing this range's elements followed by all elements of rng.

Definition at line 72 of file Range.hpp.

◆ map()

template<class T , class Allocator >
template<typename UnaryOp >
auto mm::Range< T, Allocator >::map ( UnaryOp  op) -> Range<decltype(op(this->operator[](0)))> const

Returns a new range, obtained by applying op to all elements of this Range.

Template Parameters
UnaryOpAny callable object.
Parameters
opOperation mapping T -> Out type.
Returns
[a, b, c].map(f) -> [f(a), f(b), f(c)]

Definition at line 110 of file Range.hpp.

◆ operator!=()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator!= ( const value_type v) const

Returns list of indexes of elements that are not equal to v.

Definition at line 143 of file Range.hpp.

◆ operator+=()

template<class T , class Allocator = std::allocator<T>>
Range& mm::Range< T, Allocator >::operator+= ( const Range< T, Allocator > &  rng)
inline

Operator version of Range::append.

Definition at line 190 of file Range_fwd.hpp.

◆ operator<()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator< ( const value_type v) const

Returns list of indexes of elements that are less than v.

Definition at line 118 of file Range.hpp.

◆ operator<=()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator<= ( const value_type v) const

Returns list of indexes of elements that are less or equal to v.

Definition at line 128 of file Range.hpp.

◆ operator=() [1/4]

template<class T , class Allocator = std::allocator<T>>
Range& mm::Range< T, Allocator >::operator= ( const Range< T, Allocator > &  o)
default

Default copy assignment.

◆ operator=() [2/4]

template<class T , class Allocator >
Range< T, Allocator > & mm::Range< T, Allocator >::operator= ( const value_type x)

Assign a single value to all elements: a = 4;.

Definition at line 25 of file Range.hpp.

◆ operator=() [3/4]

template<class T , class Allocator = std::allocator<T>>
Range& mm::Range< T, Allocator >::operator= ( Range< T, Allocator > &&  o)
defaultnoexcept

Default move assignment.

◆ operator=() [4/4]

template<class T , class Allocator >
Range< T, Allocator > & mm::Range< T, Allocator >::operator= ( std::initializer_list< value_type lst)

Assign from initializer list: a = {1, 2, 3};.

Definition at line 15 of file Range.hpp.

◆ operator==()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator== ( const value_type v) const

Returns list of indexes of elements that are equal to v.

Definition at line 138 of file Range.hpp.

◆ operator>()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator> ( const value_type v) const

Returns list of indexes of elements that are greater than v.

Definition at line 123 of file Range.hpp.

◆ operator>=()

template<class T , class Allocator >
indexes_t mm::Range< T, Allocator >::operator>= ( const value_type v) const

Returns list of indexes of elements that are greater or equal to v.

Definition at line 133 of file Range.hpp.

◆ operator[]() [1/4]

template<class T , class Allocator >
Range< T, Allocator >::RangeView mm::Range< T, Allocator >::operator[] ( const indexes_t indexes)

Multi-indexed access for writing.

Definition at line 47 of file Range.hpp.

◆ operator[]() [2/4]

template<class T , class Allocator >
Range< T, Allocator >::ConstRangeView mm::Range< T, Allocator >::operator[] ( const indexes_t indexes) const

Multi-indexed access for reading.

Definition at line 57 of file Range.hpp.

◆ operator[]() [3/4]

template<class T , class Allocator >
Range< T, Allocator >::reference mm::Range< T, Allocator >::operator[] ( size_type  i)

Overload vector's [] to assert parameter.

Definition at line 33 of file Range.hpp.

◆ operator[]() [4/4]

template<class T , class Allocator >
Range< T, Allocator >::const_reference mm::Range< T, Allocator >::operator[] ( size_type  i) const

Overload vector's [] to assert parameter.

Definition at line 40 of file Range.hpp.

◆ remove()

template<class T , class Allocator >
void mm::Range< T, Allocator >::remove ( indexes_t  indexes)

Remove elements wih given indexes.

Definition at line 79 of file Range.hpp.

◆ seq() [1/3]

template<class T , class Allocator = std::allocator<T>>
template<typename V >
static Range mm::Range< T, Allocator >::seq ( n)
static

Returns range {0, ..., n-1}.

Examples
test/types/Range_test.cpp.

◆ seq() [2/3]

template<class T , class Allocator = std::allocator<T>>
template<typename V >
static Range mm::Range< T, Allocator >::seq ( start,
stop 
)
static

Returns range with integers in interval [start, stop).

◆ seq() [3/3]

template<class T , class Allocator = std::allocator<T>>
template<typename V , typename D >
static Range mm::Range< T, Allocator >::seq ( start,
stop,
step 
)
static

Returns range with integers in interval [start, stop) with step step.

◆ size()

template<class T , class Allocator = std::allocator<T>>
int mm::Range< T, Allocator >::size ( ) const
inline

Returns number of elements.

Note
This function returns signed type, contrary to std::vector::size.

Definition at line 185 of file Range_fwd.hpp.


The documentation for this class was generated from the following files:
mm::Range::seq
static Range seq(V n)
Returns range {0, ..., n-1}.