|
Medusa
1.1
Coordinate Free Mehless Method implementation
|
|
Go to the documentation of this file. 1 #ifndef MEDUSA_BITS_TYPES_RANGE_FWD_HPP_
2 #define MEDUSA_BITS_TYPES_RANGE_FWD_HPP_
29 template<
class T,
class Allocator = std::allocator<T>>
30 class Range :
public std::vector<T, Allocator> {
33 typedef typename std::vector<T, Allocator>::value_type
value_type;
35 typedef typename std::vector<T, Allocator>::reference
reference;
63 for (
int i = 0; i < sz; ++i) ret[i] =
operator[](i);
70 "Container sizes must match in multiindexed assignment, but my size is %d "
71 "and assigned size is %d.",
size(), rhs.
size());
72 for (
size_type i = 0; i <
size(); ++i)
operator[](i) = rhs[i];
120 for (
int i = 0; i < sz; ++i) ret[i] =
operator[](i);
139 using std::vector<T, Allocator>::vector;
140 using std::vector<T, Allocator>::operator=;
142 Range() : std::vector<T, Allocator>() {}
146 Range(
const std::vector<T, Allocator>& o) : std::vector<T, Allocator>(o) {}
149 Range(std::vector<T, Allocator>&& o) noexcept : std::vector<T, Allocator>(std::move(o)) {}
156 template <
typename V>
159 template <
typename V>
162 template <
typename V,
typename D>
163 static Range seq(V start, V stop, D step);
185 int size()
const {
return static_cast<int>(std::vector<T, Allocator>::size()); }
208 template<
class Predicate>
217 template<
typename UnaryOp>
218 auto map(UnaryOp op) ->
Range<decltype(op(this->
operator[](0)))>
const;
249 typedef typename std::vector<T>::value_type
type;
253 typedef typename std::vector<T>::value_type
type;
264 template<
class T,
class Allocator = std::allocator<T>>
265 std::vector<T, Allocator>
operator+(
const std::vector<T, Allocator>& v1,
266 const std::vector<T, Allocator>& v2) {
267 std::vector<T, Allocator> ret = v1;
268 ret.insert(ret.end(), v2.begin(), v2.end());
274 #endif // MEDUSA_BITS_TYPES_RANGE_FWD_HPP_
size_type size() const
Size of the sub-container.
reference operator[](size_type i)
Overload vector's [] to assert parameter.
indexes_t filter(const Predicate &predicate) const
Returns list of indexes for which predicate returns true.
indexes_t operator>=(const value_type &v) const
Returns list of indexes of elements that are greater or equal to v.
Root namespace for the whole library.
indexes_t operator!=(const value_type &v) const
Returns list of indexes of elements that are not equal to v.
Range(std::vector< T, Allocator > &&o) noexcept
Move Construct from std::vector.
std::vector< T, Allocator >::const_reference const_reference
This container's const reference to value type.
indexes_t operator<=(const value_type &v) const
Returns list of indexes of elements that are less or equal to v.
std::vector< T, Allocator >::reference reference
This container's reference to value type.
Range< T > asRange() const
Cast to underlying container type.
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.
RangeView(Range< T > &receiver_, const indexes_t &modifier_)
Constructor.
ConstRangeView(const Range< T > &receiver_, const indexes_t &modifier_)
Constructor.
This class represents a non contiguous view to a Range, allowing for read and write operations.
indexes_t operator<(const value_type &v) const
Returns list of indexes of elements that are less than v.
static Range seq(V n)
Returns range {0, ..., n-1}.
void operator=(const Range< T > &rhs)
Multiindex assignment: a[{1, 2, 3}] = Range<int>({1, 2, 3});.
std::vector< T >::value_type type
Underlying vector type.
indexes_t operator==(const value_type &v) const
Returns list of indexes of elements that are equal to v.
Range(const Range::ConstRangeView &o)
Construct from ConstRangeView.
#define assert_msg(cond,...)
Assert with better error reporting.
Range< T > asRange() const
Cast to underlying container type.
Range(const Range::RangeView &o)
Construct from RangeView.
std::vector< T >::value_type type
Underlying vector type.
Range< T >::value_type type
Underlying scalar type.
ConstRangeView & operator=(ConstRangeView &)=delete
Disallow copying.
std::vector< T, Allocator > operator+(const std::vector< T, Allocator > &v1, const std::vector< T, Allocator > &v2)
Concatenate two vectors.
std::vector< int > indexes_t
Class representing a collection of indices.
std::vector< T, Allocator >::value_type value_type
This container's value type.
size_type size() const
Size of the sub-container.
Range & operator=(const Range &o)=default
Default copy assignment.
Range< T > & receiver
Reference to object we are viewing / modifying.
int size_type
This container's size type.
Type trait for vector fields to obtain their underlying vector type.
void operator=(const value_type &x)
Multiindex value assignment: a = 4;.
indexes_t operator>(const value_type &v) const
Returns list of indexes of elements that are greater than v.
Range< T >::value_type type
Underlying scalar type.
RangeView & operator=(RangeView &)=delete
Disallow copying.
Range & append(const Range &rng)
Append all elements of rng to self.
const indexes_t & modifier
List of indexes of elements to modify.
const Range< T > & receiver
Reference to object we are viewing.
const_reference operator[](size_type i) const
Read access to sub-container elements.
int size() const
Returns number of elements.
friend std::ostream & operator<<(std::ostream &os, const RangeView &c)
Output a RangeView.
Range(const Range &o)=default
Default copy constructor.
Range join(const Range &rng) const
Return new copy containing this range's elements followed by all elements of rng.
friend std::ostream & operator<<(std::ostream &os, const ConstRangeView &c)
Output a ConstRangeView.
const_reference operator[](size_type i) const
Read access to sub-container elements.
An extension of std::vector<T> to support additional useful operations.
This class represents a non contiguous view to a Range, allowing for read-only operations.
Type trait for scalar fields to obtain their underlying scalar type.
void remove(indexes_t indexes)
Remove elements wih given indexes.
Range & operator+=(const Range &rng)
Operator version of Range::append.
const indexes_t & modifier
List of indexes of elements to modify.
reference operator[](size_type i)
Write access to sub-container elements.