summaryrefslogtreecommitdiff
path: root/src/common/include/gudhi/allocator.h
blob: e828f4413c7a92f74e1cb4f5a2ca379e60222d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*    This file is part of the Gudhi Library. The Gudhi library
 *    (Geometric Understanding in Higher Dimensions) is a generic C++
 *    library for computational topology.
 *
 *    Author(s):       Marc Glisse
 *
 *    Copyright (C) 2015 Inria
 *
 *    Modification(s):
 *      - YYYY/MM Author: Description of the modification
 */

#ifndef ALLOCATOR_H_
#define ALLOCATOR_H_

#include <memory>
#include <utility>

namespace Gudhi {

/** \private
 * An allocator that can be used to build an uninitialized vector.
 */
template <class T, class Base = std::allocator<T>>
struct no_init_allocator : Base {
  typedef std::allocator_traits<Base> Base_traits;
  template <class U> struct rebind {
    typedef no_init_allocator<U, typename Base_traits::template rebind_alloc<U>> other;
  };

  // Inherit constructors.
  using Base::Base;

  // Do nothing: that's the whole point!
  template<class P>
  void construct(P*) noexcept {}

  template<class P, class...U> void construct(P*p, U&&...u) {
    Base_traits::construct(*(Base*)this, p, std::forward<U>(u)...);
  }
};

}  // namespace Gudhi

#endif  // ALLOCATOR_H_