REPOST: boost.bind usage

Since my first post using the web interface seems to have been lost, I'm trying again via email... Is it just me or is it my compiler (MSVC6SP5)? The following code gives me an error. Whats wrong? #include <boost/bind.hpp> #include <functional> using boost::bind; void main() { bind(std::greater<int>, _1, _2)(1, 2); } main.cpp(8) : error C2275: 'std::greater<int>' : illegal use of this type as an expression TIA, Markus

Since my first post using the web interface seems to have been lost, I'm
From: "Markus Schöpflin" <markus.schoepflin@ginit-technology.com> trying again via email...
Is it just me or is it my compiler (MSVC6SP5)? The following code gives me
an error. Whats wrong?
#include <boost/bind.hpp> #include <functional>
using boost::bind;
void main() { bind(std::greater<int>, _1, _2)(1, 2); }
main.cpp(8) : error C2275: 'std::greater<int>' : illegal use of this type
as an expression To make it compile, you need to: * change std::greater<int> to std::greater<int>(); * change bind(... to bind<bool>(... since MSVC 6 cannot deduce the return type; * use the qualified boost::bind<bool> syntax to work around a bug in the compiler; and finally, use int x = 1; int y = 2; boost::bind<bool>(std::greater<int>(), _1, _2)(x, y); since bind cannot take rvalues (this is usually not a problem in real code, just in examples.)

--- In Boost-Users@y..., "Peter Dimov" <pdimov@m...> wrote:
To make it compile, you need to:
* change std::greater<int> to std::greater<int>(); * change bind(... to bind<bool>(... since MSVC 6 cannot deduce the
return
type; * use the qualified boost::bind<bool> syntax to work around a bug in the compiler;
Thanks a lot, Peter!
and finally, use
int x = 1; int y = 2;
boost::bind<bool>(std::greater<int>(), _1, _2)(x, y);
since bind cannot take rvalues (this is usually not a problem in real code, just in examples.)
Hmm, the following code compiles and executes ok for me. #include <boost/bind.hpp> #include <functional> #include <iostream> using boost::bind; void main() { std::cout << boost::bind<bool>(std::greater<int>(), _1, _2)(2, 1) << '\n'; } Markus

On Monday 25 March 2002 10:43 am, you wrote:
Since my first post using the web interface seems to have been lost, I'm trying again via email...
Is it just me or is it my compiler (MSVC6SP5)? The following code gives me an error. Whats wrong?
#include <boost/bind.hpp> #include <functional>
using boost::bind;
void main() { bind(std::greater<int>, _1, _2)(1, 2); }
main.cpp(8) : error C2275: 'std::greater<int>' : illegal use of this type as an expression
TIA, Markus
Two problems here: - std::greater<int> is a type. You want std::greater<int>() to create an object of that type - constants can't (directly) be passed into boost::bind objects. You'll need to have: int x = 1, int y = 2; and call the boost::bind object with (x, y) instead of (1, 2). If you still get errors, then it's your compiler's fault because it can't figure out the return type. You'll have to tell bind to use an 'int' return type, so the final code would look like this: #include <boost/bind.hpp> #include <functional> using boost::bind; int main() { int x1 = 1; int x2 = 2; bind<int>(std::greater<int>(), _1, _2)(x1, x2); } Doug

Doug, Peter, thanks for your answer! Just for the records, the following program compiles and executes ok with MSVC6SP5. (Note the use of constants.) Markus ---<%--- #include <boost/bind.hpp> #include <functional> #include <iostream> using boost::bind; void main() { std::cout << boost::bind<bool>(std::greater<int>(), _1, _2)(2, 1) << '\n'; } --->%---

From: "Markus Schöpflin" <markus.schoepflin@ginit-technology.com>
Doug, Peter, thanks for your answer!
Just for the records, the following program compiles and executes ok with MSVC6SP5. (Note the use of constants.)
This is a MSVC 6 specific extension; constants have type 'const int' on MSVC 6, plain 'int' in standard C++.
participants (4)
-
Douglas Gregor
-
Markus Schöpflin
-
markus_schoepflin
-
Peter Dimov