Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
iter_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_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_REFERENCE_T_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_ITER_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
12#include "arene/base/iterator/detail/is_dereferenceable.hpp"
13#include "arene/base/stdlib_choice/declval.hpp"
14
15namespace arene {
16namespace base {
17
18namespace iter_reference_detail {
19/// @brief Helper struct to determine the reference type of the given iterator.
20/// @tparam Itr The iterator type
21/// Specialization for when the iterator is not dereferenceable.
22template <typename Itr, bool = iterator_detail::is_dereferenceable_v<Itr>>
23class iter_reference_impl;
24
25/// @brief Helper struct to determine the reference type of the given iterator.
26/// @tparam Itr The iterator type
27/// Specialization for when the iterator is dereferenceable.
28template <typename Itr>
29class iter_reference_impl<Itr, true> {
30 public:
31 /// @brief The reference type of the given iterator.
32 using type = decltype(*std::declval<Itr&>());
33};
34} // namespace iter_reference_detail
35
36/// @brief Determins the reference type of the given iterator.
37/// @tparam Itr The iterator type. Must satisfy @c is_dereferenceable_v<Itr> (see below).
38///
39/// Let @c is_dereferenceable_v<Itr> be an exposition only trait with the following definition:
40///
41/// If @c *std::declval<T&>() is a valid expression and yields a type @c U for which the expression @c U&
42/// is well-formed, then @c true, else @c false .
43///
44/// If @c is_dereferenceable_v<Itr> is satisfied, then resulting type of @c iter_reference_t will be equal to
45/// @c decltype(*std::declval<Itr&>()) , otherwise it will be ill-formed.
46template <typename Itr>
47using iter_reference_t = typename iter_reference_detail::iter_reference_impl<Itr>::type;
48
49} // namespace base
50} // namespace arene
51
52#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_ITER_REFERENCE_T_HPP_
Definition accumulate.hpp:37
typename iter_reference_detail::iter_reference_impl< Itr >::type iter_reference_t
Determins the reference type of the given iterator.
Definition iter_reference_t.hpp:47
Definition accumulate.hpp:36
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...