Using C++11 facilities to clean up code and Boost dependencies
We can reduce but not entirely remove dependency on Boost by replacing parts of it with stdlib equivalents. This bug is a tracker for features to replace, and for discussion about compiler compatibility.
- [ ] boost/algorithm/string.hpp: No stdlib equivalents
- [ ] boost/bind.hpp: std::bind in functional
- [ ] boost/circular_buffer.hpp: No stdlib equivalent
- [ ] boost/cstdint.hpp: Now in stdlib (cstdint)
- [ ] boost/date_time.hpp: Partial support from stdlib (chrono)
- [ ] boost/filesystem.hpp: C++ still doesn't know of files :/
- [ ] boost/foreach.hpp: C++11 built-in range-based for!
- [ ] boost/format.hpp: No direct stdlib equivalent but see std::to_string(num)
- [ ] boost/function.hpp: std::function (functional)
- [ ] boost/iostreams/stream_buffer.hpp: ???
- [ ] boost/lexical_cast.hpp: See std::to_string and std::stoi etc. (string)
- [ ] boost/noncopyable.hpp: C++11 deleted functions (but noncopyable is cleaner in code)
- [ ] boost/program_options.hpp: Never gonna get into stdlib
- [ ] boost/ptr_container/: Not in C++11 and probably not in C++14 either.
- [ ] boost/regex.hpp: The last time I tried (quite recently), the libstdc++ implementation was unusably incomplete.
- [ ] boost/smart_ptr/scoped_ptr.hpp: std::unique_ptr in memory (also replaces std::auto_ptr)
- [ ] boost/smart_ptr/shared_ptr.hpp: std::unique_ptr (if shared_ptr was only used for calling a free function of a C lib), std::shared_ptr if the resource is actually shared, C++11 move semantics instead if a resourse is only being moved.
- [ ] boost/thread/: std::thread and stdlib mutexes (no idea if stdlib implementation is good yet or if all necessary lock types are included or not)
- [ ] boost/variant.hpp: Didn't make it into C++11
We don't currently use Boost.ASIO directly but likely will, soon. Sockets didn't make it into C++11.
LLVM folks also have an automatic converter tool: http://blog.llvm.org/2013/04/status-of-c11-migrator.html
Nice work on the list. Since we can't get rid of the whole boost, I don't consider this a very high priority. However, it could still be nice to reduce the amount of compiled boost components we depend on, namely thread, date_time and possibly regex (if I didn't miss anything).
I'll dump here links to C++11 support tables.
so, this means I should think of an alternative to boost:asio lib for webserver implementation (I was thinking about using that one, but I won't start implementation before 0.8 release) since we're trying to ditch boost libraries?
We aren't trying to ditch Boost, nor can we, as seen on the list. Keeping any library deps as light as possible is a good idea, that's why I made the list (Boost was used as a reference for the C++11 standard and thus it shares a lot of the functionality that is now part of the standard library). Boost.ASIO is the most well known and most heavily tested C++ socket library, so using it makes sense. Only if we switched to another platform library (e.g. Qt), should we consider using something else, IMO.
I'm going to apply cpp11migrate on master tonight. Please notify me and push any local changes that you may have done because a huge conflict will be created otherwise.
This tool is pretty impressive. Could have removed the empty line, though ;)
Original:
for (Paths::const_iterator it = paths.begin(); it != paths.end(); ++it) {
fs::path p = *it;
p /= filename;
Migrated:
for (auto p : paths) {
p /= filename;
Commit done. Feel free to hack again :)
shouldn't we just close this?
Nothing has yet been done to reduce dependency on Boost (it is actually being increased in fspath branch). cpp11migrate only did some general syntax clean-up.
I had problems compiling using boost 1.53 (1.49 works fine)
it keeps telling me :-1: error: No rule to make target /usr/lib/libboost_thread-mt.so', needed bygame/performous'. Stop.
but libboost-thread-1.53 is installed!!
i'm reverting back to 1.49 for now....
@nieknooijens: I too get errors like that sometimes when upgrading libraries. They go away by deleting the build folder and starting from scratch.
Deleting CMakeCache.txt is usually enough. This also happens when switching between torrent and master branches because (for some reason, probably no good) they have different FindBoost scripts.
Apparently mingw lacks thread support, so we need to stick with Boost.Thread on that for now.
Is this bug still relevant or should it be closed?
The stdthread branch replaces Boost xtime/date_time, threads/locks, bind, function, and the BOOST_FOREACH macro with C++11 equivalents, and others such as cstdint are already implemented in master. Work still remains to be done. Most notable things include smart pointers, lexical_cast/format and regex.
c++ does know about files!!! http://en.cppreference.com/w/cpp/experimental/fs/directory_iterator/directory_iterator
shouldn't we replace boost::shared_ptr with std::shared_ptr ??
If you need a lightweight c++ library to replace part or whole Boost, look at Poco
slowly we're getting there: https://github.com/performous/performous/pull/339
Slowly getting there by replacing boost::shared_ptrs and boost::thread -> std::thread: #347
Used @Tronic 's list of items to check of the items we have done already to get a more detailed status into this cleanup session:
- [ ] boost/algorithm/string.hpp: No stdlib equivalents
- [x] boost/bind.hpp: std::bind in functional
- [x] boost/circular_buffer.hpp: No stdlib equivalent
- [x] boost/cstdint.hpp: Now in stdlib (cstdint)
- [x] boost/date_time.hpp: Partial support from stdlib (chrono)
- [x] boost/filesystem.hpp: C++ still doesn't know of files :/
- [x] boost/foreach.hpp: C++11 built-in range-based for!
- [ ] boost/format.hpp: No direct stdlib equivalent but see std::to_string(num)
- [x] boost/function.hpp: std::function (functional)
- [ ] boost/iostreams/stream_buffer.hpp: ???
- [x] boost/lexical_cast.hpp: See std::to_string and std::stoi etc. (string)
- [x] boost/noncopyable.hpp: C++11 deleted functions (but noncopyable is cleaner in code)
- [ ] boost/program_options.hpp: Never gonna get into stdlib
- [x] boost/ptr_container/: LK: There's many of these in code base still, but as I said below, they're not needed anymore.
- [x] boost/regex.hpp: The last time I tried (quite recently), the libstdc++ implementation was unusably incomplete.
- [x] boost/smart_ptr/scoped_ptr.hpp: std::unique_ptr in memory (also replaces std::auto_ptr)
- [x] boost/smart_ptr/shared_ptr.hpp: std::unique_ptr (if shared_ptr was only used for calling a free function of a C lib), std::shared_ptr if the resource is actually shared, C++11 move semantics instead if a resourse is only being moved.
- [x] boost/thread/: std::thread and stdlib mutexes (no idea if stdlib implementation is good yet or if all necessary lock types are included or not)
- [x] boost/variant.hpp: Didn't make it into C++11
I replaced some boost::function calls with the std version in my GL branch. Also, ptr_container is not really needed anymore because now stl containers can contain smart pointers (at least one instance of which I also fixed in the GL branch, see ShaderMap)
@Lord-Kamina please cross off what you think is already fixed i'm currently checking master upon these
Also, correct me if I'm wrong but we're actually targetting c++14 now. No?
Edit: @Baklap4 Updated with things not appearing in a project-wide search of the GL branch.
As far as master branch i've ticked off all aswell with an incoming merge request for some easy to fix shizzle
BTW. Here's the specific relevant commit you can use as a base if you want to tackle the remaining ptr_map and ptr_vectors. If not I'll do them tomorrow.
https://github.com/performous/performous/commit/c234b7934d67b4e01ca35ea7e0a2ac17310cb863
Thanks it's not all ptr_maps and vectors though. I'm atm busy with tackling the cachemap. I fixed all the ptr_vectors already
@Lord-Kamina some weird stuff happens if i cherry-pick that specific commit within audio.cc hmmm
Yeah; don't. I just linked it to show an example of how I solved it. Have you had time to finish checking that PR?
TODO
- [x]
boost/format.hppcan be replaced with the much faster: fmtlib/fmt -> #714 - [ ]
boost/iostreams/stream_buffer.hppcan be replaced withstd::fstreamsince we don't do fancy stuff with the streams. So this is basicly a lot of bloat for a simple read stream command. - [ ]
boost/algorithm/string.hppcan probably be replaced with stl functionality as it's just manipulating strings.
This would leave us with just boost-program-options as a dependency on boost. Yet it does add another (but faster) dependency: fmtlib