Здравствуйте, Аноним, Вы писали:
А>Вопрос такой: как избавиться от ф-ии exec? Ведь наверняка же можно через boost::lambda!
нафиг не нужна тут boost::lambda! (она гаразда тяжелее обычных bind'ов)
курим доки (не по диагонале) здесь
#include <iostream>
#include <algorithm>
#include <vector>
#include <boost/function.hpp>
#include <boost/bind/apply.hpp>
#include <boost/bind.hpp>
using namespace std;
int f1( int i )
{
return i;
}
int main()
{
std::vector<boost::function<int (int)> > s;
s.push_back( f1 );
// ......
// ......
// s.push_back( f10 );int param = 7;
std::for_each( s.begin(), s.end(), boost::bind( boost::apply<int>(), _1, param ) );
return 0;
}
А>Спасибо.
Использование boost::lambda
От:
Аноним
Дата:
15.04.10 14:40
Оценка:
Всем привет.
Есть код:
int f1( int i )
{
return i;
}
void exec( boost::function<int (int)> f, int i )
{
std::cout << f( i ) << "\n";
}
int main()
{
std::vector<boost::function<int (int)> > s;
s.push_back( f1 );
// ......
// ......
// s.push_back( f10 );int param = 7;
std::for_each( s.begin(), s.end(), boost::bind( exec, _1, param ) );
return 0;
}
Вопрос такой: как избавиться от ф-ии exec? Ведь наверняка же можно через boost::lambda!