Boost logo

Boost Users :

From: Zian Smith (smith7005_at_[hidden])
Date: 2008-02-27 01:09:25


Hello,

Can someone explain why I see 5 constructor calls here, but only 4
destructor calls? Is the bind function neglecting to destroy one of the
internal copies made or am I missing something? I understand that if I
use the "var" function, the problem is eliminated, but I'd still like
to figure this out. I'm using boost 1.33.1

-Thanks!

//=================================

#include <iostream>
#include <vector>
#include <algorithm>
#include "boost/lambda/bind.hpp"

using namespace std;
using namespace boost::lambda;

struct woot
{
        woot() { cout << "woot constr\n"; }
        woot(const woot& o) { cout << "woot copy-constr\n"; }
        ~woot() { cout << "woot destr\n"; }
};

void do_nothing(const woot& w)
{
}

int main()
{
        woot w;
        vector<char> v;
        for_each(v.begin(), v.end(), bind(do_nothing, w));
}

//=================================
Output:
-------

woot constr
woot copy-constr
woot copy-constr
woot copy-constr
woot destr
woot destr
woot copy-constr
woot destr
woot destr

      ____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net