|
Boost : |
From: Dill, John (john-dill_at_[hidden])
Date: 2004-05-06 16:32:22
I don't know if this was discussed at an earlier point, but I have a suggestion for a workaround of the forwarding problem. The main issue is whether you want to allow literals to be called from the bind_t operator(). I believe it's possible to change the semantics to the same as those within the bind call.
In the current implementation of bind,
bind( function, ref( object1 ), "literal" )( object2, "No literal" )
object2 is passed by reference, and "No literal" will not work due to binding a literal to a reference.
However, I believe it possible to define semantics like this:
bind( function, ref( object1 ), "literal" )( object2, "Literal allowed" )
object2 is passed by value, the literal is now allowed
bind( function, ref( object1 ), "literal" )( ref( object2 ), "Literal allowed" )
object2 is passed by reference through the reference wrapper, and the literal is still allowed.
There are several steps needed to convert the bind/mem_fn to these semantics (roughly):
For mem_fn:
1. Change the semantics of mem_fn_template of the reference function to non reference (pass by value).
2. Add another operator() which uses a reference_wrapper.
For bind:
3. Add a traits which processes the argument type to give the right semantics:
template <class T> argument_traits
{ typedef T type; };
template <class T> argument_traits<reference_wrapper<T> >
{ typedef T& type; };
template <class T> argument_traits<reference_wrapper<T const> >
{ typedef T const& type; };
4. Remove the reference from the argument type in bind_template.hpp from A1& to A1 for all N for operator().
5. Process the list_av_N type by argument_traits instead of A1&, A2&, ...
I believe that this can be done, but doesn't justify whether it should be done. There are several issues that I see at the moment.
A. Changes the semantics of everyone's bind and mem_fn, no biggy there ;-).
B. Pass by value is silent, not sure how many copies of the argument will be generated if pass-by-value.
But at the same time there is an advantage.
a. You can use literals in calling your bind functions.
What do you all think?
Best,
John
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk