Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
copy_n.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COPY_N_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COPY_N_HPP_
7
8// IWYU pragma: private, include <algorithm>
9// IWYU pragma: friend "stdlib_detail/.*"
10
11#include "arene/base/constraints.hpp"
12#include "stdlib/include/stdlib_detail/conditional.hpp"
13#include "stdlib/include/stdlib_detail/cstdint.hpp"
14#include "stdlib/include/stdlib_detail/declval.hpp"
15#include "stdlib/include/stdlib_detail/enable_if.hpp"
16#include "stdlib/include/stdlib_detail/is_convertible.hpp"
17#include "stdlib/include/stdlib_detail/is_signed.hpp"
18#include "stdlib/include/stdlib_detail/iterator_concepts.hpp"
19#include "stdlib/include/stdlib_detail/iterator_traits.hpp"
20
21// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
22// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
23// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
24
25namespace std {
26
27namespace copy_n_detail {
28/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
29/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
30/// @param value The value to convert
31/// @return The value as an integer
32inline constexpr auto convert_size_to_integer(bool const value) noexcept -> uint8_t {
33 if (value) {
34 return 1U;
35 }
36 return 0U;
37}
38
39// parasoft-begin-suppress AUTOSAR-A3_9_1-b "Overloaded for every built-in integer type"
40/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
41/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
42/// @param value The value to convert
43/// @return The value as an integer
44inline constexpr auto convert_size_to_integer(char const value) noexcept
46 return static_cast<conditional_t<is_signed_v<char>, int8_t, uint8_t>>(value);
47}
48/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
49/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
50/// @param value The value to convert
51/// @return The value as an integer
52inline constexpr auto convert_size_to_integer(unsigned char const value) noexcept -> uint8_t { return value; }
53/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
54/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
55/// @param value The value to convert
56/// @return The value as an integer
57inline constexpr auto convert_size_to_integer(signed char const value) noexcept -> int8_t { return value; }
58/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
59/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
60/// @param value The value to convert
61/// @return The value as an integer
62inline constexpr auto convert_size_to_integer(int const value) noexcept -> int { return value; }
63/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
64/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
65/// @param value The value to convert
66/// @return The value as an integer
67inline constexpr auto convert_size_to_integer(unsigned const value) noexcept -> unsigned { return value; }
68/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
69/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
70/// @param value The value to convert
71/// @return The value as an integer
72// NOLINTNEXTLINE(google-runtime-int)
73inline constexpr auto convert_size_to_integer(short const value) noexcept -> short { return value; }
74/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
75/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
76/// @param value The value to convert
77/// @return The value as an integer
78// NOLINTNEXTLINE(google-runtime-int)
79inline constexpr auto convert_size_to_integer(unsigned short const value) noexcept -> unsigned short { return value; }
80/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
81/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
82/// @param value The value to convert
83/// @return The value as an integer
84// NOLINTNEXTLINE(google-runtime-int)
85inline constexpr auto convert_size_to_integer(long const value) noexcept -> long { return value; }
86/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
87/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
88/// @param value The value to convert
89/// @return The value as an integer
90// NOLINTNEXTLINE(google-runtime-int)
91inline constexpr auto convert_size_to_integer(unsigned long const value) noexcept -> unsigned long { return value; }
92/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
93/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
94/// @param value The value to convert
95/// @return The value as an integer
96// NOLINTNEXTLINE(google-runtime-int)
97inline constexpr auto convert_size_to_integer(long long const value) noexcept -> long long { return value; }
98/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
99/// integer themselves. Each overload acceps a specific type, and returns an integer with the same value.
100/// @param value The value to convert
101/// @return The value as an integer
102// NOLINTNEXTLINE(google-runtime-int)
103inline constexpr auto convert_size_to_integer(unsigned long long const value) noexcept -> unsigned long long {
104 return value;
105}
106/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
107/// integer themselves. Each overload acceps a specific type, and returns the input value cast to an integer.
108/// @param value The value to convert
109/// @return The value as an integer
110inline constexpr auto convert_size_to_integer(float const value) noexcept -> std::int64_t {
111 return static_cast<std::int64_t>(value);
112}
113/// @brief Overloaded internal function to handle Size types that are "convertible to an integer" rather than being an
114/// integer themselves. Each overload acceps a specific type, and returns the input value cast to an integer.
115/// @param value The value to convert
116/// @return The value as an integer
117inline constexpr auto convert_size_to_integer(double const value) noexcept -> std::int64_t {
118 return static_cast<std::int64_t>(value);
119}
120// parasoft-end-suppress AUTOSAR-A3_9_1-b
121
122/// @brief Type trait to check if a type is implicitly convertible to an integral type. The value is @c true if so, @c
123/// false otherwise
124/// @tparam T The type to check
125template <typename T, typename = arene::base::constraints<>>
126extern constexpr bool is_convertible_to_integral_v = false;
127
128/// @brief Type trait to check if a type is implicitly convertible to an integral type. The value is @c true if so, @c
129/// false otherwise
130/// @tparam T The type to check
131template <typename T>
132extern constexpr bool is_convertible_to_integral_v<
133 T,
135
136/// @brief Type trait to check if a type is implicitly convertible to an integral type without throwing. The value is @c
137/// true if so, @c false otherwise
138/// @tparam T The type to check
139template <typename T, typename = arene::base::constraints<>>
140extern constexpr bool is_nothrow_convertible_to_integral_v = false;
141
142/// @brief Type trait to check if a type is implicitly convertible to an integral type without throwing. The value is @c
143/// true if so, @c false otherwise
144/// @tparam T The type to check
145template <typename T>
146extern constexpr bool
149
150} // namespace copy_n_detail
151
152// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
153/// @brief Copy @c count elements from the input range starting with @c first to the output range starting with @c out
154/// @tparam InputIterator The type of the input iterator
155/// @tparam Size The type of the count of elements to copy
156/// @tparam OutputIterator The type of the output iterator
157/// @param first The start of the source range
158/// @param count The number of elements to copy
159/// @param out The start of the output range
160/// @return The final value of @c out
161/// @pre @c InputIterator must be an input iterator
162/// @pre @c first must be the start of a valid input range of at least @c count elements
163/// @pre @c Size must be convertible to an integral type
164/// @pre @c OutputIterator must be an output iterator
165/// @pre @c out must be the start of a valid output range of at least @c count elements
166template <
167 typename InputIterator,
168 typename Size,
169 typename OutputIterator,
177 Size count,
180 -> OutputIterator {
181 // parasoft-begin-suppress AUTOSAR-M5_0_4-a "False positive: No signed/unsigned conversion here"
183 // parasoft-end-suppress AUTOSAR-M5_0_4-a
184 using count_type = decltype(count_to_copy);
185
186 for (; count_to_copy > static_cast<count_type>(0); --count_to_copy) {
187 *out = *first;
188 // parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "This is an iterator type, so incrementing is OK"
189 ++out;
190 ++first;
191 // parasoft-end-suppress AUTOSAR-M5_0_15-a-2
192 }
193 return out;
194}
195// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2
196
197} // namespace std
198
199#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_COPY_N_HPP_
Definition copy_n.hpp:27
constexpr auto convert_size_to_integer(unsigned const value) noexcept -> unsigned
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:67
constexpr auto convert_size_to_integer(int const value) noexcept -> int
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:62
constexpr auto convert_size_to_integer(signed char const value) noexcept -> int8_t
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:57
constexpr auto convert_size_to_integer(short const value) noexcept -> short
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:73
constexpr auto convert_size_to_integer(long const value) noexcept -> long
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:85
constexpr auto convert_size_to_integer(unsigned long const value) noexcept -> unsigned long
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:91
constexpr auto convert_size_to_integer(bool const value) noexcept -> uint8_t
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:32
constexpr auto convert_size_to_integer(long long const value) noexcept -> long long
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:97
constexpr auto convert_size_to_integer(unsigned long long const value) noexcept -> unsigned long long
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:103
constexpr auto convert_size_to_integer(char const value) noexcept -> conditional_t< is_signed_v< char >, int8_t, uint8_t >
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:44
constexpr auto convert_size_to_integer(float const value) noexcept -> std::int64_t
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:110
constexpr auto convert_size_to_integer(unsigned short const value) noexcept -> unsigned short
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:79
constexpr auto convert_size_to_integer(double const value) noexcept -> std::int64_t
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:117
constexpr bool is_nothrow_convertible_to_integral_v
Type trait to check if a type is implicitly convertible to an integral type without throwing....
constexpr auto convert_size_to_integer(unsigned char const value) noexcept -> uint8_t
Overloaded internal function to handle Size types that are "convertible to an integer" rather than be...
Definition copy_n.hpp:52
constexpr bool is_convertible_to_integral_v
Type trait to check if a type is implicitly convertible to an integral type. The value is true if so,...
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827