aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/gc-small-vector.hh
blob: c4bd1db26f152315ce925019d0e3a0f053508743 (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
#pragma once
///@file

#include <boost/container/small_vector.hpp>

#if HAVE_BOEHMGC

#define GC_INCLUDE_NEW
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>

#endif

namespace nix {

struct Value;

/**
 * A GC compatible vector that may used a reserved portion of `nItems` on the stack instead of allocating on the heap.
 */
#if HAVE_BOEHMGC
template <typename T, size_t nItems>
using SmallVector = boost::container::small_vector<T, nItems, traceable_allocator<T>>;
#else
template <typename T, size_t nItems>
using SmallVector = boost::container::small_vector<T, nItems>;
#endif

/**
 * A vector of value pointers. See `SmallVector`.
 */
template <size_t nItems>
using SmallValueVector = SmallVector<Value *, nItems>;

/**
 * A vector of values that must not be referenced after the vector is destroyed.
 *
 * See also `SmallValueVector`.
 */
template <size_t nItems>
using SmallTemporaryValueVector = SmallVector<Value, nItems>;

}