Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
iota.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::iota"
2
3// Copyright 2026, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_IOTA_HPP_
8#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_IOTA_HPP_
9
10// IWYU pragma: private, include "arene/base/algorithm.hpp"
11// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
12
13// parasoft-begin-suppress AUTOSAR-A7_1_5-a-2 "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
14
15// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
16#include "arene/base/algorithm/detail/traits.hpp"
17#include "arene/base/compiler_support/cpp14_inline.hpp"
18#include "arene/base/constraints/constraints.hpp"
19#include "arene/base/stdlib_choice/declval.hpp"
20#include "arene/base/stdlib_choice/enable_if.hpp"
21#include "arene/base/stdlib_choice/is_convertible.hpp"
22#include "arene/base/type_traits/is_invocable.hpp"
23#include "arene/base/type_traits/iterator_category_traits.hpp"
24// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
25
26// IWYU pragma: no_include "arene/base/stdlib_choice/iterator_traits.hpp"
27
28// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
29
30namespace arene {
31namespace base {
32
33namespace iota_detail {
34
35/// @brief function object providing the implementation of 'iota'
36class iota_impl_fn {
37 public:
38 /// @brief fills a range with successive increments of the starting value
39 /// @tparam ForwardIt the type of the ForwardIt
40 /// @tparam Value the type of the value
41 /// @param first ForwardIt to the beginning of the range
42 /// @param last ForwardIt to one past the end of the range
43 /// @param value initial value to fill with
44 ///
45 /// Private implementation shared by @c arene::base::iota and @c std::iota.
46 /// This function takes arguments by lvalue reference to avoid requiring
47 /// @c Value to be movable.
48 ///
49 template <
50 class ForwardIt,
51 class Value,
52 constraints<
53 std::enable_if_t<is_forward_iterator_v<ForwardIt>>,
54 std::enable_if_t<std::is_convertible<Value, algorithm_detail::iter_value_t<ForwardIt>>::value>,
55 decltype(++std::declval<Value&>())> = nullptr>
56 constexpr auto operator()(ForwardIt& first, ForwardIt& last, Value& value) const noexcept( //
57 noexcept(std::declval<ForwardIt&>() != std::declval<ForwardIt&>()) && //
58 noexcept(*std::declval<ForwardIt&>()++ = std::declval<Value&>()) && //
59 noexcept(++std::declval<Value&>()) //
60 ) //
61 -> void //
62 {
63 while (first != last) {
64 // parasoft-begin-suppress AUTOSAR-M5_2_10-a "idiomatic iterator operations permitted by M5-2-10 Permit #1"
65 *first++ = value;
66 // parasoft-end-suppress AUTOSAR-M5_2_10-a
67
68 // parasoft-begin-suppress AUTOSAR-M4_5_3-a "This function must work with all supported incrementable types"
69 // parasoft-begin-suppress AUTOSAR-M5_0_15-a "'value' is required to be an incrementable type
70 ++value;
71 // parasoft-end-suppress AUTOSAR-M4_5_3-a
72 // parasoft-end-suppress AUTOSAR-M5_0_15-a
73 }
74 }
75};
76
77/// @brief function object implementing 'iota'
78class iota_fn {
79 public:
80 /// @brief fills a range with successive increments of the starting value
81 /// @tparam ForwardIt the type of the ForwardIt
82 /// @tparam Value the type of the value
83 /// @param first ForwardIt to the beginning of the range
84 /// @param last ForwardIt to one past the end of the range
85 /// @param value initial value to fill with
86 ///
87 /// Fills the range <c> [first, last) </c> with sequentially increasing
88 /// values, starting with @c value and repetitively evaluating
89 /// <c> ++value </c>.
90 ///
91 /// @pre @c ForwardIt must satisfy the forward iterator requirements
92 /// @pre @c T is convertible to the value type of @c ForwardIt
93 /// @pre the expression <c> ++value </c> is well-formed
94 ///
95 /// @note Complexity <br>
96 /// Exactly <c> distance(first, last) </c> increments and assignments.
97 ///
98 template <
99 class ForwardIt,
100 class Value,
101 constraints<
102 std::enable_if_t<is_forward_iterator_v<ForwardIt>>,
103 std::enable_if_t<std::is_convertible<Value, algorithm_detail::iter_value_t<ForwardIt>>::value>,
104 decltype(++std::declval<Value&>())> = nullptr>
105 constexpr auto operator()(ForwardIt first, ForwardIt last, Value value) const noexcept( //
106 arene::base::is_nothrow_invocable_v<iota_impl_fn, ForwardIt&, ForwardIt&, Value&> //
107 ) //
108 -> void //
109 {
110 iota_impl_fn{}(first, last, value);
111 }
112};
113} // namespace iota_detail
114
115/// @def arene::base::iota
116/// @brief fills a range with successive increments of the starting value
117/// @copydoc arene::base::iota_detail::iota_fn::operator()
118// parasoft-begin-suppress AUTOSAR-M7_3_3-a "An unnamed namespace is used to create a per-TU reference to a global
119// object used in multiple TUs."
120// parasoft-begin-suppress CERT_CPP-DCL59-a "An unnamed namespace is used to create a per-TU reference to a global
121// object used in multiple TUs."
122ARENE_CPP14_INLINE_VARIABLE(iota_detail::iota_fn, iota);
123// parasoft-end-suppress AUTOSAR-M7_3_3-a
124// parasoft-end-suppress CERT_CPP-DCL59-a
125
126} // namespace base
127} // namespace arene
128
129#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_IOTA_HPP_
Definition array_exceptions_disabled.cpp:11
ARENE_CPP14_INLINE_VARIABLE(iota_detail::iota_fn, iota)
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10