Boost logo

Boost :

Subject: Re: [boost] [iterator] Using iterator_facade with range-v3
From: Krzysztof Czainski (1czajnik_at_[hidden])
Date: 2016-04-20 11:20:00


Maybe a high-level example demonstrating the problem will be helpful:

#include <iostream>

#include "third_party/boost/allowed/iterator/iterator_facade.hpp"
#include "third_party/range_v3/include/range/v3/algorithm/copy.hpp"
#include "third_party/range_v3/include/range/v3/iterator_range.hpp"
#include "third_party/range_v3/include/range/v3/utility/iterator.hpp"

template <class V, class Category>
class TestIter
    : public boost::iterator_facade<TestIter<V, Category>, V, Category, V> {
 public:
  using typename boost::iterator_facade<TestIter<V, Category>, V, Category,
                                        V>::difference_type;

  TestIter() : v_() {}

  explicit TestIter(V v) : v_(v) {}

 private:
  friend class boost::iterator_core_access;

  V dereference() const { return v_; }
  bool equal(const TestIter& other) const { return v_ == other.v_; }
  void increment() { ++v_; }
  void decrement() { --v_; }
  void advance(difference_type n) { v_ += n; }
  difference_type distance_to(const TestIter& other) const {
    return other.v_ - v_;
  }

  V v_;
};

using InIter = TestIter<int, std::input_iterator_tag>;

template <class R>
void print(R&& r) {
  ranges::copy(std::forward<R>(r), ranges::ostream_iterator<>(std::cout, ",
"));
  std::cout << "\n";
}

int main() {
  print(ranges::make_iterator_range(InIter(1), InIter(10)));
}

2016-04-11 16:34 GMT+02:00 Krzysztof Czainski <1czajnik_at_[hidden]>:

> I'm having trouble using iterators implemented in terms of
> boost::iterator_facade with the range-v3 library.
>
> The problem is decltype(it++) which in my case
> is postfix_increment_proxy<>, desn't model the Readable concept, because it
> isn't DefaultConstructible and doesn't have a ppublic value_type nested
> typedef.
>
> To me it seems reasonable to require decltype(it++) to model Readable, so
> I created a ticket (a test case and a patch with the proposed solution
> included) please see:
> https://svn.boost.org/trac/boost/ticket/12071
>
> See also the discussion at range-v3:
> https://github.com/ericniebler/range-v3/issues/304
>
> Kind regards,
> Kris
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk