reference arguments and function adapters 
Author Message
 reference arguments and function adapters

The following code won't compile -

#include <functional>
using namespace std;

struct test_fxn : public unary_function<const int&, bool>
{
    bool operator()(const int &refInt)
    { return refInt < 0; }

Quote:
};

int main()
{
    bool b = not1(test_fxn())(-1);
     return 0;

Quote:
}

I think because unary_negate takes a const reference to its wrapped
function's argument type, like so:

 bool operator()(const _Ufn::argument_type& _X) const

which evaluates to a reference to a reference.  My question is: how are
people dealing with this?  I admit my sample code is contrived, but was
inspired by a real problem where I really want to pass a UDT by
reference, not by value.

I've been getting around this by defining my own adapters along the
lines of

struct unary_negate_nref : public unary_function ...

bool operator()(_Ufn::argument_type _X) const

but the number of permutations is getting large.  That is, I've already
defined other variants of the binder functions that handle void versus
non-void return values, const versus non-const arguments to operator(),
and pass by reference versus pass by value in the ctor.
--
==============================================
Michael Herstine       Pencom New Technologies


==============================================



Sun, 29 Apr 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Passing function pointer with arguments as an argument?

2. defining function whose type same as its arguments and used as another's argument

3. Network adapters Api function

4. Problem: Arbitrary Member Function Adapter and Templates.

5. How do I make the mem_fun adapter work with const member functions

6. Problem: Arbitrary Member Function Adapter and Templates.

7. Unmanaged dll conversion of reference argument from msvc++

8. Passing Arguments by Reference

9. Problem with MethodInfo.Invoke() not passing a argument by reference

10. Pointers to member functions as function arguments

11. printing function name and arguments from inside a function

12. Newbie - function pointers to variable-argument-number function

 

 
Powered by phpBB® Forum Software