With gcc 10.1 and boost 1.73.0, the following code
#include <boost/bimap.hpp>
int main() {
boost::bimap<int, int> lookup;
}
fails to compile with flags -O2 --std=c++20, but will succeed with flags -O2 -std=c++17 (verified with compiler explorer).
This is possibly related to the following issue: https://github.com/boostorg/bimap/pull/15 (deprecated std::allocator<void>)
Is there some workaround I can use for now to get this code to successfully compile with --std=c++20?
The reason behind the error is not that the
std::allocator<void>specialization is removed. Actually, it's still valid as the primary template with thevoidargument. The code fails to compile, because::rebindis no longer part ofstd::allocatoritself. Instead, an implementation should usestd::allocator_traits<Alloc>::rebind_alloc<U>.Fortunately, most containers usually allow to specify a custom allocator as a template argument. It's also the case for
boost::bimap, where an allocator can be the third, fourth or fifth template parameter, according to docs. It defaults tostd::allocator, but instead,boost::container::allocatorcan be used, which does not produce the error:This issue has recently been fixed in 6fba6e5.
boost::bimapnow properly detects if a nested::rebindis available: