Namespaces
Variants
Views
Actions

std::ranges::constant_range

From cppreference.com
< cpp‎ | ranges
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives



Dangling iterator handling
Range concepts
constant_range
(C++23)
Views

Factories




Adaptors
Range adaptor objects
Range adaptor closure objects
Helper items
 
Defined in header <ranges>
template< class T >

concept constant_range =
  ranges::input_range<T> &&

  /*constant-iterator*/<ranges::iterator_t<T>>;
(1) (since C++23)
Helper concepts
template< class T >

concept /*constant-iterator*/ =
  std::input_iterator<T> &&

  std::same_as<std::iter_const_reference_t<T>, std::iter_reference_t<T>>;
(2) (since C++23)
1) The constant_range concept is a refinement of range for which ranges::begin returns a constant iterator.
2) The exposition-only concept /*constant-iterator*/<T> is satisfied when the result of the indirection operation of the input iterator is its const reference type which implies read-only.

[edit] Example

#include <ranges>
#include <vector>
#include <string_view>
#include <span>
 
int main()
{
    static_assert(not std::ranges::constant_range<std::vector<int>>
              and std::ranges::constant_range<const std::vector<int>>
              and std::ranges::constant_range<std::string_view>
              and not std::ranges::constant_range<std::span<int>>
              and not std::ranges::constant_range<const std::span<int>>
              and std::ranges::constant_range<std::span<const int>>);
}