Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
is_weakly_incrementable.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_WEAKLY_INCREMENTABLE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_IS_WEAKLY_INCREMENTABLE_HPP_
7
8// IWYU pragma: private, include "arene/base/iterator.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
15#include "arene/base/stdlib_choice/declval.hpp"
16#include "arene/base/stdlib_choice/enable_if.hpp"
17#include "arene/base/stdlib_choice/integral_constant.hpp"
18#include "arene/base/stdlib_choice/is_integral.hpp"
19#include "arene/base/stdlib_choice/is_same.hpp"
20#include "arene/base/stdlib_choice/is_signed.hpp"
21#include "arene/base/stdlib_choice/remove_cv.hpp"
22#include "arene/base/stdlib_choice/remove_reference.hpp"
24// parasoft-end-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
25
26namespace arene {
27namespace base {
28
29namespace weakly_incrementable_detail {
30
31/// @brief Computes the type resulting from the post-increment operation on the given iterator type.
32/// @tparam Itr The iterator type for which to compute the post-increment result type.
33template <typename Itr>
34using post_increment_t = decltype(std::declval<Itr&>()++);
35
36/// @brief Checks if the given iterator type has a valid post-increment operation.
37/// @tparam Itr The iterator type to be checked.
38template <typename Itr>
39constexpr bool has_post_increment_v = substitution_succeeds<post_increment_t, Itr>;
40
41/// @brief Computes the type resulting from the pre-increment operation on the given iterator type.
42/// @tparam Itr The iterator type for which to compute the pre-increment result type.
43template <typename Itr>
44using pre_increment_t = decltype(++std::declval<Itr&>());
45
46/// @brief Implementation helper for determining if an iterator type models the weakly incrementable concept.
47/// @tparam Itr The iterator type to be checked.
48/// @note The default specialization is false
49/// @see ::arene::base::is_weakly_incrementable
50template <typename Itr, typename = constraints<>>
51class weakly_incrementable_impl : public std::false_type {};
52
53/// @brief Specialization of weakly_incrementable_impl for iterators that satisfy all weakly incrementable requirements.
54/// @tparam Itr The iterator type to be checked.
55/// @see ::arene::base::is_weakly_incrementable<Itr>
56template <typename Itr>
57class weakly_incrementable_impl<
58 Itr,
60 std::enable_if_t<is_movable_v<Itr>>,
61 std::enable_if_t<std::is_same<pre_increment_t<Itr>, Itr&>::value>,
62 std::enable_if_t<has_post_increment_v<Itr>>,
63 std::enable_if_t<std::is_integral<iter_difference_t<Itr>>::value>,
64 std::enable_if_t<std::is_signed<iter_difference_t<Itr>>::value>>> : public std::true_type {};
65
66} // namespace weakly_incrementable_detail
67
68/// @brief A trait which validates if an iterator models pre/post-increment operations without requiring equality
69/// preservation.
70///
71/// @tparam Itr The type of the iterator to be checked.
72///
73/// An iterator models the weakly incrementable concept if all of the following are true:
74/// 1. The iterator is movable.
75/// 2. The iterator supports pre-increment (++itr) returning a reference to itself.
76/// 3. The iterator supports post-increment (itr++).
77/// 4. The iterator has a valid difference type (iter_difference_t<Itr>) and it is a signed integral type.
78///
79/// @note Condition 4 is a strengthening compared to @c std::is_weakly_incrementable , which requires a valid difference
80/// type which is only a _signed integer like_ type. Implementing the integer-like requirement is extremely difficult in
81/// C++14, so the stricter @c std::is_signed and @c std::is_integral traits are used instead.
82template <typename Itr>
83class is_weakly_incrementable : public weakly_incrementable_detail::weakly_incrementable_impl<Itr> {};
84
85/// @brief Predicate trait for checking if an iterator models the weakly incrementable concept.
86/// @tparam Itr The iterator type to be checked.
87/// @return bool @c is_weakly_incrementable<Itr>::value
88/// @see ::arene::base::is_weakly_incrementable<Itr>
89template <typename Itr>
91
92} // namespace base
93} // namespace arene
94
95#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_IS_WEAKLY_INCREMENTABLE_HPP_
A trait which validates if an iterator models pre/post-increment operations without requiring equalit...
Definition is_weakly_incrementable.hpp:83
static constexpr value_type value
Definition integral_constant.hpp:34
Definition accumulate.hpp:37
constexpr bool substitution_succeeds
Determines if a template can be instantiated successfully, similar to C++20's requires clause.
constexpr bool is_weakly_incrementable_v
Predicate trait for checking if an iterator models the weakly incrementable concept.
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
bool_constant< false > false_type
An alias for bool_constant<false>
Definition integral_constant.hpp:79
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
bool_constant< true > true_type
An alias for bool_constant<true>
Definition integral_constant.hpp:76
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...