binding a member function with an argument of reference type

T

Triple-DES

Submitted for your consideration:

#include <functional>

struct C { void f(const int&) {} };

template <typename F>
void call(F f)
{
f(123);
}
int main()
{
using namespace std;
C c;
call ( bind1st(mem_fun( &C::f), &c) );
}

This seemingly fails on most implementations because the library
attempts to form a reference to a reference. Is it possible to bind
this function using only the C++03 standard library utilities?
 
M

Maxim Yegorushkin

Submitted for your consideration:

#include<functional>

struct C { void f(const int&) {} };

template<typename F>
void call(F f)
{
f(123);
}
int main()
{
using namespace std;
C c;
call ( bind1st(mem_fun(&C::f),&c) );
}

This seemingly fails on most implementations because the library
attempts to form a reference to a reference. Is it possible to bind
this function using only the C++03 standard library utilities?

Only if you don't use reference arguments.

Use boost::bind(). It does not have this problem:

call(boost::bind(&C::f, &c, _1));
 
T

Triple-DES

Only if you don't use reference arguments.

Use boost::bind(). It does not have this problem:

   call(boost::bind(&C::f, &c, _1));

Thanks Maxim. Unfortunately, the Boost licensing scheme is
unacceptable for our application. I ended up writing my own wrapper
function object. That's roughly 15 lines of (potentially buggy) code,
that I am only going to use for this very specific task. Not an ideal
solution.
 
J

Jeff Flinn

Triple-DES said:
Thanks Maxim. Unfortunately, the Boost licensing scheme is
unacceptable for our application. I ended up writing my own wrapper

Boost's licensing scheme is probably less encumbering than the license
of the compiler that you're using. What's problematic with boost's license?

Jeff
 
T

Triple-DES

Boost's licensing scheme is probably less encumbering than the license
of the compiler that you're using. What's problematic with boost's license?

Jeff

Nothing as far as I am concerned. I suspect that my organization's
lavishly paid legal counsel fails to distinguish between the Boost
Sofware License and the GNU GPL.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top