Deduction for vecmem vector type #139
Replies: 3 comments 4 replies
-
Hi Beomki, Your structure only captures the first template argument for the I would propose the following fix to your struct: template <template <typename...> class vector_type, typename T, typename ...As>
struct foo {
foo(vector_type<T, As...>& I) : data(I) {}
vector_type<T, As...> data;
}; |
Beta Was this translation helpful? Give feedback.
-
As an alternative solution, we can simply accept any type into our template<typename T>
struct is_vector : std::false_type {};
template<typename ...As>
struct is_vector<std::vector<As...>> : std::true_type {};
template <class vector_type, std::enable_if_t<is_vector<vector_type>::value, bool> = true>
struct foo {
foo(vector_type& I) : data(I) {}
vector_type data;
}; It's your decision to make which you think is more appropriate or elegant. 😄 |
Beta Was this translation helpful? Give feedback.
-
A number of formalisms are possible. But I would vote for something a bit more concrete. Like: template <template <typename, class> class vector_type, typename T, class A>
struct foo {
foo(vector_type<T, A>& I) : data(I) {}
vector_type<T, A> data;
}; All "vector types" (that we want to use in our code) have 2 template parameters. The code can reflect that. We shouldn't use variadic templates when we don't absolutely need to. The using value_type = typename vector_type::value_type; Which is definitely not the end of the world, but we don't need to complicate things necessarily with this. |
Beta Was this translation helpful? Give feedback.
-
@krasznaa @stephenswat @paulgessinger
In detray side, I was trying to deduct vector type of
vecmem::vector
but it doesn't work due to mismatch in allocator type. (std::vector does work)How can I achieve polymorphic allocator deduction in a concise way?
It's going to be much easier to understand my motivation if you look at the codes and error below
Beta Was this translation helpful? Give feedback.
All reactions