boost::lambda start learning

Y

yurec

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"));

std::vector<std::string_t> test_vector;

std::for_each(test.begin(),test.end(),

test_vector.push_back(bind(&type::value_type::second,_1))
);
 
V

Victor Bazarov

yurec said:
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;

I've never seen 'std::string_t', what is is? There is no mention
of 'string_t' in the Standard.
type test;
test[0] = (_T("1"));
test[1] = (_T("2"));
test[2] = (_T("3"));

std::vector<std::string_t> test_vector;

std::for_each(test.begin(),test.end(),

test_vector.push_back(bind(&type::value_type::second,_1))
);

---------------------------------------------------------------------------------
error C2664: 'std::vector<_Ty>::push_back' : cannot convert
parameter 1 from 'const boost::lambda::lambda_functor<T>' to 'const
std::string_t &'

V
 
?

=?iso-8859-1?q?Kirit_S=E6lensminde?=

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

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
 
W

Wade Ward

Kirit Sælensminde said:
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

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.

so nice to see. work along these lines that isn't mine.

Is it possible that c++ understands what a functor is?

--
wade ward

President
Merrill Jensen Consulting


(e-mail address removed)
435 -838-7760
 
Y

yurec

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

so nice to see. work along these lines that isn't mine.

Is it possible that c++ understands what a functor is?

--
wade ward

President
Merrill Jensen Consulting

(e-mail address removed)
435 -838-7760

Ok, thanks to everybody, I work with it a little more , understand
better and now everyting is ok.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

boost::lambda::bind 0
boost::bind with boost::fusion::for_each 1
boost lambda question 1
boost lambda expression 3
boost::lambda question 5
lambda 4
Boost function/bind problem 0
boost::lmbda::bind 0

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top