P
Paul MG
Hi
A brief question:
Is it generally considered idiomatic/good C++ to have behaviour in the
destructor of a function object?
For instance, consider a function object whose constructor takes
references to variables in the calling scope. During the use of the
functor, ie in a call to an STL algorithm, the functor stores away
data in its member variables. Then just before the algorithm returns,
as the functor goes out of scope, its destructor does some work with
the member variables, setting the results back into the variables it
still has references to.
I hope this makes sense. If it is any use, I am seeing this pattern at
http://www.gotw.ca/gotw/041.htm. I just found it rather surprising,
though once I had read it I sort of saw the elegance of it.
Is this a standard thing to do?
thanx for input,
pmg
A brief question:
Is it generally considered idiomatic/good C++ to have behaviour in the
destructor of a function object?
For instance, consider a function object whose constructor takes
references to variables in the calling scope. During the use of the
functor, ie in a call to an STL algorithm, the functor stores away
data in its member variables. Then just before the algorithm returns,
as the functor goes out of scope, its destructor does some work with
the member variables, setting the results back into the variables it
still has references to.
I hope this makes sense. If it is any use, I am seeing this pattern at
http://www.gotw.ca/gotw/041.htm. I just found it rather surprising,
though once I had read it I sort of saw the elegance of it.
Is this a standard thing to do?
thanx for input,
pmg