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)
Change History (5)
comment:1 by , 15 years ago
Status: | new → assigned |
---|
comment:2 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:3 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Assigned to "doug_gregor" instead of nonexistent user "dgregor"