5#include "MRPch/MRBindingMacros.h"
18template <
typename T,
typename I>
23 using reference =
typename std::vector<T>::reference;
25 using iterator =
typename std::vector<T>::iterator;
31 Vector( std::vector<T> && vec ) :
vec_( std::move( vec ) ) { }
32 template<
class InputIt >
33 Vector( InputIt first, InputIt last ) :
vec_( first, last ) { }
34 Vector( std::initializer_list<T> init ) :
vec_( init ) { }
40 [[nodiscard]]
bool empty()
const {
return vec_.empty(); }
42 [[nodiscard]] std::size_t
size()
const {
return vec_.size(); }
53 while (
size() < targetSize )
59 [[nodiscard]] std::size_t
capacity()
const {
return vec_.capacity(); }
64 assert( i <
vec_.size() );
69 assert( i <
vec_.size() );
83 auto reserved =
vec_.capacity();
84 if ( reserved > 0 && newSize > reserved )
86 while ( newSize > reserved )
88 vec_.reserve( reserved );
90 vec_.resize( newSize, value );
98 if (
const auto sz =
size(); p + len > sz )
105 for (
size_t i = 0; i < len; ++i )
113 if ( i + 1 >
size() )
122 template<
typename... Args>
123 T&
emplace_back( Args&&... args ) {
return vec_.emplace_back( std::forward<Args>(args)... ); }
130 [[nodiscard]]
I beginId()
const {
return I(
size_t(0) ); }
137 [[nodiscard]]
const T*
data()
const {
return vec_.data(); }
147#if defined( MR_PARSING_FOR_PB11_BINDINGS ) || defined( MR_COMPILING_PB11_BINDINGS )
148 static_assert(
sizeof(T) > 0 );
152template <
typename T,
typename I>
154 {
return a.
vec_.begin(); }
156template <
typename T,
typename I>
158 {
return a.
vec_.begin(); }
160template <
typename T,
typename I>
162 {
return a.
vec_.end(); }
164template <
typename T,
typename I>
166 {
return a.
vec_.end(); }
169template <
typename T,
typename I>
172 return (
id &&
id < a.
size() ) ? a[id] : def;
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:29
std::vector<T>-like container that requires specific indexing type,
Definition MRMesh/MRVector.h:20
void pop_back()
Definition MRMesh/MRVector.h:120
void clear()
Definition MRMesh/MRVector.h:39
reference front()
Definition MRMesh/MRVector.h:126
typename std::vector< T >::iterator iterator
Definition MRMesh/MRVector.h:25
void autoResizeSet(I i, T val)
Definition MRMesh/MRVector.h:108
std::size_t size() const
Definition MRMesh/MRVector.h:42
std::size_t capacity() const
Definition MRMesh/MRVector.h:59
bool operator==(const Vector &b) const
Definition MRMesh/MRVector.h:36
void resizeWithReserve(size_t newSize)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRVector.h:74
reference operator[](I i)
Definition MRMesh/MRVector.h:67
typename std::vector< T >::reference reference
Definition MRMesh/MRVector.h:23
void autoResizeSet(I pos, size_t len, T val)
sets elements [pos, pos+len) to given value, adjusting the size of the vector to include new elements
Definition MRMesh/MRVector.h:94
T * data()
Definition MRMesh/MRVector.h:136
Vector(InputIt first, InputIt last)
Definition MRMesh/MRVector.h:33
Vector(std::vector< T > &&vec)
Definition MRMesh/MRVector.h:31
void reserve(size_t capacity)
Definition MRMesh/MRVector.h:60
I beginId() const
returns the identifier of the first element
Definition MRMesh/MRVector.h:130
void resizeNoInit(size_t targetSize)
Definition MRMesh/MRVector.h:48
void push_back(const T &t)
Definition MRMesh/MRVector.h:118
Vector(size_t size)
Definition MRMesh/MRVector.h:29
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRVector.h:142
const_reference operator[](I i) const
Definition MRMesh/MRVector.h:62
I backId() const
returns the identifier of the back() element
Definition MRMesh/MRVector.h:132
Vector(std::initializer_list< T > init)
Definition MRMesh/MRVector.h:34
reference back()
Definition MRMesh/MRVector.h:128
typename std::vector< T >::const_reference const_reference
Definition MRMesh/MRVector.h:24
void resizeWithReserve(size_t newSize, const T &value)
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRVector.h:81
const T * data() const
Definition MRMesh/MRVector.h:137
typename std::vector< T >::value_type value_type
Definition MRMesh/MRVector.h:22
bool empty() const
Definition MRMesh/MRVector.h:40
bool operator!=(const Vector &b) const
Definition MRMesh/MRVector.h:37
Vector(size_t size, const T &val)
Definition MRMesh/MRVector.h:30
void resize(size_t newSize)
Definition MRMesh/MRVector.h:44
reference autoResizeAt(I i)
this accessor automatically adjusts the size of the vector
Definition MRMesh/MRVector.h:111
typename std::vector< T >::const_iterator const_iterator
Definition MRMesh/MRVector.h:26
std::vector< T > vec_
the user can directly manipulate the vector, anyway she cannot break anything
Definition MRMesh/MRVector.h:145
void resize(size_t newSize, const T &t)
Definition MRMesh/MRVector.h:45
void swap(Vector &b)
Definition MRMesh/MRVector.h:139
const_reference front() const
Definition MRMesh/MRVector.h:125
void push_back(T &&t)
Definition MRMesh/MRVector.h:119
T & emplace_back(Args &&... args)
Definition MRMesh/MRVector.h:123
const_reference back() const
Definition MRMesh/MRVector.h:127
I endId() const
returns backId() + 1
Definition MRMesh/MRVector.h:134
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:286
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:288
T getAt(const Buffer< T, I > &bmap, I key, T def={})
given some buffer map and a key, returns the value associated with the key, or default value if key i...
Definition MRBuffer.h:119
constexpr NoInit noInit
Definition MRMesh/MRMeshFwd.h:79
I
Definition MRMesh/MRMeshFwd.h:110