This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

function object's dtor called several times when passed to for_each()



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]