我目前有以下代码:
using boost::bind;
typedef boost::signal<void(EventDataItem&)> EventDataItemSignal;
class EventDataItem
{
...
EventDataItemSignal OnTrigger;
...
}
typedef std::list< shared_ptr<EventDataItem> > DataItemList;
typedef std::list<boost::signals::connection> ConnectionList;
class MyClass
{
void OnStart()
{
DataItemList dilItems;
ConnectionList clConns;
DataItemList::iterator iterDataItems;
for(iterDataItems = dilItems.begin();
iterDataItems != dilItems.end();
iterDataItems++)
{
// Create Connections from Triggers
clConns.push_back((*iterDataItems)->OnTrigger.connect(
bind(&MyClass::OnEventTrigger, this)));
}
}
void OnEventTrigger()
{
// ... Do stuff on Trigger...
}
}
我想更改 MyClass::OnStart 以使用 std::transform 来实现相同的目的:
void MyClass::OnStart()
{
DataItemList dilItems;
ConnectionList clConns;
// Resize connection list to match number of data items
clConns.resize(dilItems.size());
// Build connection list from Items
// note: errors on the placeholder _1->OnTrigger
std::transform(dilItems.begin(), dilItems.end(),
clConns.begin(),
bind(&EventDataItemSignal::connect, _1->OnTrigger,
bind(&MyClass::OnEventTrigger, this)));
}
但是,我的问题是_1->OnTrigger。 如何从占位符 _1 引用 OnTrigger?