How to get at contents of placeholder::_1

Posted by sheepsimulator on Stack Overflow See other posts from Stack Overflow or by sheepsimulator
Published on 2010-04-15T19:28:02Z Indexed on 2010/04/15 22:13 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

I currently have the following code:

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...
}
}

I'd like to change MyClass::OnStart to use std::transform to achieve the same thing:

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::Stuff, this)));
}

However, my hiccup is _1->OnTrigger. How can I reference OnTrigger from placeholder _1?

© Stack Overflow or respective owner

Related posts about boost

Related posts about bind