Re: [Boost-bugs] [Boost C++ Libraries] #6606: Map: rbtree_node doesn't use allocator_traits to construct m_data

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6606: Map: rbtree_node doesn't use allocator_traits to construct m_data
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-02-24 03:45:19


#6606: Map: rbtree_node doesn't use allocator_traits to construct m_data
-------------------------------------------------+--------------------------
  Reporter: Erik Jensen <Erik.Jensen@…> | Owner: igaztanaga
      Type: Bugs | Status: new
 Milestone: To Be Determined | Component: container
   Version: Boost 1.49.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------------------------+--------------------------

Comment (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
 {
 public:
    template <typename T, typename Args...>
    allocator_constructed(const Alloc &alloc, Args &&...args)
       : _alloc(alloc)
    {
       allocator_traits<Alloc>::construct(_alloc,
          static_cast<Ty*>(static_cast<void*>(&data)),
          boost::forward<Args>(args)...);
    }
    ~manually_constructed() {
       allocator_traits<Alloc>::destroy(_alloc,
          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));
    }
    Ty* operator->() {
       return static_cast<Ty*>(static_cast<void*>(&data));
    }
    const Ty* operator->() const {
       return static_cast<Ty*>(static_cast<void*>(&data));
    }
 private:
    Alloc _alloc;
    boost::aligned_storage<sizeof(Ty), std::alignment_of<Ty>::value> data;
 };
 }}}
 And then have members of this class.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6606#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:09 UTC