[bind, function] bind a cast
Hi Is there any easy way to bind an explicit type conversion ? For example, I want to supress compiler warning here with static_cast: #include <boost/bind.hpp> #include <boost/function.hpp> int main(void) { boost::function<long (void)> foo; boost::function<short (void)> bar; bar = foo; // compiler warning. bar = boost::bind<short>(foo); // the same warning //bar = boost::bind(static_cast<short>, foo); // does not compile return 0; } If not, I think it might be added. Casts are useful sometimes not only to avoid warning, but also to get code compiled.
Hi Alexander.
Is there any easy way to bind an explicit type conversion ?
Is the Boost Lambda library's ll_static_cast<> template what you are looking for? Just use that with boost::lambda::bind() instead of boost::bind(). See http://www.boost.org/doc/html/lambda/le_in_details.html#id1247769 for details... Hope this helps. Best regards, Jurko Gospodnetić
Yes, this works, thanks. Why are Boost.Bind and Boost.Lambda separate, they seem to duplicate each other in some part ?
Hi Alexander.
Yes, this works, thanks.
Why are Boost.Bind and Boost.Lambda separate, they seem to duplicate each other in some part ?
Searching the list archive might give you better insight (I remember seeing many discussions on this subject), but I believe the gist is that Boost.Lambda is a superset of Boost.Bind but is also less portable and more heavy-weight (takes more time to compile)... Someone please correct me if I am mistaken... Best regards, Jurko Gospodnetić
participants (2)
-
Alexander Gutenev
-
Jurko Gospodnetić