473,695 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

about bind2nd

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
Oct 8 '06 #1
2 1907
benben wrote:
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::ostream_it erator<char>( std::cout ),
boost::bind( &std::tolower<c har>, _1, std::locale() ) );
std::cout << '\n';
}
Best

Kai-Uwe Bux
Oct 8 '06 #2
Kai-Uwe Bux wrote:
>
One way is to use boost::bind.
Another way is to use std::tr1::bind. <g>

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2668
by: ES Kim | last post by:
Here's a simple code: #include <vector> #include <algorithm> #include <functional> using namespace std; struct S { void f(int) const { }
2
1514
by: flyaflya | last post by:
i use a class static member function to for_each: class t1 { static test(string s); } main() { list<string> slist; ...
4
4900
by: dzikus | last post by:
Why the following code does not compile? If I change the function argument to value (not reference) everything is ok. Is it possible to modify such code that it will compile with reference argument type? Best regards Dominik #include <string> #include <list> #include <algorithm>
1
3032
by: PS | last post by:
Hi, I wrote the following code to try using bind2nd. It compiles and works fine with g++ but a Sun compiler tells me : "test_bind2nd.cpp", line 21: Error: Cannot cast from std::binder2nd<std::greater<int>> to bool(*)(const int&). Could you tell me if there's something wrong with the code itself? Thanks, PS
8
4495
by: Noah Roberts | last post by:
#include <vector> #include <algorithm> #include <functional> class X { int x; public: X(int i) : x(i) {} bool eq(const X & other) const { return x == other.x; }
2
483
by: benben | last post by:
I wrote the following lines: #include <locale> #include <functional> #include <algorithm> int main() { using namespace std; bind2nd(ptr_fun(tolower<char>), locale());
3
1813
by: Bruintje Beer | last post by:
Hi, I am having the following question (see code below) the class Data is declared as class Data { public : // rest of class };
4
1838
by: responsible | last post by:
Hi, Digging through the STL source code, i found this gem.. template <class _Operation, class _Tp> inline binder2nd<_Operation> bind2nd(const _Operation& __fn, const _Tp& __x) { typedef typename _Operation::second_argument_type _Arg2_type; return binder2nd<_Operation>(__fn, _Arg2_type(__x)); }
4
6182
by: Giovanni Gherdovich | last post by:
Hello, I'm doing some toy experiments to see how the algoritm std::transform and the function adapter std::bind2nd can play together, but my compiler give my the error error: passing `const traslate' as `this' argument of `circle traslate::operator()(circle, std::vector<double, std::allocator<double)'
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9113
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2997
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.