https://mooseframework.inl.gov
Public Member Functions | Private Types | List of all members
MooseUtils::SemidynamicVector< T, N, value_init > Class Template Reference

Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size. More...

#include <MooseUtils.h>

Inheritance diagram for MooseUtils::SemidynamicVector< T, N, value_init >:
[legend]

Public Member Functions

 SemidynamicVector (std::size_t size)
 
void resize (std::size_t new_size)
 
void push_back (const T &v)
 
template<typename... Args>
void emplace_back (Args &&... args)
 
std::size_t max_size () const
 

Private Types

typedef MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
 

Detailed Description

template<typename T, std::size_t N, bool value_init = true>
class MooseUtils::SemidynamicVector< T, N, value_init >

Utility class template for a semidynamic vector with a maximum size N and a chosen dynamic size.

This container avoids heap allocation and is meant as a replacement for small local std::vector variables. By default this class uses value initialization. This can be disabled using the third template parameter if uninitialized storage is acceptable,

Definition at line 1074 of file MooseUtils.h.

Member Typedef Documentation

◆ Parent

template<typename T, std::size_t N, bool value_init = true>
typedef MetaPhysicL::DynamicStdArrayWrapper<T, MetaPhysicL::NWrapper<N> > MooseUtils::SemidynamicVector< T, N, value_init >::Parent
private

Definition at line 1076 of file MooseUtils.h.

Constructor & Destructor Documentation

◆ SemidynamicVector()

template<typename T, std::size_t N, bool value_init = true>
MooseUtils::SemidynamicVector< T, N, value_init >::SemidynamicVector ( std::size_t  size)
inline

Definition at line 1079 of file MooseUtils.h.

1079  : Parent()
1080  {
1081  Parent::resize(size);
1082  if constexpr (value_init)
1083  for (const auto i : make_range(size))
1084  _data[i] = T{};
1085  }
MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
Definition: MooseUtils.h:1076
IntRange< T > make_range(T beg, T end)

Member Function Documentation

◆ emplace_back()

template<typename T, std::size_t N, bool value_init = true>
template<typename... Args>
void MooseUtils::SemidynamicVector< T, N, value_init >::emplace_back ( Args &&...  args)
inline

Definition at line 1106 of file MooseUtils.h.

1107  {
1108  const auto old_dynamic_n = Parent::size();
1109  Parent::resize(old_dynamic_n + 1);
1110  (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1111  }

◆ max_size()

template<typename T, std::size_t N, bool value_init = true>
std::size_t MooseUtils::SemidynamicVector< T, N, value_init >::max_size ( ) const
inline

Definition at line 1113 of file MooseUtils.h.

1113 { return N; }

◆ push_back()

template<typename T, std::size_t N, bool value_init = true>
void MooseUtils::SemidynamicVector< T, N, value_init >::push_back ( const T &  v)
inline

Definition at line 1098 of file MooseUtils.h.

Referenced by AutomaticMortarGeneration::getNodalTangents().

1099  {
1100  const auto old_dynamic_n = Parent::size();
1101  Parent::resize(old_dynamic_n + 1);
1102  _data[old_dynamic_n] = v;
1103  }

◆ resize()

template<typename T, std::size_t N, bool value_init = true>
void MooseUtils::SemidynamicVector< T, N, value_init >::resize ( std::size_t  new_size)
inline

Definition at line 1087 of file MooseUtils.h.

1088  {
1089  [[maybe_unused]] const auto old_dynamic_n = Parent::size();
1090 
1091  Parent::resize(new_size);
1092 
1093  if constexpr (value_init)
1094  for (const auto i : make_range(old_dynamic_n, _dynamic_n))
1095  _data[i] = T{};
1096  }
IntRange< T > make_range(T beg, T end)

The documentation for this class was generated from the following file: