This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
function object's dtor called several times when passed to for_each()
- To: egcs-bugs at cygnus dot com
- Subject: function object's dtor called several times when passed to for_each()
- From: Guillaume Laurent <glaurent at worldnet dot fr>
- Date: 05 Feb 1999 19:57:13 +0100
With egcs 1.1b, the dtor of a function object passed to for_each() is
called several times (4 times under linux RH5.2, 3 times only under
solaris 2.5).
Here's a sample reproducing the problem :
----8<-----------------------------------
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
class FTor : public unary_function<int, bool>
{
public:
FTor(int i);
~FTor();
bool operator()(argument_type i) {cout << "operator() : " << i << endl;}
};
FTor::FTor(int i)
{
cout << "FTor ctor : i = " << i << endl;
}
FTor::~FTor()
{
static unsigned int count = 0;
cout << "FTor dtor : count = " << count++ << endl;
}
int main(int argc, char *argv[])
{
vector<int> myvec;
for(int i = 0; i < 5; i++)
myvec.push_back(i);
FTor f(12);
for_each(myvec.begin(), myvec.end(), f);
return EXIT_SUCCESS;
}
--
Guillaume.
http://www.worldnet.fr/~glaurent