MantisBT - VCMI
View Issue Details
0001601VCMIOtherpublic2013-11-30 15:212022-04-12 08:54
beegee 
beegee 
normaltweakN/A
closedfixed 
 
0.97 
0001601: Use std::function and std::bind instead of boost::function and boost::bind
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.





No tags attached.
Issue History
2013-11-30 15:21beegeeNew Issue
2013-11-30 15:22beegeeDescription Updatedbug_revision_view_page.php?rev_id=2448#r2448
2013-11-30 16:20IvanNote Added: 0004146
2013-11-30 17:38WarmongerNote Added: 0004148
2013-11-30 17:40WarmongerNote Edited: 0004148bug_revision_view_page.php?bugnote_id=4148#r2452
2013-12-01 09:50beegeeNote Added: 0004149
2014-08-04 18:41beegeeNote Added: 0004894
2014-08-04 18:41beegeeStatusnew => resolved
2014-08-04 18:41beegeeFixed in Version => 0.97
2014-08-04 18:41beegeeResolutionopen => fixed
2014-08-04 18:41beegeeAssigned To => beegee
2022-04-12 08:54PovelitelStatusresolved => closed

Notes
(0004146)
Ivan   
2013-11-30 16:20   
If VS is OK with this change then go on - simple search & replace should work here.

I can do this myself but I'd rather leave this to somebody who has VS to make sure that everything works.
(0004148)
Warmonger   
2013-11-30 17:38   
(edited on: 2013-11-30 17:40)
Just gave it a try, 231 compilation errors. This is not so simple :P
Don't have time to investigate it now, sorry.

(0004149)
beegee   
2013-12-01 09:50   
I don't want to spend my time on refactoring this (perhaps later), but I wanted to keep this sticky somewhere, so it won't be forgotten.

I think we should use the std::-versions from now on and if someone is working on a part of the code where a boost::version is used he can convert this to the std::-version. This should be enough for now.
(0004894)
beegee   
2014-08-04 18:41   
Fixed in this commit: https://github.com/vcmi/vcmi/commit/5139378319ae967f0c72db9c4af18075dde72680 [^]