CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
edm::VecArray< T, N > Class Template Reference

#include <VecArray.h>

Public Types

using const_iterator = const value_type *
 
using const_pointer = const value_type *
 
using const_reference = const value_type &
 
using difference_type = std::ptrdiff_t
 
using iterator = value_type *
 
using pointer = value_type *
 
using reference = value_type &
 
using size_type = unsigned int
 
using value_type = T
 

Public Member Functions

reference back ()
 
const_reference back () const
 
const_iterator begin () const noexcept
 
iterator begin () noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
void clear ()
 
pointer data ()
 
const_pointer data () const
 
template<typename... Args>
void emplace_back (Args &&... args)
 
template<typename... Args>
void emplace_back_unchecked (Args &&... args)
 
constexpr bool empty () const noexcept
 
const_iterator end () const noexcept
 
iterator end () noexcept
 
reference front ()
 
const_reference front () const
 
reference operator[] (size_type pos)
 
const_reference operator[] (size_type pos) const
 
void pop_back ()
 
void push_back (const T &value)
 
void push_back_unchecked (const T &value)
 
void resize (unsigned int size)
 
constexpr size_type size () const noexcept
 
void swap (VecArray &other) noexcept(noexcept(std::swap(data_, other.data_)) &&noexcept(std::swap(size_, other.size_)))
 
 VecArray ()
 

Static Public Member Functions

static constexpr size_type capacity () noexcept
 

Private Attributes

T data_ [N]
 
unsigned int size_
 

Detailed Description

template<typename T, unsigned int N>
class edm::VecArray< T, N >

A class for extending std::array with std::vector-like interface.

This class can be useful if the maximum length is known at compile-time (can use std::array), and that the length is rather small (maximum size of std::array is comparable with the overhead of std::vector). It is also free of dynamic memory allocations.

Note that the implemented interface is not complete compared to std::array or std:vector. Feel free contribute if further needs arise.

The second template argument is unsigned int (not size_t) on purpose to reduce the size of the class by 4 bytes (at least in Linux amd64). For all practical purposes even unsigned char could be enough.

Definition at line 28 of file VecArray.h.

Member Typedef Documentation

◆ const_iterator

template<typename T, unsigned int N>
using edm::VecArray< T, N >::const_iterator = const value_type*

Definition at line 41 of file VecArray.h.

◆ const_pointer

template<typename T, unsigned int N>
using edm::VecArray< T, N >::const_pointer = const value_type*

Definition at line 39 of file VecArray.h.

◆ const_reference

template<typename T, unsigned int N>
using edm::VecArray< T, N >::const_reference = const value_type&

Definition at line 37 of file VecArray.h.

◆ difference_type

template<typename T, unsigned int N>
using edm::VecArray< T, N >::difference_type = std::ptrdiff_t

Definition at line 35 of file VecArray.h.

◆ iterator

template<typename T, unsigned int N>
using edm::VecArray< T, N >::iterator = value_type*

Definition at line 40 of file VecArray.h.

◆ pointer

template<typename T, unsigned int N>
using edm::VecArray< T, N >::pointer = value_type*

Definition at line 38 of file VecArray.h.

◆ reference

template<typename T, unsigned int N>
using edm::VecArray< T, N >::reference = value_type&

Definition at line 36 of file VecArray.h.

◆ size_type

template<typename T, unsigned int N>
using edm::VecArray< T, N >::size_type = unsigned int

Definition at line 34 of file VecArray.h.

◆ value_type

template<typename T, unsigned int N>
using edm::VecArray< T, N >::value_type = T

Definition at line 33 of file VecArray.h.

Constructor & Destructor Documentation

◆ VecArray()

template<typename T, unsigned int N>
edm::VecArray< T, N >::VecArray ( )
inline

Definition at line 43 of file VecArray.h.

43 : data_{}, size_{0} {}

Member Function Documentation

◆ back() [1/2]

template<typename T, unsigned int N>
reference edm::VecArray< T, N >::back ( )
inline

Definition at line 55 of file VecArray.h.

55 { return data_[size_ - 1]; }

◆ back() [2/2]

template<typename T, unsigned int N>
const_reference edm::VecArray< T, N >::back ( ) const
inline

Definition at line 57 of file VecArray.h.

57 { return data_[size_ - 1]; }

◆ begin() [1/2]

template<typename T, unsigned int N>
const_iterator edm::VecArray< T, N >::begin ( void  ) const
inlinenoexcept

Definition at line 62 of file VecArray.h.

62 { return data_; }

◆ begin() [2/2]

template<typename T, unsigned int N>
iterator edm::VecArray< T, N >::begin ( void  )
inlinenoexcept

Definition at line 61 of file VecArray.h.

61 { return data_; }

Referenced by edm::VecArray< std::pair< int, int >, 9 >::end().

◆ capacity()

template<typename T, unsigned int N>
static constexpr size_type edm::VecArray< T, N >::capacity ( )
inlinestaticconstexprnoexcept

Definition at line 71 of file VecArray.h.

71 { return N; }

Referenced by ClusterShapeHitFilter::getSizes().

◆ cbegin()

template<typename T, unsigned int N>
const_iterator edm::VecArray< T, N >::cbegin ( ) const
inlinenoexcept

Definition at line 63 of file VecArray.h.

63 { return data_; }

Referenced by edm::VecArray< std::pair< int, int >, 9 >::cend().

◆ cend()

template<typename T, unsigned int N>
const_iterator edm::VecArray< T, N >::cend ( ) const
inlinenoexcept

Definition at line 67 of file VecArray.h.

67 { return cbegin() + size_; }

◆ clear()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::clear ( void  )
inline

Definition at line 73 of file VecArray.h.

73 { size_ = 0; }

Referenced by ClusterShapeHitFilter::getSizes().

◆ data() [1/2]

template<typename T, unsigned int N>
pointer edm::VecArray< T, N >::data ( )
inline

Definition at line 58 of file VecArray.h.

58 { return data_; }

◆ data() [2/2]

template<typename T, unsigned int N>
const_pointer edm::VecArray< T, N >::data ( ) const
inline

Definition at line 59 of file VecArray.h.

59 { return data_; }

◆ emplace_back()

template<typename T, unsigned int N>
template<typename... Args>
void edm::VecArray< T, N >::emplace_back ( Args &&...  args)
inline

Definition at line 90 of file VecArray.h.

90  {
91  if (size_ >= N)
92  throw std::length_error("emplace_back on already-full VecArray (N=" + std::to_string(N) + ")");
93  emplace_back_unchecked(std::forward<Args>(args)...);
94  }

Referenced by ClusterTPAssociation::addKeyID(), PixelInactiveAreaFinder::InactiveAreas::areasAndLayerSets(), and PixelInactiveAreaFinder::InactiveAreas::spansAndLayerSets().

◆ emplace_back_unchecked()

template<typename T, unsigned int N>
template<typename... Args>
void edm::VecArray< T, N >::emplace_back_unchecked ( Args &&...  args)
inline

Definition at line 98 of file VecArray.h.

98  {
99  data_[size_] = T(std::forward<Args>(args)...);
100  ++size_;
101  }

Referenced by edm::VecArray< std::pair< int, int >, 9 >::emplace_back().

◆ empty()

template<typename T, unsigned int N>
constexpr bool edm::VecArray< T, N >::empty ( void  ) const
inlineconstexprnoexcept

Definition at line 69 of file VecArray.h.

69 { return size_ == 0; }

◆ end() [1/2]

template<typename T, unsigned int N>
const_iterator edm::VecArray< T, N >::end ( void  ) const
inlinenoexcept

Definition at line 66 of file VecArray.h.

66 { return begin() + size_; }

◆ end() [2/2]

template<typename T, unsigned int N>
iterator edm::VecArray< T, N >::end ( void  )
inlinenoexcept

Definition at line 65 of file VecArray.h.

65 { return begin() + size_; }

◆ front() [1/2]

template<typename T, unsigned int N>
reference edm::VecArray< T, N >::front ( )
inline

Definition at line 50 of file VecArray.h.

50 { return data_[0]; }

Referenced by PixelClusterShapeExtractor::processRec().

◆ front() [2/2]

template<typename T, unsigned int N>
const_reference edm::VecArray< T, N >::front ( ) const
inline

Definition at line 52 of file VecArray.h.

52 { return data_[0]; }

◆ operator[]() [1/2]

template<typename T, unsigned int N>
reference edm::VecArray< T, N >::operator[] ( size_type  pos)
inline

Definition at line 46 of file VecArray.h.

46 { return data_[pos]; }

◆ operator[]() [2/2]

template<typename T, unsigned int N>
const_reference edm::VecArray< T, N >::operator[] ( size_type  pos) const
inline

Definition at line 48 of file VecArray.h.

48 { return data_[pos]; }

◆ pop_back()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::pop_back ( )
inline

Definition at line 104 of file VecArray.h.

104 { --size_; }

Referenced by edm::VecArray< std::pair< int, int >, 9 >::resize().

◆ push_back()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::push_back ( const T value)
inline

Definition at line 76 of file VecArray.h.

76  {
77  if (size_ >= N)
78  throw std::length_error("push_back on already-full VecArray (N=" + std::to_string(N) + ")");
80  }

◆ push_back_unchecked()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::push_back_unchecked ( const T value)
inline

Definition at line 83 of file VecArray.h.

83  {
84  data_[size_] = value;
85  ++size_;
86  }

Referenced by ClusterShapeHitFilter::getSizes(), and edm::VecArray< std::pair< int, int >, 9 >::push_back().

◆ resize()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::resize ( unsigned int  size)
inline

Definition at line 106 of file VecArray.h.

106  {
107  if (size > N)
108  throw std::length_error("Requesting size " + std::to_string(size) + " while maximum allowed is " +
109  std::to_string(N));
110 
111  while (size < size_)
112  pop_back();
113  size_ = size;
114  }

◆ size()

template<typename T, unsigned int N>
constexpr size_type edm::VecArray< T, N >::size ( void  ) const
inlineconstexprnoexcept

◆ swap()

template<typename T, unsigned int N>
void edm::VecArray< T, N >::swap ( VecArray< T, N > &  other)
inlinenoexcept

Definition at line 116 of file VecArray.h.

117  {
118  std::swap(data_, other.data_);
119  std::swap(size_, other.size_);
120  }

Member Data Documentation

◆ data_

template<typename T, unsigned int N>
T edm::VecArray< T, N >::data_[N]
private

◆ size_

template<typename T, unsigned int N>
unsigned int edm::VecArray< T, N >::size_
private
writedatasetfile.args
args
Definition: writedatasetfile.py:18
pos
Definition: PixelAliasList.h:18
edm::VecArray::begin
iterator begin() noexcept
Definition: VecArray.h:61
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
N
#define N
Definition: blowfish.cc:9
trackingPlots.other
other
Definition: trackingPlots.py:1464
edm::VecArray::data_
T data_[N]
Definition: VecArray.h:29
value
Definition: value.py:1
edm::VecArray::emplace_back_unchecked
void emplace_back_unchecked(Args &&... args)
Definition: VecArray.h:98
edm::VecArray::push_back_unchecked
void push_back_unchecked(const T &value)
Definition: VecArray.h:83
edm::VecArray::pop_back
void pop_back()
Definition: VecArray.h:104
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
edm::VecArray::size
constexpr size_type size() const noexcept
Definition: VecArray.h:70
edm::VecArray::cbegin
const_iterator cbegin() const noexcept
Definition: VecArray.h:63
edm::VecArray::size_
unsigned int size_
Definition: VecArray.h:30