[Boost-bugs] [Boost C++ Libraries] #11970: Use perfect forwarding for object_pool

Subject: [Boost-bugs] [Boost C++ Libraries] #11970: Use perfect forwarding for object_pool
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-02-09 19:29:22

#11970: Use perfect forwarding for object_pool
 Reporter: djpeaco@… | Owner: cnewbold
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: pool
  Version: Boost 1.61.0 | Severity: Problem
 Keywords: object_pool |
 boost::object_pool::construct uses a code generation system to create
 versions of that method that take up to some arbitrary number of input
 parameters. With C++11/14 it is possible to do the same using perfect
 forwarding, which would allow any number of input parameters using a
 single template method, and without bloating the hpp.

 I think this would also solve a related problem I am having. The object
 that I am trying to construct using the object_pool takes a unique_ptr as
 an input parameter to it's constructor (it is taking ownership of it):
 class Node {}

 class Tree {
     Tree(std::unique_ptr<Node> root, int foo, int bar) :
         m_root(std::move(root)) {}
     std::unique_ptr<Node> m_root;

 void makeTrees()
     boost::object_pool<Tree> treePool;
     std::unique_ptr<Node> node (new Node());
     Tree* tree = treePool.construct (node, 1, 2);

 In the current implementation, the compiler gives an error because
 object_pool::construct doesn't call std::move on root when newing the
 /usr/local/include/boost/pool/detail/pool_construct.ipp(258): error:
 function "std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp,
 _Dp> &) [with _Tp=Node, _Dp=std::function<void (Node *)>]" (declared at
 line 273 of "/usr/include/c++/4.8.5/bits/unique_ptr.h") cannot be
 referenced -- it is a deleted function
     try { new (ret) element_type(a0, a1, a2); }

 I think (but am not certain) that using perfect forwarding would allow

Ticket URL: <https://svn.boost.org/trac/boost/ticket/11970>
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:19 UTC