Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
make_subrange.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::make_subrange"
2
3// Copyright 2024, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UTILITY_MAKE_SUBRANGE_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UTILITY_MAKE_SUBRANGE_HPP_
8
9// IWYU pragma: private, include "arene/base/utility.hpp"
10// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
11
12// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
13#include "arene/base/constraints/constraints.hpp"
14#include "arene/base/stdlib_choice/enable_if.hpp"
15#include "arene/base/stdlib_choice/is_copy_constructible.hpp"
16#include "arene/base/stdlib_choice/is_move_constructible.hpp"
17#include "arene/base/stdlib_choice/iterator_traits.hpp"
18#include "arene/base/stdlib_choice/move.hpp"
19#include "arene/base/type_traits/denotes_range.hpp"
20#include "arene/base/type_traits/remove_cvref.hpp"
21// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
22
23namespace arene {
24namespace base {
25
26namespace make_subrange_detail {
27
28///
29/// @brief Implementation of a simple range view around an iterator and a sentinel. Morally similar to @c std::subrange.
30///
31/// @tparam Iterator The type of the position iterator for the range
32/// @tparam Sentinel The type of the sentinel for the range
33///
34template <typename Iterator, typename Sentinel>
35class iterator_range {
36 public:
37 /// @brief The iterator type of the range
38 using iterator_type = remove_cvref_t<Iterator>;
39 /// @brief The sentinel type of the range
40 using sentinel_type = remove_cvref_t<Sentinel>;
41 /// @brief The value type of the range
42 using value_type = typename std::iterator_traits<iterator_type>::value_type;
43
44 /// @brief Construct an iterator_range from an iterator/sentinel pair
45 ///
46 /// @param itr The itr
47 /// @param sent The sent
48 constexpr iterator_range(iterator_type itr, sentinel_type sent) noexcept(
49 std::is_nothrow_move_constructible<iterator_type>::value &&
50 std::is_nothrow_move_constructible<sentinel_type>::value
51 )
52 : iterator_(std::move(itr)),
53 sentinel_(std::move(sent)) {}
54
55 /// @brief Obtain the iterator for the start of the range
56 /// @return The iterator
57 constexpr auto begin() const noexcept(std::is_nothrow_copy_constructible<iterator_type>::value) -> iterator_type {
58 return iterator_;
59 }
60 /// @brief Obtain the sentinel for the end of the range
61 /// @return The sentinel
62 constexpr auto end() const noexcept(std::is_nothrow_copy_constructible<sentinel_type>::value) -> sentinel_type {
63 return sentinel_;
64 }
65
66 private:
67 /// @brief The iterator representing the start of the subrange
68 iterator_type iterator_;
69 /// @brief The sentinel representing the end of the subrange
70 sentinel_type sentinel_;
71};
72} // namespace make_subrange_detail
73
74// parasoft-begin-suppress AUTOSAR-M3_3_2-a-2 "False positive: inline function used in multiple translation units"
75/// @brief Combine an iterator and sentinel into a range type that can be used with range-based @c for loops.
76/// @tparam Iterator The type of the position iterator for the range
77/// @tparam Sentinel The type of the sentinel for the range
78/// @param iterator The iterator
79/// @param sentinel The sentinel
80/// @return A range object for the iterator/sentinel pair
81template <
82 typename Iterator,
83 typename Sentinel,
91// parasoft-end-suppress AUTOSAR-M3_3_2-a-2
92
93} // namespace base
94} // namespace arene
95
96#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_UTILITY_MAKE_SUBRANGE_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10