Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
CustomAlloc.h
Go to the documentation of this file.
1#ifndef Podd_CustomAlloc_h_
2#define Podd_CustomAlloc_h_
3
4// Custom allocators for Decoder package
5
6#include <memory>
7
8namespace Decoder {
9// From https://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container/21028912#21028912
10// Allocator adaptor that interposes construct() calls to
11// convert value initialization into default initialization.
12template<typename T, typename A=std::allocator<T>>
13class default_init_allocator : public A {
14 typedef std::allocator_traits<A> a_t;
15public:
16 template<typename U>
21
22 using A::A;
23
24 template<typename U>
25 void construct( U* ptr )
26 noexcept(std::is_nothrow_default_constructible<U>::value) {
27 ::new(static_cast<void*>(ptr)) U;
28 }
29 template<typename U, typename...Args>
30 void construct( U* ptr, Args&& ... args ) {
31 a_t::construct(static_cast<A&>(*this),
32 ptr, std::forward<Args>(args)...);
33 }
34};
35
36using VectorUInt = std::vector<UInt_t>;
37// std::vector that does NOT zero-initialize its elements on resize()
38using VectorUIntNI = std::vector<UInt_t, default_init_allocator<UInt_t>>;
39
40} // namespace Decoder
41
42#endif //Podd_CustomAlloc_h_
void construct(U *ptr, Args &&... args)
Definition CustomAlloc.h:30
void construct(U *ptr) noexcept(std::is_nothrow_default_constructible< U >::value)
Definition CustomAlloc.h:25
std::allocator_traits< A > a_t
Definition CustomAlloc.h:14
std::vector< UInt_t > VectorUInt
Definition CustomAlloc.h:36
std::vector< UInt_t, default_init_allocator< UInt_t > > VectorUIntNI
Definition CustomAlloc.h:38