I use typedef to determine the type of container in my program so that I can easily switch between regular STL and STXXL containers , according to:
typedef stxxl:vector<Data> MyContainer;
or
typedef std:vector<Data> MyContainer;
One of the difficulties lies in the fact that STXXL provides a special version std::for_each, stxxl::for_eachoptimized for use with STXXL containers. I would prefer to use this function when MyContainer is entered as stxxl::vector.
One solution would be to define my own function for_eachthat calls the correct function for_eachand use it whenever I want to call for_each.
Another solution that I am currently studying is overload / specialization std::foreachso that stxxl::for_eachit invokes whenever it is called with stxxl::vector<Data>::(const_)iteratorboth the first and second arguments.
I can not get the second idea to work. I tried the following:
namespace std
{
template <class UnaryFunction>
UnaryFunction for_each(stxxl:vector<Data>::const_iterator first,
stxxl:vector<Data>::const_iterator last, UnaryFunction f)
{
stxxl::for_each(first, last, f, 4);
}
}
Along with a similar function for non-constant iterators. They are not called though.
What would be the preferred solution to this problem? How can I get my version std::for_eachfor stxxl::vectoriterators to call?
Update: I got a second idea to work now, as published. The problem was that I included the wrong file (ouch ...). The first question remains, though: What is the preferred solution to this problem? Is it possible to overload std :: for_each since the std namespace is not intended for mere mortals?