vecmem 1.28.0
Loading...
Searching...
No Matches
narrow_size.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2026 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// VecMem include(s).
11#include "vecmem/utils/types.hpp"
12
13// System include(s).
14#include <cassert>
15#include <cstddef>
16#include <limits>
17#include <type_traits>
18
19namespace vecmem::details {
20
46template <typename SIZE_TYPE, typename INPUT_TYPE>
47VECMEM_HOST constexpr SIZE_TYPE narrow_size(INPUT_TYPE size) {
48
49 static_assert(
50 std::is_integral_v<SIZE_TYPE> && std::is_unsigned_v<SIZE_TYPE>,
51 "The device-side size type must be an unsigned integer type");
52 static_assert(
53 std::is_integral_v<INPUT_TYPE> && std::is_unsigned_v<INPUT_TYPE>,
54 "Only unsigned sizes can be narrowed with this helper");
55
56 assert(static_cast<std::size_t>(size) <=
57 static_cast<std::size_t>(std::numeric_limits<SIZE_TYPE>::max()));
58 return static_cast<SIZE_TYPE>(size);
59}
60
61} // namespace vecmem::details
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
Namespace for types that should not be used directly by clients.
Definition array.hpp:23
VECMEM_HOST constexpr SIZE_TYPE narrow_size(INPUT_TYPE size)
Narrow a host-side element count to a device-side size type.
Definition narrow_size.hpp:47