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
 
iterator begin () noexcept
 
const_iterator begin () const 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
 
iterator end () noexcept
 
const_iterator end () const 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} {}
unsigned int size_
Definition: VecArray.h:30
T data_[N]
Definition: VecArray.h:29

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]; }
unsigned int size_
Definition: VecArray.h:30
T data_[N]
Definition: VecArray.h:29

◆ 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]; }
unsigned int size_
Definition: VecArray.h:30
T data_[N]
Definition: VecArray.h:29

◆ begin() [1/2]

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

Definition at line 61 of file VecArray.h.

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

61 { return data_; }
T data_[N]
Definition: VecArray.h:29

◆ begin() [2/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_; }
T data_[N]
Definition: VecArray.h:29

◆ capacity()

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

Definition at line 71 of file VecArray.h.

Referenced by ClusterShapeHitFilter::getSizes().

71 { return N; }
#define N
Definition: blowfish.cc:9

◆ cbegin()

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

Definition at line 63 of file VecArray.h.

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

63 { return data_; }
T data_[N]
Definition: VecArray.h:29

◆ 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_; }
const_iterator cbegin() const noexcept
Definition: VecArray.h:63
unsigned int size_
Definition: VecArray.h:30

◆ clear()

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

Definition at line 73 of file VecArray.h.

Referenced by ClusterShapeHitFilter::getSizes().

73 { size_ = 0; }
unsigned int size_
Definition: VecArray.h:30

◆ 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_; }
T data_[N]
Definition: VecArray.h:29

◆ 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_; }
T data_[N]
Definition: VecArray.h:29

◆ 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.

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

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  }
unsigned int size_
Definition: VecArray.h:30
std::string to_string(const V &value)
Definition: OMSAccess.h:77
#define N
Definition: blowfish.cc:9
void emplace_back_unchecked(Args &&... args)
Definition: VecArray.h:98

◆ 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.

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

98  {
99  data_[size_] = T(std::forward<Args>(args)...);
100  ++size_;
101  }
unsigned int size_
Definition: VecArray.h:30
long double T
T data_[N]
Definition: VecArray.h:29

◆ empty()

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

Definition at line 69 of file VecArray.h.

69 { return size_ == 0; }
unsigned int size_
Definition: VecArray.h:30

◆ end() [1/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_; }
unsigned int size_
Definition: VecArray.h:30
iterator begin() noexcept
Definition: VecArray.h:61

◆ end() [2/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_; }
unsigned int size_
Definition: VecArray.h:30
iterator begin() noexcept
Definition: VecArray.h:61

◆ front() [1/2]

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

Definition at line 50 of file VecArray.h.

Referenced by PixelClusterShapeExtractor::processRec().

50 { return data_[0]; }
T data_[N]
Definition: VecArray.h:29

◆ 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]; }
T data_[N]
Definition: VecArray.h:29

◆ 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]; }
T data_[N]
Definition: VecArray.h:29

◆ 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]; }
T data_[N]
Definition: VecArray.h:29

◆ pop_back()

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

Definition at line 104 of file VecArray.h.

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

104 { --size_; }
unsigned int size_
Definition: VecArray.h:30

◆ 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  }
unsigned int size_
Definition: VecArray.h:30
std::string to_string(const V &value)
Definition: OMSAccess.h:77
Definition: value.py:1
#define N
Definition: blowfish.cc:9
void push_back_unchecked(const T &value)
Definition: VecArray.h:83

◆ 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.

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

83  {
84  data_[size_] = value;
85  ++size_;
86  }
unsigned int size_
Definition: VecArray.h:30
T data_[N]
Definition: VecArray.h:29

◆ 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  }
void pop_back()
Definition: VecArray.h:104
unsigned int size_
Definition: VecArray.h:30
std::string to_string(const V &value)
Definition: OMSAccess.h:77
#define N
Definition: blowfish.cc:9
constexpr size_type size() const noexcept
Definition: VecArray.h:70

◆ size()

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

◆ 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  }
unsigned int size_
Definition: VecArray.h:30
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T data_[N]
Definition: VecArray.h:29

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