test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
 
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

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

Definition at line 41 of file VecArray.h.

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

Definition at line 39 of file VecArray.h.

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

Definition at line 37 of file VecArray.h.

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

Definition at line 35 of file VecArray.h.

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

Definition at line 40 of file VecArray.h.

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

Definition at line 38 of file VecArray.h.

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

Definition at line 36 of file VecArray.h.

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

Definition at line 34 of file VecArray.h.

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

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

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
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
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
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
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 ClusterShape::determineShape(), and ClusterShapeHitFilter::getSizes().

71 { return N; }
#define N
Definition: blowfish.cc:9
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
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
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(), and SiPixelClusterShapeCacheProducer::produce().

73  {
74  size_ = 0;
75  }
unsigned int size_
Definition: VecArray.h:30
template<typename T, unsigned int N>
pointer edm::VecArray< T, N >::data ( )
inline

Definition at line 58 of file VecArray.h.

Referenced by cuy.FindIssue::__init__().

58 { return data_; }
T data_[N]
Definition: VecArray.h:29
template<typename T, unsigned int N>
const_pointer edm::VecArray< T, N >::data ( ) const
inline

Definition at line 59 of file VecArray.h.

Referenced by cuy.FindIssue::__init__().

59 { return data_; }
T data_[N]
Definition: VecArray.h:29
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
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
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
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]; }
T data_[N]
Definition: VecArray.h:29
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
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
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
template<typename T, unsigned int N>
void edm::VecArray< T, N >::pop_back ( )
inline

Definition at line 91 of file VecArray.h.

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

91  {
92  --size_;
93  }
unsigned int size_
Definition: VecArray.h:30
template<typename T, unsigned int N>
void edm::VecArray< T, N >::push_back ( const T value)
inline

Definition at line 78 of file VecArray.h.

78  {
79  if(size_ >= N)
80  throw std::length_error("push_back on already-full VecArray (N="+std::to_string(N)+")");
82  }
unsigned int size_
Definition: VecArray.h:30
#define N
Definition: blowfish.cc:9
void push_back_unchecked(const T &value)
Definition: VecArray.h:85
template<typename T, unsigned int N>
void edm::VecArray< T, N >::push_back_unchecked ( const T value)
inline
template<typename T, unsigned int N>
void edm::VecArray< T, N >::resize ( unsigned int  size)
inline

Definition at line 95 of file VecArray.h.

Referenced by Vispa.Gui.TextDialog.TextDialog::__init__(), Vispa.Plugins.ConfigEditor.ToolDialog.ToolDialog::__init__(), Vispa.Main.MainWindow.MainWindow::_loadIni(), and Vispa.Gui.PortConnection.PointToPointConnection::updateConnection().

95  {
96  if(size > N)
97  throw std::length_error("Requesting size "+std::to_string(size)+" while maximum allowed is "+std::to_string(N));
98 
99  while(size < size_)
100  pop_back();
101  size_ = size;
102  }
void pop_back()
Definition: VecArray.h:91
unsigned int size_
Definition: VecArray.h:30
#define N
Definition: blowfish.cc:9
constexpr size_type size() const noexcept
Definition: VecArray.h:70
template<typename T, unsigned int N>
constexpr size_type edm::VecArray< T, N >::size ( void  ) const
inlinenoexcept

Definition at line 70 of file VecArray.h.

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

70 { return size_; }
unsigned int size_
Definition: VecArray.h:30
template<typename T, unsigned int N>
void edm::VecArray< T, N >::swap ( VecArray< T, N > &  other)
inlinenoexcept

Definition at line 104 of file VecArray.h.

107  {
108  std::swap(data_, other.data_);
109  std::swap(size_, other.size_);
110  }
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

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