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 1096 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 1098 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 1101 of file MooseUtils.h.

1101  : Parent()
1102  {
1103  Parent::resize(size);
1104  if constexpr (value_init)
1105  for (const auto i : make_range(size))
1106  _data[i] = T{};
1107  }
MetaPhysicL::DynamicStdArrayWrapper< T, MetaPhysicL::NWrapper< N > > Parent
Definition: MooseUtils.h:1098
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 1128 of file MooseUtils.h.

1129  {
1130  const auto old_dynamic_n = Parent::size();
1131  Parent::resize(old_dynamic_n + 1);
1132  (::new (&_data[old_dynamic_n]) T(std::forward<Args>(args)...));
1133  }

◆ 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 1135 of file MooseUtils.h.

1135 { 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 1120 of file MooseUtils.h.

Referenced by AutomaticMortarGeneration::getNodalTangents().

1121  {
1122  const auto old_dynamic_n = Parent::size();
1123  Parent::resize(old_dynamic_n + 1);
1124  _data[old_dynamic_n] = v;
1125  }

◆ 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 1109 of file MooseUtils.h.

1110  {
1111  [[maybe_unused]] const auto old_dynamic_n = Parent::size();
1112 
1113  Parent::resize(new_size);
1114 
1115  if constexpr (value_init)
1116  for (const auto i : make_range(old_dynamic_n, _dynamic_n))
1117  _data[i] = T{};
1118  }
IntRange< T > make_range(T beg, T end)

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