Question on std::binary_function template arguments

You may recall my earlier question asking if there was an easy way to "bind" a member
function to a weak_ptr. Looking at the lower-level STL features, I came up with this
idea, to prepare an adaptor in the same manner as mem_fun and mem_fun_ref. Generalizing
the idea, it takes a member function and produces a functor that takes the object as a
first argument, for various ways of presenting the object. I extended it with
mem_fun_weak, where the resulting functor is called with a weak_ptr as the first argument.
Below is one form (the one I need). To work along with the other STL primitives, there
are a total of 4 forms (const/non-const, one arg or no args). That doesn't have arbitrary
signatures like the more general "bind", which is something I'd like to discuss further.
For now, my question concerns the first template argument to std::binary_function.
Looking at the declarations for the standard mem_fun1_t and mem_fun1_ref_t, I don't know
if this should be:
1) the full type passed as the first argument to the resulting functor,
2) such, but without the final &,
3) just the object's type,
4..n) something else?
Can someone clarify that for me?
Here is my code (using #1 above):
template

on Mon Sep 12 2011, "John M. Dlugosz"
For now, my question concerns the first template argument to std::binary_function. Looking at the declarations for the standard mem_fun1_t and mem_fun1_ref_t, I don't know if this should be: 1) the full type passed as the first argument to the resulting functor, 2) such, but without the final &, 3) just the object's type, 4..n) something else?
Can someone clarify that for me?
I know this isn't the answer you're looking for, but IMO you should just avoid std::binary_function and friends. They don't buy you anything you can't get from embedding the typedefs directly, and they can inhibit the empty base optimization. -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On 13 September 2011 11:13, Dave Abrahams
I know this isn't the answer you're looking for, but IMO you should just avoid std::binary_function and friends. They don't buy you anything you can't get from embedding the typedefs directly, and they can inhibit the empty base optimization.
And they are deprecated in C++11 (along with mem_fun and mem_fun_ref, for that matter). -- Nevin ":-)" Liber mailto:nevin@eviloverlord.com (847) 691-1404

On 9/13/2011 11:38 AM, Nevin Liber wrote:
On 13 September 2011 11:13, Dave Abrahams
wrote: I know this isn't the answer you're looking for, but IMO you should just avoid std::binary_function and friends. They don't buy you anything you can't get from embedding the typedefs directly, and they can inhibit the empty base optimization.
And they are deprecated in C++11 (along with mem_fun and mem_fun_ref, for that matter).
Thanks. So what is the "best practice" for creating something that plays well with older compilers that don't have decltype or all the C++11 features? What kinds of things are first_argument_type and second_argument_type needed for? I'm supposing that they would make bind smarter, work better perhaps, or give more sensible error messages. If mem_fun etc. are deprecated in favor of just using function and bind, then is there also a general extension mechanism defined? That is, tell subsequent uses of bind just what to do with first arguments of that nature? —John

on Wed Sep 14 2011, "John M. Dlugosz"
On 9/13/2011 11:38 AM, Nevin Liber wrote:
On 13 September 2011 11:13, Dave Abrahams
wrote: I know this isn't the answer you're looking for, but IMO you should just avoid std::binary_function and friends. They don't buy you anything you can't get from embedding the typedefs directly, and they can inhibit the empty base optimization.
And they are deprecated in C++11 (along with mem_fun and mem_fun_ref, for that matter).
Thanks.
So what is the "best practice" for creating something that plays well with older compilers that don't have decltype or all the C++11 features?
What kinds of things are first_argument_type and second_argument_type needed for?
Almost nothing these days. There are some (mostly older) library components like bind2nd that create wrapper function objects with non-templatized call operators, and therefore need first_argument_type and second_argument_type so they can deduce the parameter types to the generated wrapper.
I'm supposing that they would make bind smarter, work better perhaps, or give more sensible error messages.
bind uses templated function call operators, so it doesn't need to know what arguments the underlying function object can accept. It wouldn't use the information if you supplied it. The only interesting information for modern library components is the return type of your function (object). On compilers without decltype you need to do something like embed a result_type typedef or provide an embedded result<> metafunction. -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (3)
-
Dave Abrahams
-
John M. Dlugosz
-
Nevin Liber