i'll keep it short, hope this doesn't sound lazy:
i need to make a functor that can act upon any stl container when given an iterator.
best analog that comes to mind is std::make_heap.
i just cant wrap my head around how to do that...
This is a discussion on help with a functor within the C++ Programming forums, part of the General Programming Boards category; i'll keep it short, hope this doesn't sound lazy: i need to make a functor that can act upon any ...
i'll keep it short, hope this doesn't sound lazy:
i need to make a functor that can act upon any stl container when given an iterator.
best analog that comes to mind is std::make_heap.
i just cant wrap my head around how to do that...
Just define your operator ():
I chose to return a reference to the functor (standard approach), but you can return whatever you like - even void.Code:class SomeProcess { public: template <typename Iterator> const SomeProcess& operator ()(Iterator pos, Iterator end) { // do something useful... return *this; } template <typename Container> const SomeProcess& operator ()(Container& box) { return (*this)(box.begin(), box.end()); } };
Oh, and if you design a functor to operate on an object within a container, you could use it in functions like std::for_each, etc.