Search code examples
c++range-v3

ranges-v3 access cursor internals


In c++ range-v3 library.

Is it possible to access cursor's (from view_facade) internal data?

class range_t : public ranges::view_facade<range_t>
{
    friend ranges::range_access;

    struct cursor {
        cursor() = default;
        cursor(FlatMultiMap& self, std::size_t index)
            : self(&self)
            , index(index)
        {}

        // other implementation stuff
    private:
        // I want to get this data from outside cursor class
        FlatMultiMap* self;
        std::size_t   index;
    };

    cursor begin_cursor() const
    {
        return { *self, index };
    }
    cursor end_cursor() const
    {
        return { *self, end_index };
    }

    FlatMultiMap* self;
    std::size_t   index;
    std::size_t   end_index;

public:
    range_t() = default;
    range_t(FlatMultiMap& self, std::size_t index, std::size_t end_index)
        : self(&self)
        , index(index)
        , end_index(end_index)
    {}

    template<class I, class S>
    range_t(I iterator, S sentinel)
    {
         // how to do this?
         iterator.self  // Error
    }

};

If no - does range-v3 provide something like https://www.boost.org/doc/libs/1_68_0/libs/iterator/doc/iterator_facade.html ?


Solution

  • To access/expose cursor internal data, one need to use cursor's mixin.

    It is now documented https://ericniebler.github.io/range-v3/ at "Create Custom Iterators" section.