0

This is the line causing the issue:

auto it = find_if(menus->begin(), menus->end(), [](MenuComponent* m){return true;});

My iterator is defined as:

class ComponentIterator : std::iterator< std::forward_iterator_tag, MenuComponent* > 

It has ++, ==, !=, *, -> all defined. This iterator also works with the following line:

auto it = copy_if(menus->begin(), menus->end(), othermenu.begin(), [](MenuComponent* m){return true;});

g++ 4.8.1 output is as follows:

In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from main.cpp:2:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = ComponentIterator; _Predicate = main()::__lambda0]’:
main.cpp:211:97:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:4465:40: error: no matching function for call to ‘__iterator_category(ComponentIterator&)’
        std::__iterator_category(__first));
                                        ^
/usr/include/c++/4.8/bits/stl_algo.h:4465:40: note: candidate is:
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/string:40,
                 from main.cpp:1:
/usr/include/c++/4.8/bits/stl_iterator_base_types.h:201:5: note: template<class _Iter> typename std::iterator_traits<_Iterator>::iterator_category std::__iterator_category(const _Iter&)
     __iterator_category(const _Iter&)
     ^
/usr/include/c++/4.8/bits/stl_iterator_base_types.h:201:5: note:   template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/stl_iterator_base_types.h: In substitution of ‘template<class _Iter> typename std::iterator_traits<_Iterator>::iterator_category std::__iterator_category(const _Iter&) [with _Iter = ComponentIterator]’:
/usr/include/c++/4.8/bits/stl_algo.h:4465:40:   required from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = ComponentIterator; _Predicate = main()::__lambda0]’
main.cpp:211:97:   required from here
/usr/include/c++/4.8/bits/stl_iterator_base_types.h:201:5: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<ComponentIterator>’
make: *** [main.o] Error 1

Any ideas?

Zambezi
  • 767
  • 1
  • 9
  • 19
  • Hard to help without code. Can you provide a compilable example the demonstrates the problem. – Martin York Jul 27 '15 at 02:03
  • I guess you didn't add a `typedef` for `iterator_category`, nor specialise `std::iterator_traits`? Might help to have a read of [this](http://stackoverflow.com/questions/8054273/how-to-implement-an-stl-style-iterator-and-avoid-common-pitfalls). – Tony Delroy Jul 27 '15 at 02:04

1 Answers1

1

Most likely cause is that the inheritance of class ComponentIterator : blah blah is private.

Like Loki says in comments though, it's hard to be sure without a usable example to confirm that switching it to public solves the problem.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699