Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_indirectly_readable.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#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_IS_INDIRECTLY_READABLE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_IS_INDIRECTLY_READABLE_HPP_
7
14#include "arene/base/stdlib_choice/declval.hpp"
15#include "arene/base/stdlib_choice/enable_if.hpp"
16#include "arene/base/stdlib_choice/integral_constant.hpp"
17#include "arene/base/stdlib_choice/is_same.hpp"
20
21// IWYU pragma: private, include "arene/base/iterator.hpp"
22// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
23
24namespace arene {
25namespace base {
26namespace is_indirectly_readable_detail {
27
28/// @brief Computes the type resulting from dereferencing a const lvalue of the given iterator type.
29/// @tparam Itr The iterator type for which to determine the dereference result type.
30template <typename Itr>
31using const_reference_t = decltype(*std::declval<Itr const&>());
32
33/// @brief Computes the type resulting from moving from a const lvalue of the given iterator type.
34/// @tparam Itr The iterator type for which to determine the iter_move result type.
35template <typename Itr>
36using const_iter_move_t = decltype(ranges::iter_move(std::declval<Itr const&>()));
37
38/// @brief helper variable template for implementing @c is_indirectly_readable_v for when one of the required types is
39/// not defined
40/// @tparam Itr The iterator type
41/// @see is_indirectly_readable_v
42/// The default implementation is false
43template <typename Itr, typename = constraints<>>
44extern constexpr bool is_indirectly_readable{false};
45
46/// @brief helper variable template for implementing @c is_indirectly_readable_v for when all of the required types are
47/// defined
48/// @tparam Itr The iterator type
49/// @see is_indirectly_readable_v
50template <typename Itr>
51// parasoft-begin-suppress CERT_CPP-DCL56-a "False positive: variable 'is_indirectly_readable' is initialized"
52extern constexpr bool is_indirectly_readable<
53 Itr,
60 //
61 std::is_same<const_reference_t<Itr>, iter_reference_t<Itr>>::value &&
62 std::is_same<const_iter_move_t<Itr>, iter_rvalue_reference_t<Itr>>::value &&
66};
67// parasoft-end-suppress CERT_CPP-DCL56-a
68
69} // namespace is_indirectly_readable_detail
70
71/// @brief Query trait to determine if an iterator is indirectly readable. A backport of the
72/// @c [std::indirectly_readable](https://en.cppreference.com/w/cpp/iterator/indirectly_readable) concept.
73/// @tparam Itr The iterator type
74/// @return bool @c true if all of the following are satisfied, else @c false :
75/// - @c iter_value_t<Itr> is defined
76/// - @c iter_reference_t<Itr> is defined
77/// - @c iter_rvalue_reference_t<Itr> is defined
78/// - <c>decltype(*std::declval<Itr const&>())</c> is the same type as @c iter_reference_t<Itr>
79/// - <c>decltype(ranges::iter_move(std::declval<Itr const&>()))</c> is the same type as @c iter_rvalue_reference_t<Itr>
80/// - @c iter_reference_t<Itr>&& and @c iter_value_t<Itr>& satisfy @c has_common_reference_with_v
81/// - @c iter_reference_t<Itr>&& and @c iter_rvalue_reference_t<Itr>&& satisfy @c has_common_reference_with_v
82/// - @c iter_rvalue_reference_t<Itr>&& and <c>iter_value_t<Itr> const&</c> satisfy @c has_common_reference_with_v
83template <typename Itr>
84extern constexpr bool
85 is_indirectly_readable_v{is_indirectly_readable_detail::is_indirectly_readable<remove_cvref_t<Itr>>};
86
87/// @brief Trait to determine if an iterator is indirectly readable.
88/// @tparam Itr The iterator type
89/// The member @c value is equivalent to @c is_indirectly_readable_v<Itr>.
90template <typename Itr>
91class is_indirectly_readable : public std::integral_constant<bool, is_indirectly_readable_v<Itr>> {};
92
93} // namespace base
94} // namespace arene
95
96#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_IS_INDIRECTLY_READABLE_HPP_
Trait to determine if an iterator is indirectly readable.
Definition is_indirectly_readable.hpp:91
A helper class to represent a compile-time constant with the specified type and value....
Definition integral_constant.hpp:23
Definition accumulate.hpp:37
typename indirectly_readable_traits< remove_cvref_t< Itr > >::value_type iter_value_t
Determins the value type of the given iterator.
Definition iter_value_t.hpp:29
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
constexpr bool is_indirectly_readable_v
Query trait to determine if an iterator is indirectly readable. A backport of the [std::indirectly_re...
constexpr bool has_common_reference_with_v
Query trait to determine if two types have a common reference. A backport of the [std::common_referen...
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
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,...