Skip to content

Commit

Permalink
Marked all (reasonable) container constructor explicit.
Browse files Browse the repository at this point in the history
  • Loading branch information
krasznaa committed Nov 7, 2024
1 parent 29eb187 commit ef8aa2b
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 51 deletions.
4 changes: 2 additions & 2 deletions core/include/vecmem/containers/array.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* VecMem project, part of the ACTS project (R&D line)
*
* (c) 2021 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -89,7 +89,7 @@ class array {
/// Can only be used if the user chose a non-default value for the size
/// template parameter.
///
array(memory_resource& resource);
explicit array(memory_resource& resource);

/// Constructor with a size and a memory resource to use
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VecMem project, part of the ACTS project (R&D line)
*
* (c) 2021-2023 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -40,7 +40,7 @@ class jagged_device_vector_iterator {
/// Type of the data object that we have an array of
typedef data::vector_view<TYPE> data_type;
/// Pointer to the data object
typedef const data_type* data_pointer;
typedef std::add_pointer_t<std::add_const_t<data_type>> data_pointer;

/// @}

Expand Down Expand Up @@ -70,7 +70,7 @@ class jagged_device_vector_iterator {
/// the existence of this type as possible.
///
VECMEM_HOST_AND_DEVICE
pointer(const data_pointer data);
explicit pointer(const data_pointer data);

/// Return a pointer to a device vector (non-const)
VECMEM_HOST_AND_DEVICE
Expand All @@ -92,7 +92,7 @@ class jagged_device_vector_iterator {
jagged_device_vector_iterator();
/// Constructor from an underlying data object
VECMEM_HOST_AND_DEVICE
jagged_device_vector_iterator(data_pointer data);
explicit jagged_device_vector_iterator(data_pointer data);
/// Constructor from a slightly different underlying data object
template <typename OTHERTYPE,
std::enable_if_t<details::is_same_nc<TYPE, OTHERTYPE>::value,
Expand Down Expand Up @@ -189,7 +189,7 @@ namespace std {
/// of @c vecmem::details::jagged_device_vector_iterator.
///
template <typename T>
struct iterator_traits<vecmem::details::jagged_device_vector_iterator<T> > {
struct iterator_traits<vecmem::details::jagged_device_vector_iterator<T>> {
typedef
typename vecmem::details::jagged_device_vector_iterator<T>::value_type
value_type;
Expand Down
4 changes: 2 additions & 2 deletions core/include/vecmem/containers/device_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class device_array {

/// Constructor, on top of a previously allocated/filled block of memory
VECMEM_HOST_AND_DEVICE
device_array(const data::vector_view<value_type>& data);
explicit device_array(const data::vector_view<value_type>& data);
/// Construct a const device array from a non-const data object
template <
typename OTHERTYPE,
std::enable_if_t<details::is_same_nc<T, OTHERTYPE>::value, bool> = true>
VECMEM_HOST_AND_DEVICE device_array(
VECMEM_HOST_AND_DEVICE explicit device_array(
const data::vector_view<OTHERTYPE>& data);
/// Copy constructor
VECMEM_HOST_AND_DEVICE
Expand Down
10 changes: 2 additions & 8 deletions core/include/vecmem/containers/device_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* VecMem project, part of the ACTS project (R&D line)
*
* (c) 2021-2022 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -78,13 +78,7 @@ class device_vector {

/// Constructor, on top of a previously allocated/filled block of memory
VECMEM_HOST_AND_DEVICE
device_vector(const data::vector_view<value_type>& data);
/// Construct a const device vector from a non-const data object
template <typename OTHERTYPE,
std::enable_if_t<details::is_same_nc<TYPE, OTHERTYPE>::value,
bool> = true>
VECMEM_HOST_AND_DEVICE device_vector(
const data::vector_view<OTHERTYPE>& data);
explicit device_vector(const data::vector_view<value_type>& data);
/// Copy constructor
VECMEM_HOST_AND_DEVICE
device_vector(const device_vector& parent);
Expand Down
14 changes: 0 additions & 14 deletions core/include/vecmem/containers/impl/device_vector.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ VECMEM_HOST_AND_DEVICE device_vector<TYPE>::device_vector(
static_cast<const void*>(m_ptr));
}

template <typename TYPE>
template <typename OTHERTYPE,
std::enable_if_t<details::is_same_nc<TYPE, OTHERTYPE>::value, bool> >
VECMEM_HOST_AND_DEVICE device_vector<TYPE>::device_vector(
const data::vector_view<OTHERTYPE>& data)
: m_capacity(data.capacity()), m_size(data.size_ptr()), m_ptr(data.ptr()) {

VECMEM_DEBUG_MSG(5,
"Created vecmem::device_vector with capacity %u and "
"size pointer %p from pointer %p",
m_capacity, static_cast<const void*>(m_size),
static_cast<const void*>(m_ptr));
}

template <typename TYPE>
VECMEM_HOST_AND_DEVICE device_vector<TYPE>::device_vector(
const device_vector& parent)
Expand Down
18 changes: 9 additions & 9 deletions core/include/vecmem/containers/impl/jagged_device_vector.ipp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* VecMem project, part of the ACTS project (R&D line)
*
* (c) 2021-2022 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -49,7 +49,7 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::at(size_type pos)
assert(pos < m_size);

// Return a reference to the vector element.
return m_ptr[pos];
return reference{m_ptr[pos]};
}

template <typename T>
Expand All @@ -60,23 +60,23 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::at(size_type pos) const
assert(pos < m_size);

// Return a reference to the vector element.
return m_ptr[pos];
return const_reference{m_ptr[pos]};
}

template <typename T>
VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::operator[](size_type pos)
-> reference {

// Return a reference to the vector element.
return m_ptr[pos];
return reference{m_ptr[pos]};
}

template <typename T>
VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::operator[](
size_type pos) const -> const_reference {

// Return a reference to the vector element.
return m_ptr[pos];
return const_reference{m_ptr[pos]};
}

template <typename T>
Expand All @@ -86,7 +86,7 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::front() -> reference {
assert(m_size > 0);

// Return a reference to the first element of the vector.
return m_ptr[0];
return reference{m_ptr[0]};
}

template <typename T>
Expand All @@ -97,7 +97,7 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::front() const
assert(m_size > 0);

// Return a reference to the first element of the vector.
return m_ptr[0];
return const_reference{m_ptr[0]};
}

template <typename T>
Expand All @@ -107,7 +107,7 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::back() -> reference {
assert(m_size > 0);

// Return a reference to the last element of the vector.
return m_ptr[m_size - 1];
return reference{m_ptr[m_size - 1]};
}

template <typename T>
Expand All @@ -118,7 +118,7 @@ VECMEM_HOST_AND_DEVICE auto jagged_device_vector<T>::back() const
assert(m_size > 0);

// Return a reference to the last element of the vector.
return m_ptr[m_size - 1];
return const_reference{m_ptr[m_size - 1]};
}

template <typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ template <typename TYPE>
VECMEM_HOST_AND_DEVICE auto jagged_device_vector_iterator<TYPE>::operator*()
const -> reference {

return *m_ptr;
return reference{*m_ptr};
}

template <typename TYPE>
VECMEM_HOST_AND_DEVICE auto
jagged_device_vector_iterator<TYPE>::operator->() const -> pointer {

return m_ptr;
return pointer{m_ptr};
}

template <typename TYPE>
VECMEM_HOST_AND_DEVICE auto jagged_device_vector_iterator<TYPE>::operator[](
difference_type n) const -> reference {

return *(*this + n);
return reference{*(*this + n)};
}

template <typename TYPE>
Expand Down
2 changes: 1 addition & 1 deletion core/include/vecmem/containers/jagged_device_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class jagged_device_vector {
* object.
*/
VECMEM_HOST_AND_DEVICE
jagged_device_vector(data::jagged_vector_view<T> data);
explicit jagged_device_vector(data::jagged_vector_view<T> data);

/// Copy constructor
VECMEM_HOST_AND_DEVICE
Expand Down
5 changes: 3 additions & 2 deletions core/include/vecmem/containers/static_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* VecMem project, part of the ACTS project (R&D line)
*
* (c) 2021 CERN for the benefit of the ACTS project
* (c) 2021-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/
Expand Down Expand Up @@ -77,7 +77,8 @@ class static_vector {
static_vector();
/// Construct a vector with a specific size
VECMEM_HOST_AND_DEVICE
static_vector(size_type size, const_reference value = value_type());
explicit static_vector(size_type size,
const_reference value = value_type());
/// Construct a vector with values coming from a pair of iterators
template <
typename InputIt,
Expand Down
7 changes: 5 additions & 2 deletions tests/cuda/test_cuda_containers_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,11 @@ __global__ void arrayTransformKernel(
}
// Create the "device type".
vecmem::static_array<vecmem::device_vector<int>, 4> vec{data[0], data[1],
data[2], data[3]};
vecmem::static_array<vecmem::device_vector<int>, 4> vec{
vecmem::device_vector<int>{data[0]},
vecmem::device_vector<int>{data[1]},
vecmem::device_vector<int>{data[2]},
vecmem::device_vector<int>{data[3]}};
// Perform the transformation.
vec[i][j] *= 2;
Expand Down
7 changes: 5 additions & 2 deletions tests/hip/test_hip_containers_kernels.hip
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,11 @@ __global__ void arrayTransformKernel(
}

// Create the "device type".
vecmem::static_array<vecmem::device_vector<int>, 4> vec{data[0], data[1],
data[2], data[3]};
vecmem::static_array<vecmem::device_vector<int>, 4> vec{
vecmem::device_vector<int>{data[0]},
vecmem::device_vector<int>{data[1]},
vecmem::device_vector<int>{data[2]},
vecmem::device_vector<int>{data[3]}};

// Perform the transformation.
vec[i][j] *= 2;
Expand Down
5 changes: 4 additions & 1 deletion tests/sycl/test_sycl_containers.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,10 @@ TEST_F(sycl_containers_test, array_memory) {

// Create the "device type".
vecmem::static_array<vecmem::device_vector<int>, 4> vec{
data[0], data[1], data[2], data[3]};
vecmem::device_vector<int>{data[0]},
vecmem::device_vector<int>{data[1]},
vecmem::device_vector<int>{data[2]},
vecmem::device_vector<int>{data[3]}};

// Perform the transformation.
vec[static_cast<vecmem::static_array<
Expand Down

0 comments on commit ef8aa2b

Please sign in to comment.