Opened 15 years ago

Closed 15 years ago

#1067 closed Bugs (fixed)

Function needs to use pass-by-reference internally

Reported by: Douglas Gregor Owned by: Douglas Gregor
Milestone: Boost 1.35.0 Component: function
Version: Boost 1.34.0 Severity: Optimization
Keywords: Cc:

Description

Boost.Function uses pass-by-value internally for the function object. While it is unspecified how many times the function object would be copied, we should still minimize this amount. The following code snippet illustrates how many copy constructions are performed.

struct Functor {

Functor(void)

{ std::cout << "Functor constructor (" << this << ')' << std::endl; }

Functor(const Functor&)

{ std::cout << "Functor copy constructor (" << this << ')' << std::endl; }

~Functor(void)

{ std::cout << "Functor destructor (" << this << ')' << std::endl; }

void operator()(void) const

{ std::cout << "Hello world!" << std::endl; }

std::string memfunc(void) const

{ return std::string("hello world!!!!!!"); }

};

int main(void) {

Functor func; boost::function0<void> f(func);

return 0;

}

Attachments (1)

boostfunction.cpp (651 bytes ) - added by Tarjei Knapstad <tarjei.knapstad@…> 15 years ago.
Ready-to-run example code

Download all attachments as: .zip

Change History (5)

comment:1 by Douglas Gregor, 15 years ago

Status: newassigned

comment:2 by Marshall Clow, 15 years ago

Owner: changed from Douglas Gregor to doug_gregor
Status: assignednew

Assigned to "doug_gregor" instead of nonexistent user "dgregor"

by Tarjei Knapstad <tarjei.knapstad@…>, 15 years ago

Attachment: boostfunction.cpp added

Ready-to-run example code

comment:3 by Douglas Gregor, 15 years ago

Owner: changed from doug_gregor to Douglas Gregor
Status: newassigned

comment:4 by Douglas Gregor, 15 years ago

Resolution: fixed
Status: assignedclosed

(In [39244]) function_template.hpp:

  • Pass-by-reference internally, when we can. Fixes #1067
Note: See TracTickets for help on using tickets.