View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

allocator.h
Go to the documentation of this file.
1#ifndef VISTLE_UTIL_ALLOCATOR_H
2#define VISTLE_UTIL_ALLOCATOR_H
3
4#include <memory>
5
6namespace vistle {
7
8// Allocator adaptor that interposes construct() calls to
9// convert value initialization into default initialization.
10// from http://stackoverflow.com/a/21028912/273767
11template<typename T, typename A = std::allocator<T>>
12class default_init_allocator: public A {
13 typedef std::allocator_traits<A> a_t;
14
15public:
16 template<typename U>
17 struct rebind {
19 };
20
21 using A::A;
22
23 template<typename U>
24 void construct(U *ptr) noexcept(std::is_nothrow_default_constructible<U>::value)
25 {
26 ::new (static_cast<void *>(ptr)) U;
27 }
28 template<typename U, typename... Args>
29 void construct(U *ptr, Args &&...args)
30 {
31 a_t::construct(static_cast<A &>(*this), ptr, std::forward<Args>(args)...);
32 }
33};
34
35template<typename T>
37} // namespace vistle
38#endif
Definition: allocator.h:12
void construct(U *ptr, Args &&...args)
Definition: allocator.h:29
void construct(U *ptr) noexcept(std::is_nothrow_default_constructible< U >::value)
Definition: allocator.h:24
Definition: allocator.h:17
Definition: allobjects.cpp:30