vecmem 1.14.0
Loading...
Searching...
No Matches
jagged_vector_view.ipp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2025 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8
9#pragma once
10
11namespace vecmem {
12namespace data {
13
14template <typename T>
16 size_type size, pointer ptr, pointer host_ptr)
17 : m_size(size),
18 m_ptr(ptr),
19 m_host_ptr(host_ptr != nullptr ? host_ptr : ptr) {}
20
21template <typename T>
22template <typename OTHERTYPE,
23 std::enable_if_t<details::is_same_nc<T, OTHERTYPE>::value, bool> >
26 : m_size(parent.size()),
27 // This looks scarier than it really is. We "just" reinterpret a
28 // vecmem::data::vector_view<T> pointer to be seen as
29 // vecmem::data::vector_view<const T> instead.
32 parent.ptr()))),
33 m_host_ptr(reinterpret_cast<pointer>(
35 parent.host_ptr()))) {}
36
37template <typename T>
38template <typename OTHERTYPE,
39 std::enable_if_t<details::is_same_nc<T, OTHERTYPE>::value, bool> >
42
43 // Self-assignment is not dangerous for this type. But putting in
44 // extra checks into the code would not be great.
45 m_size = rhs.size();
46 m_ptr = reinterpret_cast<pointer>(
48 m_host_ptr = reinterpret_cast<pointer>(
50 rhs.host_ptr()));
51
52 // Return this (updated) object.
53 return *this;
54}
55
56template <typename T>
57template <typename OTHERTYPE,
58 std::enable_if_t<std::is_same<std::remove_cv_t<T>,
59 std::remove_cv_t<OTHERTYPE> >::value,
60 bool> >
61VECMEM_HOST_AND_DEVICE bool jagged_vector_view<T>::operator==(
63
64 return ((m_size == rhs.size()) &&
65 (static_cast<const void*>(m_ptr) ==
66 static_cast<const void*>(rhs.ptr())) &&
67 (static_cast<const void*>(m_host_ptr) ==
68 static_cast<const void*>(rhs.host_ptr())));
69}
70
71template <typename T>
72template <typename OTHERTYPE,
73 std::enable_if_t<std::is_same<std::remove_cv_t<T>,
74 std::remove_cv_t<OTHERTYPE> >::value,
75 bool> >
76VECMEM_HOST_AND_DEVICE bool jagged_vector_view<T>::operator!=(
78
79 return !(*this == rhs);
81
82template <typename T>
83VECMEM_HOST_AND_DEVICE auto jagged_vector_view<T>::size() const -> size_type {
84
85 return m_size;
86}
87
88template <typename T>
89VECMEM_HOST_AND_DEVICE auto jagged_vector_view<T>::capacity() const
90 -> size_type {
91
92 return m_size;
93}
94
95template <typename T>
96VECMEM_HOST_AND_DEVICE auto jagged_vector_view<T>::ptr() const -> pointer {
98 return m_ptr;
99}
100
101template <typename T>
102VECMEM_HOST_AND_DEVICE auto jagged_vector_view<T>::host_ptr() const -> pointer {
103
104 return m_host_ptr;
105}
107} // namespace data
108} // namespace vecmem
A view for jagged vectors.
Definition jagged_vector_view.hpp:44
VECMEM_HOST_AND_DEVICE pointer host_ptr() const
Access the host accessible array describing the inner vectors.
Definition jagged_vector_view.ipp:102
VECMEM_HOST_AND_DEVICE jagged_vector_view & operator=(const jagged_vector_view< OTHERTYPE > &rhs)
Assignment operator from a "slightly different" object.
std::size_t size_type
We cannot use boolean types.
Definition jagged_vector_view.hpp:52
std::add_pointer_t< value_type > pointer
Pointer type to the jagged array.
Definition jagged_vector_view.hpp:56
VECMEM_HOST_AND_DEVICE bool operator!=(const jagged_vector_view< OTHERTYPE > &rhs) const
Inequality check. Simply based on operator==.
Definition jagged_vector_view.ipp:76
jagged_vector_view()=default
Default constructor.
VECMEM_HOST_AND_DEVICE size_type capacity() const
Get the maximum capacity of the "outer" vector.
Definition jagged_vector_view.ipp:89
VECMEM_HOST_AND_DEVICE bool operator==(const jagged_vector_view< OTHERTYPE > &rhs) const
Equality check.
Definition jagged_vector_view.ipp:61
VECMEM_HOST_AND_DEVICE pointer ptr() const
Get a pointer to the vector elements.
Definition jagged_vector_view.ipp:96
VECMEM_HOST_AND_DEVICE size_type size() const
Get the "outer" size of the jagged vector.
Definition jagged_vector_view.ipp:83
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35