23#ifndef VCL_SPACE_CORE_PARALLEL_VECTOR_TUPLE_H
24#define VCL_SPACE_CORE_PARALLEL_VECTOR_TUPLE_H
26#include <vclib/base.h>
55template<
typename... Types>
58 using VecTuple = std::tuple<std::vector<Types>...>;
64 static constexpr uint
TUPLE_SIZE = std::tuple_size_v<VecTuple>;
69 std::array<bool, TUPLE_SIZE> mVecEnabled;
70 std::size_t mSize = 0;
79 mVecEnabled.fill(
true);
96 std::size_t
size()
const {
return mSize; }
106 static_assert(I <
TUPLE_SIZE,
"Index out of bounds");
107 return mVecEnabled[I];
123 static_assert(I <
TUPLE_SIZE,
"Index out of bounds");
124 mVecEnabled[I] =
true;
125 std::get<I>(mVecTuple).resize(mSize);
139 static_assert(I <
TUPLE_SIZE,
"Index out of bounds");
140 mVecEnabled[I] =
false;
141 std::get<I>(mVecTuple).clear();
152 mVecEnabled.fill(
true);
154 auto func = [
this](
auto&&
vec) {
169 mVecEnabled.fill(
false);
173 std::apply(
func, mVecTuple);
190 throw std::runtime_error(
191 "Accessing disabled vector at index " + std::to_string(I));
194 return std::span<const RT>(std::get<I>(mVecTuple));
210 throw std::runtime_error(
211 "Accessing disabled vector at index " + std::to_string(I));
213 return std::span(std::get<I>(mVecTuple));
264 template<std::
size_t N>
265 void applyToAllEnabledVectors(
auto&&
func)
267 if (mVecEnabled[N]) {
268 func(std::get<N>(mVecTuple));
270 if constexpr (N != 0)
271 applyToAllEnabledVectors<N - 1>(func);
275template<
typename... Types>
A class representing a box in N-dimensional space.
Definition box.h:46
A class that holds multiple vectors of different types in a tuple, constraind to the same size.
Definition parallel_vector_tuple.h:57
auto span()
Returns a std::span to the vector at the given index.
Definition parallel_vector_tuple.h:207
void disableAllVectors()
Disables all vectors in the tuple.
Definition parallel_vector_tuple.h:167
void disableVector()
Disables the vector at the given index.
Definition parallel_vector_tuple.h:137
void enableAllVectors()
Enables all vectors in the tuple.
Definition parallel_vector_tuple.h:150
auto span() const
Returns a const std::span to the vector at the given index.
Definition parallel_vector_tuple.h:187
bool isVectorEnabled() const
Returns whether a vector at a given index is enabled.
Definition parallel_vector_tuple.h:104
void clear()
Clears all enabled vectors and resets the size of the parallel vector tuple to zero.
Definition parallel_vector_tuple.h:252
void reserve(std::size_t size)
Reserves space for all enabled vectors to the given size.
Definition parallel_vector_tuple.h:238
ParallelVectorTuple()
Constructs a ParallelVectorTuple with all vectors enabled.
Definition parallel_vector_tuple.h:76
static constexpr uint tupleSize()
The number of vectors in the tuple.
Definition parallel_vector_tuple.h:85
void resize(std::size_t size)
Resizes all enabled vectors to the given size, and sets the current size of the parallel vector tuple...
Definition parallel_vector_tuple.h:221
static constexpr uint TUPLE_SIZE
The number of vectors in the tuple.
Definition parallel_vector_tuple.h:64
void enableVector()
Enables the vector at the given index.
Definition parallel_vector_tuple.h:121
std::size_t size() const
Returns the size of the parallel vector tuple.
Definition parallel_vector_tuple.h:96
typename TypeAt< I, T... >::type TypeAtT
Alias for the type at a given index in a pack of types (variadic templates) or a TypeWrapper.
Definition variadic_templates.h:173
A simple structure that wraps a list of variadic templates, without instantiating anything....
Definition type_wrapper.h:39