Connecting Tech Pros Worldwide Forums | Help | Site Map

boost::lambda start learning

yurec
Guest
 
Posts: n/a
#1: Oct 30 '07
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_ttype;
type test;
test[0] = (_T("1"));
test[1] = (_T("2"));
test[2] = (_T("3"));

std::vector<std::string_ttest_vector;

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

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

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


Victor Bazarov
Guest
 
Posts: n/a
#2: Oct 30 '07

re: boost::lambda start learning


yurec wrote:
Quote:
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_ttype;
I've never seen 'std::string_t', what is is? There is no mention
of 'string_t' in the Standard.
Quote:
type test;
test[0] = (_T("1"));
test[1] = (_T("2"));
test[2] = (_T("3"));
>
std::vector<std::string_ttest_vector;
>
std::for_each(test.begin(),test.end(),
>
test_vector.push_back(bind(&type::value_type::seco nd,_1))
);
>
---------------------------------------------------------------------------------
Quote:
>error C2664: 'std::vector<_Ty>::push_back' : cannot convert
parameter 1 from 'const boost::lambda::lambda_functor<T>' to 'const
std::string_t &'
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


=?iso-8859-1?q?Kirit_S=E6lensminde?=
Guest
 
Posts: n/a
#3: Oct 31 '07

re: boost::lambda start learning


On Oct 30, 10:02 pm, yurec <Yurij.Zha...@materialise.kiev.uawrote:
Quote:
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_ttype;
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.
Quote:
>
std::vector<std::string_ttest_vector;
>
std::for_each(test.begin(),test.end(),
>
test_vector.push_back(bind(&type::value_type::seco nd,_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
Quote:
---------------------------------------------------------------------------------
: 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

Wade Ward
Guest
 
Posts: n/a
#4: Oct 31 '07

re: boost::lambda start learning



"Kirit Sælensminde" <kirit.saelensminde@gmail.comwrote in message
news:1193801172.814120.146730@z9g2000hsf.googlegro ups.com...
Quote:
On Oct 30, 10:02 pm, yurec <Yurij.Zha...@materialise.kiev.uawrote:
Quote:
>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_ttype;
> 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.
>
Quote:
>>
> std::vector<std::string_ttest_vector;
>>
> std::for_each(test.begin(),test.end(),
>>
>test_vector.push_back(bind(&type::value_type::sec ond,_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
>
Quote:
>---------------------------------------------------------------------------------
>: 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.
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


wade@zaxfuuq.net
435 -838-7760


yurec
Guest
 
Posts: n/a
#5: Oct 31 '07

re: boost::lambda start learning


On 31 , 06:45, "Wade Ward" <zaxf...@invalid.netwrote:
Quote:
"Kirit Sælensminde" <kirit.saelensmi...@gmail.comwrote in message
>
news:1193801172.814120.146730@z9g2000hsf.googlegro ups.com...
>
Quote:
On Oct 30, 10:02 pm, yurec <Yurij.Zha...@materialise.kiev.uawrote:
Quote:
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?
>
Quote:
Quote:
using namespace boost::lambda;
>
Quote:
Quote:
typedef std::map<int,std::string_ttype;
type test;
test[0] = (_T("1"));
test[1] = (_T("2"));
test[2] = (_T("3"));
>
Quote:
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.
>
Quote:
Quote:
std::vector<std::string_ttest_vector;
>
Quote:
Quote:
std::for_each(test.begin(),test.end(),
>
Quote:
Quote:
test_vector.push_back(bind(&type::value_type::seco nd,_1))
);
>
Quote:
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.
>
Quote:
Take a look at this generic composition example:
http://www.boostcookbook.com/Recipe:/1234820
>
Quote:
Quote:
---------------------------------------------------------------------------*------
: error C2664: 'std::vector<_Ty>::push_back' : cannot convert
parameter 1 from 'const boost::lambda::lambda_functor<T>' to 'const
std::string_t &'
>
Quote:
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
>
w...@zaxfuuq.net
435 -838-7760
Ok, thanks to everybody, I work with it a little more , understand
better and now everyting is ok.

Closed Thread


Similar C / C++ bytes