MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001601VCMIOtherpublic2013-11-30 15:212022-04-12 08:54
Reporterbeegee 
Assigned Tobeegee 
PrioritynormalSeveritytweakReproducibilityN/A
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version0.97 
Summary0001601: Use std::function and std::bind instead of boost::function and boost::bind
DescriptionWe 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.





TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0004146)
Ivan (developer)
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 (administrator)
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 (developer)
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 (developer)
2014-08-04 18:41

Fixed in this commit: https://github.com/vcmi/vcmi/commit/5139378319ae967f0c72db9c4af18075dde72680 [^]

- Issue History
Date Modified Username Field Change
2013-11-30 15:21 beegee New Issue
2013-11-30 15:22 beegee Description Updated View Revisions
2013-11-30 16:20 Ivan Note Added: 0004146
2013-11-30 17:38 Warmonger Note Added: 0004148
2013-11-30 17:40 Warmonger Note Edited: 0004148 View Revisions
2013-12-01 09:50 beegee Note Added: 0004149
2014-08-04 18:41 beegee Note Added: 0004894
2014-08-04 18:41 beegee Status new => resolved
2014-08-04 18:41 beegee Fixed in Version => 0.97
2014-08-04 18:41 beegee Resolution open => fixed
2014-08-04 18:41 beegee Assigned To => beegee
2022-04-12 08:54 Povelitel Status resolved => closed

Site | Forums | Wiki | Slack | GitHub


Copyright © 2000 - 2024 MantisBT Team
Hosting provided by DigitalOcean