Re: boost::lambda start learning
On Oct 30, 10:02 pm, yurec <Yurij.Zha...@materialise.kiev.ua> wrote:
Hi
I start learning boost.Today I tried to use boost::lambda but failed
to compile very simple example.
2 hours of googling gave nothing.
Can anybody help me?
using namespace boost::lambda;
typedef std::map<int,std::string_t> type;
type test;
test[0] = (_T("1"));
test[1] = (_T("2"));
test[2] = (_T("3"));
Microsoft's _T hack doesn't really address any of the important issues
to do with going from narrow characters to wide characters. You're
normally better off just using wide characters if you think you'll
need them and narrow if you won't.
std::vector<std::string_t> test_vector;
std::for_each(test.begin(),test.end(),
test_vector.push_back(bind(&type::value_type::second,_1))
);
You need to do a double bind. Although bind you have isn't really to a
function, what you need to do is still function composition so you
need a double bind - the first to bind to type::value_type::second and
the second to bind to push_back.
Take a look at this generic composition example: http://www.boostcookbook.com/Recipe:/1234820
---------------------------------------------------------------------------------
: error C2664: 'std::vector<_Ty>::push_back' : cannot convert
parameter 1 from 'const boost::lambda::lambda_functor<T>' to 'const
std::string_t &'
This is because you can't pass the functor you get from bind to
push_back as you're doing. You need to also bind push_back.
K