Boost logo

Boost :

Subject: [boost] [function] Problem copying when constructed with a functor
From: Edward Diener (eldiener_at_[hidden])
Date: 2011-05-23 20:31:26


This simple code:

#include <boost/detail/lightweight_test.hpp>
#include <boost/function.hpp>

struct p_functor_class_int
   {
   p_functor_class_int() : data(50) { }
   int operator()() const { return data; }
   void operator()(int d) { data = d; }
   int data;
   };

int main()
   {
   boost::function<int ()> bfun(p_functor_class_int());
   boost::function<int ()> bfun2(bfun);
   return boost::report_errors();
   }

gives compiler errors. On gcc-4.6 I get:

"In file included from
C:\Programming\VersionControl\boost/boost/function/detail/maybe_include.hpp:13:0,
                  from
C:\Programming\VersionControl\boost/boost/function/detail/function_iterate.hpp:14,
                  from
C:\Programming\VersionControl\boost/boost/preprocessor/iteration/detail/iter/forward1.hpp:47,
                  from
C:\Programming\VersionControl\boost/boost/function.hpp:64,
                  from test_function_bug.cpp:2:
C:\Programming\VersionControl\boost/boost/function/function_template.hpp: In
static member function 'static R
boost::detail::function::function_invoker0<FunctionPtr,
R>::invoke(boost::detail::function::function_buffer&) [with FunctionPtr
= boost::function<int()> (*)(p_functor_class_int (*)()), R = int]':
C:\Programming\VersionControl\boost/boost/function/function_template.hpp:907:60:
   instantiated from 'void boost::function0<R>::assign_to(Functor) [with
Functor = boost::function<int()> (*)(p_functor_class_int (*)()), R = int]'
C:\Programming\VersionControl\boost/boost/function/function_template.hpp:722:7:
   instantiated from 'boost::function0<R>::function0(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value,
int>::type) [with Functor = boost::function<int()>
(*)(p_functor_class_int (*)()), R = int, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value,
int>::type = int]'
C:\Programming\VersionControl\boost/boost/function/function_template.hpp:1042:16:
   instantiated from 'boost::function<R()>::function(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value,
int>::type) [with Functor = boost::function<int()>
(*)(p_functor_class_int (*)()), R = int, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value,
int>::type = int]'
test_function_bug.cpp:15:37: instantiated from here
C:\Programming\VersionControl\boost/boost/function/function_template.hpp:95:39:
error: too few arguments to function
C:\Programming\VersionControl\boost/boost/function/function_template.hpp:96:9:
warning: control reaches end of non-void function [-Wreturn-type]
"

I am sure I must be doing something wrong but I can not see it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk