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() );
76 auto reserved =
vec_.capacity();
77 if ( reserved > 0 && newSize > reserved )
79 while ( newSize > reserved )
81 vec_.reserve( reserved );
83 vec_.resize( newSize, value );
91 if (
const auto sz =
size(); p + len > sz )
98 for (
size_t i = 0; i < len; ++i )
106 if ( i + 1 >
size() )
115 template<
typename... Args>
116 T&
emplace_back( Args&&... args ) {
return vec_.emplace_back( std::forward<Args>(args)... ); }
123 [[nodiscard]]
I beginId()
const {
return I(
size_t(0) ); }
130 [[nodiscard]]
const T*
data()
const {
return vec_.data(); }
140#if defined( MR_PARSING_FOR_PB11_BINDINGS ) || defined( MR_COMPILING_PB11_BINDINGS )
141 static_assert(
sizeof(T) > 0 );
145template <
typename T,
typename I>
147 {
return a.
vec_.begin(); }
149template <
typename T,
typename I>
151 {
return a.
vec_.begin(); }
153template <
typename T,
typename I>
155 {
return a.
vec_.end(); }
157template <
typename T,
typename I>
159 {
return a.
vec_.end(); }
162template <
typename T,
typename I>
165 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:113
void clear()
Definition MRMesh/MRVector.h:39
reference front()
Definition MRMesh/MRVector.h:119
typename std::vector< T >::iterator iterator
Definition MRMesh/MRVector.h:25
void autoResizeSet(I i, T val)
Definition MRMesh/MRVector.h:101
std::size_t size() const
Definition MRMesh/MRVector.h:42
std::size_t capacity() const
Definition MRMesh/MRVector.h:59
void resize(size_t newSize) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:44
reference autoResizeAt(I i) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
this accessor automatically adjusts the size of the vector
Definition MRMesh/MRVector.h:104
reference operator[](I i)
Definition MRMesh/MRVector.h:67
void resizeWithReserve(size_t newSize, const T &value=T())
doubles reserved memory until resize(newSize) can be done without reallocation
Definition MRMesh/MRVector.h:74
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:87
T * data()
Definition MRMesh/MRVector.h:129
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:123
void push_back(const T &t)
Definition MRMesh/MRVector.h:111
void resizeNoInit(size_t targetSize) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:48
size_t heapBytes() const
returns the amount of memory this object occupies on heap
Definition MRMesh/MRVector.h:135
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:125
Vector(std::initializer_list< T > init)
Definition MRMesh/MRVector.h:34
bool operator!=(const Vector &b) const MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:37
reference back()
Definition MRMesh/MRVector.h:121
typename std::vector< T >::const_reference const_reference
Definition MRMesh/MRVector.h:24
const T * data() const
Definition MRMesh/MRVector.h:130
typename std::vector< T >::value_type value_type
Definition MRMesh/MRVector.h:22
bool operator==(const Vector &b) const MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:36
bool empty() const
Definition MRMesh/MRVector.h:40
Vector(size_t size, const T &val)
Definition MRMesh/MRVector.h:30
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:138
void swap(Vector &b)
Definition MRMesh/MRVector.h:132
void resize(size_t newSize, const T &t) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:45
const_reference front() const
Definition MRMesh/MRVector.h:118
Vector(size_t size) MR_REQUIRES_IF_SUPPORTED(sizeof(T)>0 &&std
Definition MRMesh/MRVector.h:29
void push_back(T &&t)
Definition MRMesh/MRVector.h:112
T & emplace_back(Args &&... args)
Definition MRMesh/MRVector.h:116
const_reference back() const
Definition MRMesh/MRVector.h:120
I endId() const
returns backId() + 1
Definition MRMesh/MRVector.h:127
auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:280
auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:282
Definition MRCameraOrientationPlugin.h:8
T getAt(const Buffer< T, I > &bmap, I key)
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:57
I
Definition MRMesh/MRMeshFwd.h:88