Modify

Ticket #7888 (reopened Feature Requests)

Opened 15 months ago

Last modified 5 months ago

circular_buffer should support move semantics

Reported by: holmes@… Owned by: apolukhin
Milestone: To Be Determined Component: circular_buffer
Version: Boost 1.52.0 Severity: Problem
Keywords: circular_buffer move emplace Cc:

Description

I would like to use circular buffer to store unique_ptr's or other moveable objects. I hope this feature will be added.

Attachments

Change History

comment:1 Changed 15 months ago by anonymous

Elaborate please. What it is move semantics? Why you cannot store unique_ptrs in the current version?

comment:2 Changed 15 months ago by holmes@…

a description of the term move semantics can be found here  http://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c++11.html

Here is an example of what I would like to do which works with a std::deque :

std::deque<std::unique_ptr<int>> myQueue;
std::unique_ptr<int> myP(new int(4));		
myQueue.push_back(std::move(myP));		//transfer ownership to the queue
auto otherP = std::move(myQueue.front());	//transfer ownership back from the queue to a new unique_ptr
myQueue.pop_front();

This doesn't work with boost::circular_buffer because there is only one overload of push_back and it takes a const T&. I need another overload that takes T&&.

comment:3 Changed 13 months ago by anonymous

I would also like to see this feature implemented in circular_buffer. At this moment it is actually possible to use std::shared_ptr. But, in order to maintain the same semantics as other containers in C++11 STL, circular_buffer should implement move semantics as well. Once that happens, using std::unique_ptr will be straightforward, bringing a potential performance improvement compared to std::shared_ptr.

comment:4 Changed 12 months ago by anonymous

One more request for this. If you store more complex elements inside the circular buffer, you don't want to have overhead code to care for the destruction of the elements when they are pushed out of the ring.

comment:5 Changed 10 months ago by apolukhin

  • Owner changed from jano_gaspar to apolukhin
  • Status changed from new to assigned

comment:6 Changed 10 months ago by apolukhin

(In [84941]) Basic commit of C++11 move constructor and move assignment for circular_buffer (refs #7888). some of the functions marked with BOOST_NOEXCEPT

comment:7 Changed 9 months ago by apolukhin

(In [84984]) Add basic rvalues move support for elements of circular_buffer (refs #7888). Patch uses Boost.Move to emulate rvalues in C++03

comment:8 Changed 9 months ago by apolukhin

(In [84988]) Improved rvalues move support for elements of circular_buffer (refs #7888):

  • move_if_noexcept uses is_copy_constructible trait
  • more tests, tests are now more strict
  • linearize() now works with move-only types

comment:9 Changed 9 months ago by apolukhin

(In [84991]) Improved rvalues move support for elements of circular_buffer (refs #7888):

  • set_capacity and rset_capacity now work with move-only types if move constructor of type marked with noexcept
  • force placement ::new usage
  • minor optimizations (move values in more cases)
  • more tests

comment:10 Changed 9 months ago by apolukhin

(In [85003]) Improved rvalues move support for elements of circular_buffer (refs #7888):

  • all erase methods now use move construction to to move elements
  • space optimized circullar buffer now has move constructor, move assignment and functions that work with rvalues
  • more methods marked as BOOST_NOEXCEPT
  • much more tests

comment:11 Changed 9 months ago by apolukhin

(In [85059]) Fix errors in circular_buffer tests(refs #7888).

comment:12 Changed 9 months ago by apolukhin

(In [85082]) Fixed my own typo (refs #7888)

comment:13 Changed 9 months ago by apolukhin

(In [85101]) Fixed MSVC related bug for rvalues move support of circular_buffer (refs #7888)

comment:14 Changed 9 months ago by apolukhin

(In [85133]) Fix errors in circular_buffer tests(refs #7888).

comment:15 Changed 8 months ago by apolukhin

(In [85240]) Updated documentaion of the circular_buffer to reflect the rvalue references support (refs #7888) + replaced some tabs with whitespaces and added the boost.root parameter to jamfile.v2

comment:16 Changed 8 months ago by apolukhin

(In [85458]) Make move_if_noexcept more strict and move values only if they have noexcept move constructor *and* noexcept move assignment operator (refs #7888)

comment:17 Changed 8 months ago by apolukhin

  • Status changed from assigned to closed
  • Resolution set to fixed

(In [85510]) Big merge of Boost.CircularBuffer? :

  • Full merge of QuickBoock? documentation from Paul A. Bristow
  • Merged rvalue references support with tests and documentation (fixed #7888)

comment:18 follow-up: ↓ 19 Changed 5 months ago by pbf@…

This change has unfortunately introduced fresh warnings when building against boost 1.55 using VisualStudio? 2010 with warning level 4. I now see:

1>C:\src\svn\OTI\ThirdParty?\boost_1_55_0_OT1\include\boost/circular_buffer/base.hpp(199): warning C4172: returning address of local variable or temporary

Likewise, building using gcc 4.4.7 on RedHat? produces the following warning:

/media/sf_C_DRIVE/src/svn/OTI/ThirdParty/boost_1_55_0_OT1/include/boost/circular_buffer/base.hpp:2157: error: suggest parentheses around ‘&&’ within ‘

Shall I open a new ticket for this issue? Unfortunately it's causing my builds to break, since I build with warnings-as-errors on both platforms. I'll need to either disable the warnings, or fix the problems.

comment:19 in reply to: ↑ 18 Changed 5 months ago by apolukhin

Replying to pbf@…:

This change has unfortunately introduced fresh warnings when building against boost 1.55 using VisualStudio? 2010 with warning level 4. I now see:

Great thanks for reporting that issue! I'll take care of those warnings, no need to open a separate ticket.

comment:20 Changed 5 months ago by apolukhin

  • Status changed from closed to reopened
  • Resolution fixed deleted
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as reopened
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.