[config] BOOST_NO_CXX11_ALLOCATOR and template aliases

VC11 appears to not define BOOST_NO_CXX11_ALLOCATOR. However, as std::allocator_traits contains two template aliases, rebind_alloc and rebind_traits, and VC11 doesn't support template aliases, it has nonstandard definitions of these two. This is obviously a problem for code that wants to use std::allocator_traits. One way to fix that is for the user code to check BOOST_NO_CXX11_TEMPLATE_ALIASES and if so, refrain from using std::allocator_traits. Another is to just not define BOOST_NO_CXX11_ALLOCATOR for VC11. (VC12 is conforming.) I tend to be in favor of the second option, as the effect would essentially be the same.

[Peter Dimov]
Another is to just not define BOOST_NO_CXX11_ALLOCATOR for VC11. (VC12 is conforming.)
You should be aware that while 2013 has the machinery to respect C++11 minimal allocators (in particular, providing a default for rebind), we missed several places where we should be using that machinery. For example, basic_string and allocate_shared were unintentionally requiring the full C++03 allocator interface. I've audited the entire STL for this problem and I have local changes to fix all occurrences for the next major version. I'm not sure if BOOST_NO_CXX11_ALLOCATOR covers this, but I thought you should know. STL

Stephan T. Lavavej wrote:
You should be aware that while 2013 has the machinery to respect C++11 minimal allocators (in particular, providing a default for rebind), we missed several places where we should be using that machinery. For example, basic_string and allocate_shared were unintentionally requiring the full C++03 allocator interface.
This is not a problem in our specific use case, which is boost::allocate_shared. We just need std::allocator_traits in order to properly support minimal allocators (along with construct/destroy) from our side. :-)

I'm enabling code when BOOST_NO_CXX11_ALLOCATOR is not defined that uses std::allocator_traits<R> for construct, destroy as well as all members like pointer, const_pointer, size_type, difference_type, where what R is depends on whether BOOST_NO_CXX11_TEMPLATE_ALIASES is defined: if yes, then R is typename A::template rebind<Other>::other; if not, then R is typename std::allocator_traits<A>::template rebind_alloc<Other>. It's a not too ugly a workaround at the moment [commit 6d73b4aa54 at github.com/boostorg/smart_ptr] but VC11 seems to be the only thing requiring it. Searching through history I found that Daniel was also bitten by that implementation closer to the first release that supported VC11: https://groups.google.com/d/msg/boost-developers-archive/3uJDk-rRuJI/udDulU_... I'm much in favor of having BOOST_NO_CXX11_ALLOCATOR no longer defined on VC11. Glen

VC11 appears to not define BOOST_NO_CXX11_ALLOCATOR. However, as std::allocator_traits contains two template aliases, rebind_alloc and rebind_traits, and VC11 doesn't support template aliases, it has nonstandard definitions of these two.
This is obviously a problem for code that wants to use std::allocator_traits.
One way to fix that is for the user code to check BOOST_NO_CXX11_TEMPLATE_ALIASES and if so, refrain from using std::allocator_traits.
Another is to just not define BOOST_NO_CXX11_ALLOCATOR for VC11. (VC12 is conforming.)
I tend to be in favor of the second option, as the effect would essentially be the same.
+1. Can you make the changes? I'm not yet in a position to test VC11, though I hope to be soon. John.

John Maddock wrote:
Can you make the changes? I'm not yet in a position to test VC11, though I hope to be soon.
I don't have VC11 either, but the minimum test that would disqualify it would probably entail adding to boost_no_cxx11_allocator.ipp something like: std::allocator_traits<std::allocator<int> > at; + std::allocator_traits<std::allocator<int>
::rebind_alloc<void*>::value_type ra = &at;
A stricter approach would actually test that std::allocator_traits<std::allocator<int> >::rebind_alloc<void*> is std::allocator<void*>.

Can you make the changes? I'm not yet in a position to test VC11, though I hope to be soon.
I don't have VC11 either, but the minimum test that would disqualify it would probably entail adding to boost_no_cxx11_allocator.ipp something like:
std::allocator_traits<std::allocator<int> > at; + std::allocator_traits<std::allocator<int>
::rebind_alloc<void*>::value_type ra = &at;
A stricter approach would actually test that std::allocator_traits<std::allocator<int> >::rebind_alloc<void*> is std::allocator<void*>.
Done in develop. Tested VC10, 11 and 12. HTH, John.

Done in develop. Tested VC10, 11 and 12.
Thanks!
Belated thanks for BOOST_NO_CXX11_HDR_ATOMIC as well. I hadn't noticed. But it, too, needs to one day make its way into master.
I was waiting for the regression tests to start up again - but now that they're running and everything looks OK, I've gone ahead and merged to master. John.
participants (4)
-
Glen Fernandes
-
John Maddock
-
Peter Dimov
-
Stephan T. Lavavej