Opened 7 years ago

Closed 6 years ago

#6606 closed Bugs (fixed)

Map: rbtree_node doesn't use allocator_traits to construct m_data

Reported by: Erik Jensen <Erik.Jensen@…> Owned by: Ion Gaztañaga
Milestone: To Be Determined Component: container
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:


I'm not at all sure what the best way to fix this is. The STL implementation that ships with the Visual Studio 11 preview calls allocate for the tree node and then construct for each of the members (the actual tree node constructor never gets called, as far as I can tell).

Change History (3)

comment:1 Changed 7 years ago by Erik Jensen <Erik.Jensen@…>

I guess another option would be to tuck a class like this (which I just made up) into your details, somewhere:

#include <boost/type_traits.hpp>
template <typename Ty, typename Alloc>
class allocator_constructed
   template <typename T, typename Args...>
   allocator_constructed(const Alloc &alloc, Args &&...args)
      : _alloc(alloc)
   ~manually_constructed() {
   Ty& operator*() {
      return *static_cast<Ty*>(static_cast<void*>(&data));
   const Ty& operator*() const {
      return *static_cast<Ty*>(static_cast<void*>(&data));
   Ty* operator->() {
      return static_cast<Ty*>(static_cast<void*>(&data));
   const Ty* operator->() const {
      return static_cast<Ty*>(static_cast<void*>(&data));
   Alloc _alloc;
   boost::aligned_storage<sizeof(Ty), std::alignment_of<Ty>::value> data;

And then have members of this class.

comment:2 Changed 7 years ago by Erik Jensen <Erik.Jensen@…>

One further note:

I was reading through the standard, and came across this (§23.2.1¶3):

For the components affected by this subclause that declare an allocator_type, objects stored in these components shall be constructed using the allocator_traits<allocator_type>::construct function and destroyed using the allocator_traits<allocator_type>::destroy function ( These functions are called only for the container’s element type, not for internal types used by the container. [ Note: This means, for example, that a node-based container might need to construct nodes containing aligned buffers and call construct to place the element into the buffer. —end note ]

My understanding, then, is that while construct should be called for the pair, it should not be called for rbtree_node (which it currently is).

comment:3 Changed 6 years ago by Ion Gaztañaga

Resolution: fixed
Status: newclosed

Fixed in Boost 1.50

Note: See TracTickets for help on using tickets.