MeshLib C++ Docs
Loading...
Searching...
No Matches
MRResizeNoInit.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRMacros.h"
5#include <concepts>
6
7namespace MR
8{
9
13template <typename T>
14void resizeNoInit( std::vector<T> & vec, size_t targetSize ) MR_REQUIRES_IF_SUPPORTED( sizeof( T ) > 0 && std::constructible_from<T, NoInit> )
15{
16 // allocate enough memory
17 vec.reserve( targetSize );
18 // resize without memory access
19 while ( vec.size() < targetSize )
20 vec.emplace_back( noInit );
21 // in case initial size was larger
22 vec.resize( targetSize );
23}
24
25} //namespace MR
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:31
Definition MRCameraOrientationPlugin.h:8
constexpr NoInit noInit
Definition MRMesh/MRMeshFwd.h:90
void resizeNoInit(std::vector< T > &vec, size_t targetSize)
Definition MRResizeNoInit.h:14