Using bind with assignment operator

K

KD

Hi All,

Can anyone please tell me if it is possible to bind the assignment
operator using STL or boost?

Here's some naive pseudo code which does not even compile but may help
clarify my intent:
{
bool value = true;

function f = bind(&operator=, ref(value), false);

f(); // Sets 'value' to false.
}

Thanks,
Keith
 
A

Alf P. Steinbach

* KD:
Can anyone please tell me if it is possible to bind the assignment
operator using STL or boost?

You can not obtain the address of a built-in operator.

However, it's easy to define corresponding functions, and the standard library
defines some such wrappers, although as far as I can recall not for assignment.

Since you're using Boost it may be worthwhile to check if some Boost sublibrary
defines a relevant wrapper.

If not, e.g.

template< typename T >
T& assign( T& variable, T const& value )
{
return (variable = value);
}

Here's some naive pseudo code which does not even compile but may help
clarify my intent:
{
bool value = true;

function f = bind(&operator=, ref(value), false);

f(); // Sets 'value' to false.
}

Cheers & hth.,

- Alf
 

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

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top