The Boost reference states that boost::ref can be used to pass an
argument
to statechart::fifo_scheduler::create_processor by reference instead of
by
value. I haven't been able to get this to work if the argument type
derives
from boost::noncopyable.
It appears that the create_processor implementation instantiates code
that
attempts to copy the argument.
Here's an example. Note that this compiles and runs sucessfully if
Object
does not derive from boost::noncopyable.
Thanks,
Steve Hawkes
----
#include
#include
#include
#include
#include
#include <iostream>
class Object : public boost::noncopyable
{
};
struct Initial;
struct Test :
boost::statechart::asynchronous_state_machine
{
public:
Test(my_context ctx, Object& arg1)
: my_base(ctx)
{
}
};
struct Initial : boost::statechart::simple_state
{
};
int
main()
{
Object value;
boost::statechart::fifo_scheduler<> scheduler;
const boost::statechart::fifo_scheduler<>::processor_handle
processor1 =
scheduler.create_processor
(boost::ref(value));
return (0);
}
----
Here's the compiler error:
----
g++ -Wall -lboost_system-mt -lboost_thread-mt -o test test.cc
/usr/include/boost/noncopyable.hpp: In copy constructor
'Object::Object(const Object&)':
test.cc:9: instantiated from 'typename
boost::statechart::processor_container, typename FifoWorker::work_item,
Allocator>::processor_handle
boost::statechart::fifo_scheduler::create_processor(Arg1) [with Processor = Test, Arg1 =
Object&, FifoWorker =
boost::statechart::fifo_worker, Allocator =
std::allocator<void>]'
test.cc:36: instantiated from here
/usr/include/boost/noncopyable.hpp:27: error:
'boost::noncopyable_::noncopyable::noncopyable(const
boost::noncopyable_::noncopyable&)' is private
test.cc:9: error: within this context
/usr/include/boost/statechart/fifo_scheduler.hpp: In member function
'typename
boost::statechart::processor_container, typename FifoWorker::work_item,
Allocator>::processor_handle
boost::statechart::fifo_scheduler::create_processor(Arg1) [with Processor = Test, Arg1 =
Object&, FifoWorker =
boost::statechart::fifo_worker, Allocator =
std::allocator<void>]':
/usr/include/boost/statechart/fifo_scheduler.hpp:63: note: synthesized
method 'Object::Object(const Object&)' first required here
/usr/include/boost/statechart/fifo_scheduler.hpp:63: error:
initializing argument 3 of 'WorkItem
boost::statechart::processor_container::create_processor(boost::weak_ptr >&, Scheduler&, Arg1) [with Processor
= Test, Arg1 = Object, Scheduler =
boost::statechart::fifo_scheduler, std::allocator<void> >, WorkItem =
boost::function0<void>, Allocator = std::allocator<void>]'