bind2nd doesnt accept methods using pass-by-ref?
Rob Willis
robwillis@greenwood.net
Tue Jun 20 12:21:00 GMT 2000
Still learning the ins and outs of STL. I hit the following case, where
bind2nd can not take accept methods that use pass-by-reference. That
seems very limiting... I looked in the bind2nd definition, it appears
as if the bind2nd template is saving a copy of the value to be passed
into the method - is this what the standard requires?? Seems like in
many cases you would want the bind2nd to just save a ref to the value...
-Rob
rob@e-critical.com
#include <functional>
#include <algorithm>
#include <vector>
using namespace std;
class Base
{
public:
virtual void testOp1( const double * d_ptr ) = 0;
virtual void testOp2( const double & d_ref ) = 0;
};
int main()
{
std::vector< Base * > vObjects;
double d_value = 1.0;
// this compiles
for_each( vObjects.begin(), vObjects.end(),
bind2nd( mem_fun( &Base::testOp1 ), &d_value ) );
/* // this doesnt compile
for_each( vObjects.begin(), vObjects.end(),
bind2nd( mem_fun( &Base::testOp2 ), d_value ) );
*/
}
More information about the Libstdc++
mailing list