[Function] Takes functor by value not reference?

I may be misunderstanding as the boost::function code is tricky to follow but it seems to me that the function contructor takes the functor it is passed by value rather than by reference. This requires the functor to be copyable. In my case I'm trying to pass a functor as its abstract supertype which prevents copying. Is it not possible to take the functor my reference, thereby removing the need for copying? The constructor in question appears in function_template.hpp at line 1056 in version 1.40.0: Summarised: template<typename R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_PARMS> class function<BOOST_FUNCTION_PARTIAL_SPEC> : public BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> { typedef BOOST_FUNCTION_FUNCTION<R BOOST_FUNCTION_COMMA BOOST_FUNCTION_TEMPLATE_ARGS> base_type; template<typename Functor> function(Functor f) : base_type(f) { } } Many thanks. Alex Lamaison -- http://swish.sourceforge.net

Alexander Lamaison wrote:
I may be misunderstanding as the boost::function code is tricky to follow but it seems to me that the function contructor takes the functor it is passed by value rather than by reference.
This requires the functor to be copyable. In my case I'm trying to pass a functor as its abstract supertype which prevents copying. Is it not possible to take the functor my reference, thereby removing the need for copying?
Could you just use a Boost.Ref wrapper? Rather than passing f, you would pass ref(f).

On Sun, 14 Feb 2010 13:00:38 -0500, Jeff Schwab wrote:
Alexander Lamaison wrote:
I may be misunderstanding as the boost::function code is tricky to follow but it seems to me that the function contructor takes the functor it is passed by value rather than by reference.
This requires the functor to be copyable. In my case I'm trying to pass a functor as its abstract supertype which prevents copying. Is it not possible to take the functor my reference, thereby removing the need for copying?
Could you just use a Boost.Ref wrapper? Rather than passing f, you would pass ref(f).
That looks like it might be just what I need. Thanks!
participants (2)
-
Alexander Lamaison
-
Jeff Schwab