constant_iterator#
-
template<class _Tp, class _Index = ::cuda::std::ptrdiff_t>
class constant_iterator# The
constant_iterator
class represents an iterator in an infinite sequence of repeated values.This iterator is useful for creating a range filled with the same value without explicitly storing it in memory. Using
constant_iterator
saves both memory capacity and bandwidth.The following code snippet demonstrates how to create a
constant_iterator
whosevalue_type
isint
and whose value is10
.#include <cuda/iterator> cuda::constant_iterator iter(10); *iter; // returns 10 iter[0]; // returns 10 iter[1]; // returns 10 iter[13]; // returns 10 // and so on...
- Template Parameters:
_Tp – the value type of the
constant_iterator
._Index – The index type of the
constant_iterator
. It can optionally be specified, but must satisfy integer-like
Public Types
-
using iterator_concept = ::cuda::std::random_access_iterator_tag#
-
using iterator_category = ::cuda::std::random_access_iterator_tag#
-
using difference_type = ::cuda::std::ptrdiff_t#
Public Functions
-
template<class _Tp2 = _Tp, ::cuda::std::enable_if_t<::cuda::std::default_initializable<_Tp2>, int> = 0>
inline constexpr constant_iterator(
- inline constexpr constant_iterator(
- _Tp __value,
Creates a
constant_iterator
from a value.The index is set to zero
- Parameters:
__value – The value to store in the
constant_iterator
-
template<typename _Index2, ::cuda::std::enable_if_t<::cuda::std::__integer_like<_Index2>, int> = 0>
inline explicit constexpr constant_iterator(
) noexcept(::cuda::std::is_nothrow_move_constructible_v<_Tp>)# Creates
constant_iterator
from a value and an index.- Parameters:
__value – The value to store in the
constant_iterator
__index – The index in the sequence represented by this
constant_iterator
-
inline constexpr difference_type index() const noexcept#
Returns a the current index.
-
inline constexpr const _Tp &operator*() const noexcept#
Returns a const reference to the stored value.
- inline constexpr const _Tp &operator[]( ) const noexcept#
Returns a const reference to the stored value.
-
inline constexpr constant_iterator &operator++() noexcept#
Increments the stored index.
- inline constexpr constant_iterator operator++(
- int,
Increments the stored index.
-
inline constexpr constant_iterator &operator--() noexcept#
Decrements the stored index.
- inline constexpr constant_iterator operator--(
- int,
Decrements the stored index.
- inline constexpr constant_iterator &operator+=(
- difference_type __n,
Advances a
constant_iterator
by a given number of elements.- Parameters:
__n – The amount of elements to advance
- inline constexpr constant_iterator &operator-=(
- difference_type __n,
Decrements a
constant_iterator
by a given number of elements.- Parameters:
__n – The amount of elements to decrement
Friends
- inline friend constexpr constant_iterator operator+(
- constant_iterator __iter,
- difference_type __n,
Creates a copy of a
constant_iterator
advanced by a given number of elements.- Parameters:
__iter – The
constant_iterator
to advance__n – The amount of elements to advance
- inline friend constexpr constant_iterator operator+(
- difference_type __n,
- constant_iterator __iter,
Creates a copy of a
constant_iterator
advanced by a given number of elements.- Parameters:
__n – The amount of elements to advance
__iter – The
constant_iterator
to advance
- inline friend constexpr constant_iterator operator-(
- constant_iterator __iter,
- difference_type __n,
Creates a copy of a
constant_iterator
decremented by a given number of elements.- Parameters:
__n – The amount of elements to decrement
__iter – The
constant_iterator
to decrement
- inline friend constexpr difference_type operator-(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Returns the distance between two
constant_iterator
.
- inline friend constexpr bool operator==(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Compares two
constant_iterator
for equality by comparing the index in the sequence.
- inline friend constexpr bool operator<(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Compares two
constant_iterator
for less than by comparing the index in the sequence.
- inline friend constexpr bool operator<=(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Compares two
constant_iterator
for less equal by comparing the index in the sequence.
- inline friend constexpr bool operator>(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Compares two
constant_iterator
for greater than by comparing the index in the sequence.
- inline friend constexpr bool operator>=(
- const constant_iterator &__lhs,
- const constant_iterator &__rhs,
Compares two
constant_iterator
for greater equal by comparing the index in the sequence.
-
template<class _Tp>
inline constexpr auto make_constant_iterator( - _Tp __value,
- ::cuda::std::ptrdiff_t __index = 0,
Creates a
constant_iterator
from a value and an index.- Parameters:
__value – The value to be stored
__index – The optional index representing the position in a sequence. Defaults to 0.