Skip to content

Instantly share code, notes, and snippets.

@eao197
Created September 12, 2025 06:04
Show Gist options
  • Select an option

  • Save eao197/21aee004eff17ab81f3f3f6e4dce92dd to your computer and use it in GitHub Desktop.

Select an option

Save eao197/21aee004eff17ab81f3f3f6e4dce92dd to your computer and use it in GitHub Desktop.
Types of iterators from std::ranges::view::iota
#include <iostream>
#include <ranges>
#include <type_traits>
int main()
{
auto r = std::ranges::views::iota(std::size_t{0u}, std::size_t{10});
using begin_it_t = std::decay_t< decltype(r.begin()) >;
using end_it_t = std::decay_t< decltype(r.end()) >;
if constexpr( std::same_as< begin_it_t, end_it_t > )
std::cout << "iterators of the same type" << std::endl;
else
std::cout << "iterators of different types" << std::endl;
if constexpr( std::sentinel_for< end_it_t, begin_it_t > )
std::cout << "end_it is sentinel for begin_it" << std::endl;
else
std::cout << "end_it is not sentinel for begin_it" << std::endl;
if constexpr( std::sized_sentinel_for< end_it_t, begin_it_t > )
std::cout << "end_it is sized_sentinel for begin_it" << std::endl;
else
std::cout << "end_it is not sized_sentinel for begin_it" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment