WPILibC++  unspecified
default_init_allocator.h
1 // From:
2 // http://stackoverflow.com/questions/21028299/is-this-behavior-of-vectorresizesize-type-n-under-c11-and-boost-container
3 // Credits: Casey and Howard Hinnant
4 
5 #ifndef CSCORE_DEFAULT_INIT_ALLOCATOR_H_
6 #define CSCORE_DEFAULT_INIT_ALLOCATOR_H_
7 
8 #include <memory>
9 #include <utility>
10 
11 namespace cs {
12 
13 // Allocator adaptor that interposes construct() calls to
14 // convert value initialization into default initialization.
15 template <typename T, typename A = std::allocator<T>>
16 class default_init_allocator : public A {
17  typedef std::allocator_traits<A> a_t;
18 
19  public:
20  template <typename U>
21  struct rebind {
22  using other =
24  };
25 
26  using A::A;
27 
28  template <typename U>
29  void construct(U* ptr) noexcept(
30  std::is_nothrow_default_constructible<U>::value) {
31  ::new (static_cast<void*>(ptr)) U;
32  }
33  template <typename U, typename... Args>
34  void construct(U* ptr, Args&&... args) {
35  a_t::construct(static_cast<A&>(*this), ptr, std::forward<Args>(args)...);
36  }
37 };
38 
39 } // namespace cs
40 
41 #endif // CSCORE_DEFAULT_INIT_ALLOCATOR_H_
Definition: CvSourceImpl.h:19
Definition: default_init_allocator.h:16
Definition: default_init_allocator.h:21