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"
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"
22// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
23
24namespace arene {
25namespace 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///
43template <
44 typename Itr,
45 typename Sent,
46 typename T,
50constexpr void fill(
51 Itr first,
52 Sent last,
53 T const& value
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_
Type trait to detect if an instance of To is assignable to from arguments of From without throwing.
Definition is_assignable.hpp:78
Definition accumulate.hpp:37
constexpr bool denotes_nothrow_iterable_range_v
Check if an iterator/sentinel pair form an iterable range that can be iterated without throwing.
constexpr void fill(Itr first, Sent last, T const &value) noexcept(std::is_nothrow_assignable<, T const & >::value &&denotes_nothrow_iterable_range_v< Itr, Sent >)
Assigns all elements in a sequence to a given value.
Definition fill.hpp:50
constexpr auto make_subrange(Iterator iterator, Sentinel sentinel) noexcept(std::is_nothrow_move_constructible< Iterator >::value &&//std::is_nothrow_move_constructible< Sentinel >::value) -> make_subrange_detail::iterator_range< Iterator, Sentinel >
Combine an iterator and sentinel into a range type that can be used with range-based for loops.
Definition make_subrange.hpp:98
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41