Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
fill.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
///
6
/// @file fill.hpp
7
/// @brief Provides implementation of constexpr backport of @c std::fill
8
///
9
#
ifndef
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FILL_HPP_
10
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FILL_HPP_
11
12
// IWYU pragma: private, include "arene/base/algorithm.hpp"
13
// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
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/constraints/constraints.hpp"
17
#
include
"arene/base/stdlib_choice/declval.hpp"
18
#
include
"arene/base/stdlib_choice/enable_if.hpp"
19
#
include
"arene/base/stdlib_choice/is_assignable.hpp"
20
#
include
"arene/base/type_traits/denotes_range.hpp"
21
#
include
"arene/base/utility/make_subrange.hpp"
22
// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
23
24
namespace
arene
{
25
namespace
base
{
26
27
///
28
/// @brief Assigns all elements in a sequence to a given value.
29
///
30
/// @tparam Itr The type of the iterator for the sequence. Its @c reference must be @c std::assignable from @c T
31
/// @tparam Sent The type of the sentinel to mark the end of the sequence. It must be inequality comparable with @c Itr
32
/// @tparam T The type of the value to fill the sequence with.
33
/// @param first Iterator to the first position in the sequence to fill.
34
/// @param last Sentinel to mark the end of the sequence to fill.
35
/// @param value The value to fill the sequence with.
36
/// @post All elements in the sequence @c [first,last) will have their element assigned to @c value
37
/// @pre Repeated incrementing of @c first must eventually produce an iterator which compares equal to @c last , else
38
/// behavior is undefined.
39
///
40
/// Performs exactly @c std::distance(first,last) assignments of @c value . Backport of the @c constexpr
41
/// [std::fill](https://en.cppreference.com/w/cpp/algorithm/fill) from C++20 .
42
///
43
template
<
44
typename
Itr
,
45
typename
Sent
,
46
typename
T
,
47
constraints
<
48
std
::
enable_if_t
<
denotes_range_v
<
Itr
,
Sent
>>,
49
std
::
enable_if_t
<
std
::
is_assignable
<
decltype
(*
std
::
declval
<
Itr
>()),
T
const
&>::
value
>> =
nullptr
>
50
constexpr
void
fill
(
51
Itr
first
,
52
Sent
last
,
53
T
const
&
value
54
)
noexcept
(
std
::
is_nothrow_assignable
<
decltype
(*
std
::
declval
<
Itr
>()),
T
const
&>::
value
&&
denotes_nothrow_iterable_range_v
<
Itr
,
Sent
>) {
55
for
(
auto
&
element
:
make_subrange
(
first
,
last
)) {
56
element
=
value
;
57
}
58
}
59
60
}
// namespace base
61
}
// namespace arene
62
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ALGORITHM_FILL_HPP_
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
algorithm
fill.hpp
Generated by
1.13.2