10#include "vecmem/containers/details/resize_jagged_vector.hpp"
11#include "vecmem/containers/jagged_vector.hpp"
12#include "vecmem/containers/vector.hpp"
13#include "vecmem/edm/details/schema_traits.hpp"
14#include "vecmem/edm/schema.hpp"
15#include "vecmem/memory/memory_resource.hpp"
25namespace vecmem::edm::details {
30template <
typename TYPE>
33template <
typename TYPE>
36 using return_type = std::add_lvalue_reference_t<TYPE>;
37 using const_return_type =
38 std::add_lvalue_reference_t<std::add_const_t<TYPE>>;
41template <
typename TYPE>
44 using return_type = std::add_lvalue_reference_t<type>;
45 using const_return_type =
46 std::add_lvalue_reference_t<std::add_const_t<type>>;
49template <
typename TYPE>
52 using return_type = std::add_lvalue_reference_t<type>;
53 using const_return_type =
54 std::add_lvalue_reference_t<std::add_const_t<type>>;
59 using type =
typename host_type<
typename std::tuple_element<
61 using return_type =
typename host_type<
typename std::tuple_element<
63 using const_return_type =
typename host_type<
typename std::tuple_element<
72template <
typename TYPE>
79template <
typename TYPE>
82 memory_resource&
mr) {
96std::size_t get_host_size(
98 std::index_sequence<INDEX, Is...>, std::size_t size = 0,
113 throw std::length_error(
114 "Inconsistent variable sizes in host container!");
117 if constexpr (
sizeof...(Is) == 0) {
118 if (!(size_known || var_size_known)) {
119 throw std::length_error(
120 "Could not determine the size of the host container?!?");
124 return get_host_size<VARTYPES...>(data, std::index_sequence<Is...>{},
126 size_known || var_size_known);
136template <
typename... VARTYPES, std::size_t INDEX, std::size_t... Is>
137std::size_t get_host_capacity(
138 const std::tuple<
typename host_type<VARTYPES>::type...>& data,
139 std::index_sequence<INDEX, Is...>,
140 std::size_t capacity = std::numeric_limits<std::size_t>::max(),
141 bool capacity_known =
false) {
144 if constexpr (type::details::is_vector<
typename std::tuple_element<
145 INDEX, std::tuple<VARTYPES...>>::type>::value) {
149 capacity = std::min(std::get<INDEX>(data).capacity(), capacity);
150 capacity_known =
true;
153 if constexpr (
sizeof...(Is) == 0) {
154 if (!capacity_known) {
155 throw std::length_error(
156 "Could not determine the capacity of the host container?!?");
160 return get_host_capacity<VARTYPES...>(
161 data, std::index_sequence<Is...>{}, capacity, capacity_known);
171template <
typename... VARTYPES, std::size_t INDEX, std::size_t... Is>
172void host_resize(std::tuple<
typename host_type<VARTYPES>::type...>& data,
173 std::size_t size, std::index_sequence<INDEX, Is...>) {
176 if constexpr (type::details::is_jagged_vector_v<
typename std::tuple_element<
177 INDEX, std::tuple<VARTYPES...>>::type>) {
179 }
else if constexpr (type::details::is_vector_v<
typename std::tuple_element<
180 INDEX, std::tuple<VARTYPES...>>::type>) {
181 std::get<INDEX>(data).resize(size);
184 if constexpr (
sizeof...(Is) > 0) {
185 host_resize<VARTYPES...>(data, size, std::index_sequence<Is...>{});
195template <
typename... VARTYPES, std::size_t INDEX, std::size_t... Is>
196void host_reserve(std::tuple<
typename host_type<VARTYPES>::type...>& data,
197 std::size_t size, std::index_sequence<INDEX, Is...>) {
200 if constexpr (type::details::is_vector<
typename std::tuple_element<
201 INDEX, std::tuple<VARTYPES...>>::type>::value) {
202 std::get<INDEX>(data).reserve(size);
205 if constexpr (
sizeof...(Is) > 0) {
206 host_reserve<VARTYPES...>(data, size, std::index_sequence<Is...>{});
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
Technical base type for data<schema<VARTYPES...>>
Definition data.hpp:25
void resize_jagged_vector(std::vector< std::vector< T, ALLOC1 >, ALLOC2 > &vec, std::size_t size)
Resize a generic jagged vector.
Definition resize_jagged_vector.hpp:23
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
Definition host_traits.hpp:73
Definition host_traits.hpp:58
Definition host_traits.hpp:31
Definition schema_traits.hpp:90