5 #ifndef UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED
6 #define UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED
13 #ifndef UAVCAN_CPP_VERSION
14 # error UAVCAN_CPP_VERSION
29 #if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
32 alignas(T)
unsigned char pool[
sizeof(T)];
37 unsigned char pool[
sizeof(T)];
38 long double _aligner1;
65 fill(data_.pool, data_.pool +
sizeof(T),
uint8_t(0));
71 fill(data_.pool, data_.pool +
sizeof(T),
uint8_t(0));
74 construct<const T&>(*rhs);
85 construct<const T&>(*rhs);
92 operator T*()
const {
return ptr_; }
94 const T*
operator->()
const { ensureConstructed();
return ptr_; }
97 const T&
operator*()
const { ensureConstructed();
return *ptr_; }
98 T&
operator*() { ensureConstructed();
return *ptr_; }
107 fill(data_.pool, data_.pool +
sizeof(T),
uint8_t(0));
112 ensureNotConstructed();
113 ptr_ =
new (
static_cast<void*
>(data_.pool)) T();
131 template <
typename P1>
134 ensureNotConstructed();
135 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1);
138 template<
typename P1,
typename P2>
141 ensureNotConstructed();
142 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1, p2);
145 template<
typename P1,
typename P2,
typename P3>
149 ensureNotConstructed();
150 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1, p2, p3);
153 template<
typename P1,
typename P2,
typename P3,
typename P4>
157 ensureNotConstructed();
158 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1, p2, p3, p4);
161 template<
typename P1,
typename P2,
typename P3,
typename P4,
typename P5>
166 ensureNotConstructed();
167 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1, p2, p3, p4, p5);
170 template<
typename P1,
typename P2,
typename P3,
typename P4,
typename P5,
typename P6>
175 ensureNotConstructed();
176 ptr_ =
new (
static_cast<void*
>(data_.pool)) T(p1, p2, p3, p4, p5, p6);
182 #endif // UAVCAN_UTIL_LAZY_CONSTRUCTOR_HPP_INCLUDED