Skip to content

proxy_iterator_interface<T, std::random_access_iterator_tag> is not a RandomAccessIterator #81

@sdebionne

Description

@sdebionne

The zip_iterator from the documentation does not pass the RandomAccessIterator concept check from Boost.ConceptCheck. That is:

function_requires<boost::RandomAccessIterator<zip_iterator>(); 

gives:

./boost/concept_check.hpp:209:13: error: conversion from 'std::input_iterator_tag' to non-scalar type 'std::bidirectional_iterator_tag' requested

Maybe that is to be expected because the old RandomAccessIterator is not inline with the c++20 concepts one?

Here is the full snippet:

#include <boost/concept_check.hpp>

#include <boost/stl_interfaces/iterator_interface.hpp>

#include <algorithm>
#include <array>
#include <tuple>

#include <cassert>


struct zip_iterator : boost::stl_interfaces::proxy_iterator_interface<
                      zip_iterator,
                      std::random_access_iterator_tag,
                      std::tuple<int, int>,
                      std::tuple<int &, int &>>
{
    constexpr zip_iterator() noexcept : it1_(), it2_() {}
    constexpr zip_iterator(int * it1, int * it2) noexcept : it1_(it1), it2_(it2)
    {}

    constexpr std::tuple<int &, int &> operator*() const noexcept
    {
        return std::tuple<int &, int &>{*it1_, *it2_};
    }
    constexpr zip_iterator & operator += (std::ptrdiff_t i) noexcept
    {
        it1_ += i;
        it2_ += i;
        return *this;
    }
    constexpr auto operator-(zip_iterator other) const noexcept
    {
        return it1_ - other.it1_;
    }

private:
    int * it1_;
    int * it2_;
};

int main()
{
    function_requires<boost::RandomAccessIterator<zip_iterator>(); 
    return 0;
}

Context: boostorg/gil#669

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions