Skip to content

Commit 50c99c2

Browse files
[oneDPL] Improve requirements for iterator source types (#550)
Improve requirements for iterator source types to set more explicit requirements -------- Signed-off-by: Dan Hoeflinger <[email protected]> Co-authored-by: Alexey Kukanov <[email protected]>
1 parent eeac4e8 commit 50c99c2

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

source/elements/oneDPL/source/parallel_api.rst

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ Iterators
2424
The oneDPL iterators are defined in the ``<oneapi/dpl/iterator>`` header,
2525
in ``namespace oneapi::dpl``.
2626

27+
Let us define a named requirement, ``AdaptingIteratorSource``, to describe valid random access iterator-like
28+
types that can be used as source for oneDPL iterators as described below.
29+
The type ``Iter`` satisfies the ``AdaptingIteratorSource`` named requirement if it is any of the following:
30+
31+
* A random access iterator
32+
* The unspecified iterator-like type returned by ``oneapi::dpl::begin`` or ``oneapi::dpl::end``
33+
* A ``permutation_iterator``
34+
* A ``transform_iterator``
35+
* A ``counting_iterator``
36+
* A ``discard_iterator``
37+
* A ``zip_iterator``
38+
2739
.. code:: cpp
2840
2941
template <typename Integral>
@@ -153,7 +165,19 @@ defined by the source iterator provided, and whose iteration order over the dere
153165
is defined by either another iterator or a functor that maps the ``permutation_iterator`` index
154166
to the index of the source iterator. The arithmetic and comparison operators of
155167
``permutation_iterator`` behave as if applied to integer counter values maintained by the
156-
iterator instances to determine their position in the index map.
168+
iterator instances to determine their position in the index map. ``SourceIterator`` must satisfy
169+
``AdaptingIteratorSource``.
170+
171+
The type ``IndexMap`` must be one of the following:
172+
173+
* A random access iterator
174+
* The unspecified iterator-like type returned by ``oneapi::dpl::begin`` or ``oneapi::dpl::end``
175+
* A ``permutation_iterator``
176+
* A ``transform_iterator``
177+
* A ``counting_iterator``
178+
* A functor with a signature equivalent to ``T operator()(const T&) const`` where ``T`` is a
179+
``std::iterator_traits<SourceIterator>::difference_type``
180+
157181

158182
``permutation_iterator::operator*`` uses the counter value of the instance on which
159183
it is invoked to index into the index map. The corresponding value in the map is then used
@@ -222,7 +246,8 @@ defined by the unary function and source iterator provided. When dereferenced,
222246
element of the source iterator; dereference operations cannot be used to modify the elements of
223247
the source iterator unless the unary function result includes a reference to the element. The
224248
arithmetic and comparison operators of ``transform_iterator`` behave as if applied to the
225-
source iterator itself.
249+
source iterator itself. The template type ``Iterator`` must satisfy
250+
``AdaptingIteratorSource``.
226251

227252
.. code:: cpp
228253
@@ -280,7 +305,8 @@ using the source iterator and unary function object provided.
280305
the value returned from ``zip_iterator`` is a tuple of the values returned by dereferencing the
281306
source iterators over which the ``zip_iterator`` is defined. The arithmetic operators of
282307
``zip_iterator`` update the source iterators of a ``zip_iterator`` instance as though the
283-
operation were applied to each of these iterators.
308+
operation were applied to each of these iterators. The types ``T`` within the template pack
309+
``Iterators...`` must satisfy ``AdaptingIteratorSource``.
284310

285311
.. code:: cpp
286312

0 commit comments

Comments
 (0)