about bind2nd

B

benben

I tried to do the following:

bind2nd(ptr_fun(&tolower<char>), locale());

But was hit with errors claiming some where deep down the STL library
some code is trying to take a reference to a reference type.

I guess that is because the std::tolower<>() template takes a reference
to a locale as its second parameter then bind2nd tries to take the
reference of that parameter. But how to I circumvent this?

Regards,
Ben
 
K

Kai-Uwe Bux

benben said:
I tried to do the following:

bind2nd(ptr_fun(&tolower<char>), locale());

But was hit with errors claiming some where deep down the STL library
some code is trying to take a reference to a reference type.

I guess that is because the std::tolower<>() template takes a reference
to a locale as its second parameter then bind2nd tries to take the
reference of that parameter. But how to I circumvent this?

One way is to use boost::bind.

#include <locale>
#include <iostream>
#include <boost/bind.hpp>
#include <iterator>
#include <algorithm>

int main ( void ) {
std::string str = "HELLO WORLD!";
std::transform
( str.begin(), str.end(),
std::eek:stream_iterator<char>( std::cout ),
boost::bind( &std::tolower<char>, _1, std::locale() ) );
std::cout << '\n';
}


Best

Kai-Uwe Bux
 

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

Members online

No members online now.

Forum statistics

Threads
473,919
Messages
2,570,037
Members
46,444
Latest member
MadeleineH

Latest Threads

Top