8 // based on boost::core::noinit_adaptor
9 // The goal is to avoid initialization of the content of a container,
10 // because setting several kB of uint8_t to 0 has a real cost if you
11 // do 100k times per second.
12 template<class Allocator>
13 struct noinit_adaptor: Allocator
17 typedef noinit_adaptor<typename std::allocator_traits<Allocator>::template
18 rebind_alloc<U> > other;
21 noinit_adaptor(): Allocator() { }
24 noinit_adaptor(U&& u) noexcept : Allocator(std::forward<U>(u)) { }
27 noinit_adaptor(const noinit_adaptor<U>& u) noexcept : Allocator(static_cast<const U&>(u)) { }
30 void construct(U* p) {
34 template<class U, class V, class... Args>
35 void construct(U* p, V&& v, Args&&... args) {
36 ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
45 template<class T, class U>
46 inline bool operator==(const noinit_adaptor<T>& lhs,
47 const noinit_adaptor<U>& rhs) noexcept
49 return static_cast<const T&>(lhs) == static_cast<const U&>(rhs);
52 template<class T, class U>
53 inline bool operator!=(const noinit_adaptor<T>& lhs,
54 const noinit_adaptor<U>& rhs) noexcept
59 template<class Allocator>
60 inline noinit_adaptor<Allocator> noinit_adapt(const Allocator& a) noexcept
62 return noinit_adaptor<Allocator>(a);
65 template<class T> using NoInitVector = std::vector<T, noinit_adaptor<std::allocator<T>>>;
67 using PacketBuffer = NoInitVector<uint8_t>;