0

I have stumbled upon somehow stupid problem, yet I have not found any answear or even question about it. I am implementing custom transforming input iterator, and want to do something like that:

template<class T>
class my_it : 
public std::iterator<std::input_iterator_tag, T, ??? should I put anything here ??? > {
    ...
    my_proxy_with_implemented_arrow<T> operator->();
    T operator*();
    ...
};

As the type name says - proxy has implemented operator-> to get pointer behaviour. And so my question is, should I define pointer template argument in inherited std::iterator to my_proxy_with_implemented_arrow<T> and reference to T or should I keep the default values and don't care about return values?

In other words - do the types given in inherited std::iterator should be the same as the types returned by the iterator operators?

bartop
  • 9,971
  • 1
  • 23
  • 54
  • Just follow [the example](http://en.cppreference.com/w/cpp/iterator/iterator). Also note the "deprecated in C++17", so arguably you shouldn't use it at all. – nwp Nov 23 '17 at 18:50
  • Maybe it can help: https://stackoverflow.com/a/22801650/5945883 – R2RT Nov 23 '17 at 18:51
  • @nwp So what should I use? What is the alternative? And will it work with previous standards? – bartop Nov 23 '17 at 19:08
  • 1
    The alternative is to drop the inheritance and implement all the [requirements for your iterator](http://en.cppreference.com/w/cpp/concept/InputIterator) by hand, including the linked ones. – nwp Nov 23 '17 at 19:11
  • @nwp Fine, but will iterator_traits work properly if I don't define, for example, iterator tag? – bartop Nov 23 '17 at 19:20
  • Not sure what exactly you mean by iterator tag. As it says in the above mentioned documentation you need to satisfy [iterator](http://en.cppreference.com/w/cpp/concept/Iterator) which means, among other things, that `std::iterator_traits` must have a member typedef `iterator_category` and so on. If you follow all the requirements it will work properly. All the requirements include all the tags, typedefs and operators, so it probably includes your iterator tag. – nwp Nov 23 '17 at 19:26

0 Answers0