Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
iterator_traits.hpp
Go to the documentation of this file.
1
// Copyright 2024, Toyota Motor Corporation
2
//
3
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5
#
ifndef
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_ITERATOR_TRAITS_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_ITERATOR_TRAITS_HPP_
7
8
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11
// IWYU pragma: private, include <iterator>
12
13
#
include
"arene/base/constraints.hpp"
14
#
include
"stdlib/include/stdlib_detail/cstddef.hpp"
15
#
include
"stdlib/include/stdlib_detail/iterator_tags.hpp"
16
17
namespace
std
{
18
namespace
iterator_traits_detail
{
19
20
/// @brief base type for non-iterator types
21
/// @tparam Iter non-iterator type
22
///
23
/// Provides an empty type to be used as a base class if @c iterator_traits is
24
/// used with a non-iterator. Use of the base class allows @c iterator_traits to
25
/// be SFINAE-friendly.
26
///
27
template
<
class
Iter,
typename
=
arene
::
base
::
constraints
<>>
28
class
iterator_traits_base
{};
29
30
/// @brief base type for iterator types
31
/// @tparam Iter iterator type
32
///
33
/// This base type for @c iterator_traits is selected when the @c Iter type
34
/// defines all of the following member type aliases:
35
/// * difference_type
36
/// * value_type
37
/// * pointer
38
/// * reference
39
/// * iterator_category
40
///
41
template
<
class
Iter
>
42
class
iterator_traits_base
<
43
Iter
,
44
arene
::
base
::
constraints
<
45
typename
Iter
::
difference_type
,
46
typename
Iter
::
value_type
,
47
typename
Iter
::
reference
,
48
typename
Iter
::
pointer
,
49
typename
Iter
::
iterator_category
>> {
50
public
:
51
/// @brief difference_type
52
using
difference_type
=
typename
Iter
::
difference_type
;
53
/// @brief value_type
54
using
value_type
=
typename
Iter
::
value_type
;
55
/// @brief pointer
56
using
pointer
=
typename
Iter
::
pointer
;
57
/// @brief reference
58
using
reference
=
typename
Iter
::
reference
;
59
/// @brief iterator_category
60
using
iterator_category
=
typename
Iter
::
iterator_category
;
61
};
62
63
}
// namespace iterator_traits_detail
64
65
/// @brief provides a uniform interface to the properties of an iterator
66
/// @tparam Iter iterator type to retrieve properties for
67
///
68
/// @c std::iterator_traits is a type trait class that provides a uniform
69
/// interface to the properties of Iterator types, allowing implementations of
70
/// algorithms only in terms of iterators.
71
///
72
/// This template can be specialized for user-defined Iterator types so that the
73
/// information about the iterator can be retrieved even if type does not
74
/// provide the usual typedefs.
75
///
76
/// The member types provided by this type trait class are:
77
///
78
/// | ** nested type ** | ** definition ** |
79
/// |----------------------|----------------------------|
80
/// | @c difference_type | @c Iter::difference_type |
81
/// | @c value_type | @c Iter::value_type |
82
/// | @c pointer | @c Iter::pointer |
83
/// | @c reference | @c Iter::reference |
84
/// | @c iterator_category | @c Iter::iterator_category |
85
///
86
/// @note This class is SFINAE-friendly: if a type does not define *all* the
87
/// member types listed above, then @c iterator_traits is empty for that type.
88
///
89
template
<
class
Iter>
90
class
iterator_traits
:
public
iterator_traits_detail
::
iterator_traits_base
<
Iter
> {};
91
92
/// @brief specialization for pointer to non-const type
93
/// @tparam T type
94
///
95
template
<
class
T>
96
class
iterator_traits
<T*> {
97
public
:
98
/// @brief difference_type
99
using
difference_type
=
std
::
ptrdiff_t
;
100
/// @brief value_type
101
using
value_type = T;
102
/// @brief pointer
103
using
pointer = T*;
104
/// @brief reference
105
using
reference = T&;
106
/// @brief iterator_category
107
using
iterator_category
=
std
::
random_access_iterator_tag
;
108
};
109
110
/// @brief specialization for pointer to const type
111
/// @tparam T type
112
///
113
template
<
class
T>
114
class
iterator_traits
<T
const
*> {
115
public
:
116
/// @brief difference_type
117
using
difference_type
=
std
::
ptrdiff_t
;
118
/// @brief value_type
119
using
value_type = T;
120
/// @brief pointer
121
using
pointer = T
const
*;
122
/// @brief reference
123
using
reference = T
const
&;
124
/// @brief iterator_category
125
using
iterator_category
=
std
::
random_access_iterator_tag
;
126
};
127
128
}
// namespace std
129
130
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_ITERATOR_TRAITS_HPP_
std::iterator_traits_detail::iterator_traits_base
base type for non-iterator types
Definition
iterator_traits.hpp:28
std::iterator_traits
provides a uniform interface to the properties of an iterator
Definition
iterator_traits.hpp:90
std::iterator_traits_detail
Definition
iterator_traits.hpp:18
std::hash<::arene::base::result< void, E > >::operator()
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition
result.hpp:1827
stdlib
include
stdlib_detail
iterator_traits.hpp
Generated by
1.13.2