Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
iter_rvalue_reference_t.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::iter_rvalue_reference_t"
2// Copyright 2026, Toyota Motor Corporation
3//
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5
6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_ITER_RVALUE_REFERENCE_T_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_ITER_RVALUE_REFERENCE_T_HPP_
8
9// IWYU pragma: private, include "arene/base/iterator.hpp"
10// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
11
13#include "arene/base/iterator/detail/can_reference.hpp"
14#include "arene/base/iterator/detail/is_dereferenceable.hpp"
16#include "arene/base/stdlib_choice/declval.hpp"
17#include "arene/base/stdlib_choice/enable_if.hpp"
18
19namespace arene {
20namespace base {
21
22namespace iter_rvalue_reference_detail {
23/// @brief Determines the type returned by invoking @c ranges::iter_move on the given iterator.
24/// @tparam Itr The iterator type
25template <typename Itr>
26using iter_move_t = decltype(ranges::iter_move(std::declval<Itr&>()));
27
28/// @brief Helper struct to determine the rvalue-reference type of the given iterator.
29/// @tparam Itr The iterator type
30/// The specialization case for when the iterator is not dereferenceable or its iter_move result cannot be referenced.
31template <typename Itr, typename = constraints<>>
32class iter_rvalue_reference_t;
33
34/// @brief Helper struct to determine the rvalue-reference type of the given iterator.
35/// @tparam Itr The iterator type
36/// The specialization case for when the iterator is dereferenceable and its iter_move result can be referenced.
37template <typename Itr>
38class iter_rvalue_reference_t<
39 Itr,
41 std::enable_if_t<iterator_detail::is_dereferenceable_v<Itr>>,
42 std::enable_if_t<iterator_detail::can_reference_v<iter_move_t<Itr>>>>> {
43 public:
44 /// @brief The rvalue-reference type of the given iterator.
45 using type = iter_move_t<Itr>;
46};
47} // namespace iter_rvalue_reference_detail
48
49/// @brief Determins the rvalue-reference type of the given iterator.
50/// @tparam Itr The iterator type. Must satisfy @c is_dereferenceable_v<Itr> (see below).
51///
52/// Let @c can_reference_v<T> be an exposition only trait with the following definition:
53///
54/// If @c T is a type for which the expression @c T& is well-formed, then @c true, else @c false .
55///
56/// Let @c is_dereferenceable_v<Itr> be an exposition only trait with the following definition:
57///
58/// If dereferencing an lvalue of type @c Itr is valid and yields a type @c U, its value is that of @c can_reference_v
59/// applied to @c U; otherwise, it is @c false.
60///
61///
62/// Let @c iter_mv_t be the type of the expression @c arene::base::ranges::iter_move(std::declval<Itr&>()) . If both
63/// @c is_dereferenceable_v<Itr> is satisfied and @c can_reference_v<iter_mv_t> is satisfied, then
64/// resulting type of @c iter_rvalue_reference_t will be equal to @c iter_mv_t , otherwise it will be ill-formed.
65template <typename Itr>
66using iter_rvalue_reference_t = typename iter_rvalue_reference_detail::iter_rvalue_reference_t<Itr>::type;
67
68} // namespace base
69} // namespace arene
70
71#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_ITER_RVALUE_REFERENCE_T_HPP_
Definition accumulate.hpp:37
typename iter_rvalue_reference_detail::iter_rvalue_reference_t< Itr >::type iter_rvalue_reference_t
Determins the rvalue-reference type of the given iterator.
Definition iter_rvalue_reference_t.hpp:66
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
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...