MantisBT

View Revisions: Issue #1601 Back to Issue ]
Summary 0001601: Use std::function and std::bind instead of boost::function and boost::bind
Revision 2013-11-30 15:21 by beegee
Description We should use std::function and std::bind consistently. Currently our codebase uses both versions, the one from std and boost.

I think it should be possible to use the std:: -versions for MSVC11(VS12) and higher. There are some differences between std and boost. Boost seems to be more tolerant than std, e.g. you can bind a function with a different return type than the signature of the function object. That refactoring shouldn't be underestimated, we have a lot of uses of boost::bind/function.

A problem is if you mix boost:: and std:: versions is that the bool conversion operator of boost::function will fail. See this:

1. Construct a function object with boost::bind which calls a member function. The object which will be used for calling the member function is null.
2. Assign the function object to a std::function instance
3. Assign the std::function instance to a boost::function instance
4. Call boost::function's () operator

Then this will fail:
if(funcObject) // tests whether the function object is callable -> the member function of the object which was passed earlier is null and so the function shouldn't be called, BUT it will be called and so the program crashes.





Revision 2013-11-30 15:22 by beegee
Description We should use std::function and std::bind consistently. Currently our codebase uses both versions, the one from std and boost.

I think it should be possible to use the std:: -versions for MSVC11(VS12) and higher. There are some differences between std and boost. Boost seems to be more tolerant than std, e.g. you can bind a function with a different return type than the signature of the function object. That refactoring shouldn't be underestimated, we have a lot of uses of boost::bind/function.

A problem is if you mix boost:: and std:: versions is that the bool conversion operator of boost::function will fail. See this:

1. Construct a function object with boost::bind which calls a member function. The object which will be used for calling the member function is null.
2. Assign the function object to a std::function instance
3. Assign the std::function instance to a boost::function instance
4. Call boost::function's () operator

Then this will fail:
if(funcObject) // tests whether the function object is callable -> the member function of the object which was passed earlier is null and so the function shouldn't be called, BUT it will be called and so the program crashes.

We already had a bug in vcmiclient because of this.






Site | Forums | Wiki | Slack | GitHub


Copyright © 2000 - 2024 MantisBT Team
Hosting provided by DigitalOcean