-
Notifications
You must be signed in to change notification settings - Fork 62
Add emplace_{back,front} to circular_buffer - rebased to latest develop #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
f9z
wants to merge
7
commits into
boostorg:develop
Choose a base branch
from
f9z:emplace
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
df790ee
Add emplace_{back,front} to circular_buffer
AI0867 c7c0d4a
Add emplace_{back,front} to circular_buffer_space_optimized
AI0867 90ef625
Add tests for emplace_{back,front}
AI0867 19a1ce4
Revert "Add tests for emplace_{back,front}"
e5b44b1
add emplace_test
d5819ae
finalise rebase
c4c85d7
replace replace() with destroy_item() + construct()
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1429,7 +1429,7 @@ private empty_value<Alloc> | |
boost::allocator_construct(alloc(), boost::to_address(m_last), static_cast<ValT>(item)); | ||
increment(m_last); | ||
++m_size; | ||
} | ||
} | ||
} | ||
|
||
/*! INTERNAL ONLY */ | ||
|
@@ -1454,6 +1454,86 @@ private empty_value<Alloc> | |
BOOST_CATCH_END | ||
} | ||
|
||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES | ||
template <class ...Args> | ||
void emplace_back_impl(BOOST_FWD_REF(Args) ...args) { | ||
if (full()) { | ||
if (empty()) | ||
return; | ||
destroy_item(m_last); | ||
boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward<Args>(args)...); | ||
increment(m_last); | ||
m_first = m_last; | ||
} else { | ||
boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward<Args>(args)...); | ||
increment(m_last); | ||
++m_size; | ||
} | ||
} | ||
#else | ||
template <class V> | ||
void emplace_back_impl(BOOST_FWD_REF(V) value) { | ||
if (full()) { | ||
if (empty()) | ||
return; | ||
destroy_item(m_last); | ||
boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward<Args>(args)...); | ||
increment(m_last); | ||
m_first = m_last; | ||
} else { | ||
boost::allocator_construct(alloc(), boost::to_address(m_last), ::boost::forward<V>(value)); | ||
increment(m_last); | ||
++m_size; | ||
} | ||
} | ||
#endif | ||
|
||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES | ||
template <class ...Args> | ||
void emplace_front_impl(BOOST_FWD_REF(Args) ...args) { | ||
BOOST_TRY { | ||
if (full()) { | ||
if (empty()) | ||
return; | ||
decrement(m_first); | ||
destroy_item(m_first); | ||
boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward<Args>(args)...); | ||
m_last = m_first; | ||
} else { | ||
decrement(m_first); | ||
boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward<Args>(args)...); | ||
++m_size; | ||
} | ||
} BOOST_CATCH(...) { | ||
increment(m_first); | ||
BOOST_RETHROW | ||
} | ||
BOOST_CATCH_END | ||
} | ||
#else | ||
template <class V> | ||
void emplace_front_impl(BOOST_FWD_REF(V) value) { | ||
BOOST_TRY { | ||
if (full()) { | ||
if (empty()) | ||
return; | ||
decrement(m_first); | ||
destroy_item(m_first); | ||
boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward<Args>(args)...); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has not been compiled with BOOST_NO_CXX11_VARIADIC_TEMPLATES defined because I do not think this would compile. There is no variadic template parameter Args (args) here |
||
m_last = m_first; | ||
} else { | ||
decrement(m_first); | ||
boost::allocator_construct(alloc(), boost::to_address(m_first), ::boost::forward<V>(value)); | ||
++m_size; | ||
} | ||
} BOOST_CATCH(...) { | ||
increment(m_first); | ||
BOOST_RETHROW | ||
} | ||
BOOST_CATCH_END | ||
} | ||
#endif | ||
|
||
public: | ||
//! Insert a new element at the end of the <code>circular_buffer</code>. | ||
/*! | ||
|
@@ -1583,6 +1663,64 @@ private empty_value<Alloc> | |
push_front(boost::move(temp)); | ||
} | ||
|
||
//! Construct a new element at the end of the <code>circular_buffer</code>. | ||
/*! | ||
\post if <code>capacity() > 0</code> then <code>back() == item</code><br> | ||
If the <code>circular_buffer</code> is full, the first element will be removed. If the capacity is | ||
<code>0</code>, nothing will be inserted. | ||
\param item The element to be inserted. | ||
\throws Whatever <code>T::T(Args...)</code> throws. | ||
Whatever <code>T::operator = (T&&)</code> throws. | ||
\par Exception Safety | ||
Basic; no-throw if the operation in the <i>Throws</i> section does not throw anything. | ||
\par Iterator Invalidation | ||
Does not invalidate any iterators with the exception of iterators pointing to the overwritten element. | ||
\par Complexity | ||
Constant (in the size of the <code>circular_buffer</code>). | ||
\sa <code>\link push_back() push_back(const_reference)\endlink</code>, | ||
<code>pop_back()</code>, <code>emplace_front()</code> | ||
*/ | ||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES | ||
template <class ...Args> | ||
void emplace_back(BOOST_FWD_REF(Args) ...args) { | ||
emplace_back_impl(::boost::forward<Args>(args)...); | ||
} | ||
#else | ||
template <class V> | ||
void emplace_back(BOOST_FWD_REF(V) value) { | ||
emplace_back_impl(::boost::forward<V>(value)); | ||
} | ||
#endif | ||
|
||
//! Construct a new element at the beginning of the <code>circular_buffer</code>. | ||
/*! | ||
\post if <code>capacity() > 0</code> then <code>back() == item</code><br> | ||
If the <code>circular_buffer</code> is full, the last element will be removed. If the capacity is | ||
<code>0</code>, nothing will be inserted. | ||
\param item The element to be inserted. | ||
\throws Whatever <code>T::T(Args...)</code> throws. | ||
Whatever <code>T::operator = (T&&)</code> throws. | ||
\par Exception Safety | ||
Basic; no-throw if the operation in the <i>Throws</i> section does not throw anything. | ||
\par Iterator Invalidation | ||
Does not invalidate any iterators with the exception of iterators pointing to the overwritten element. | ||
\par Complexity | ||
Constant (in the size of the <code>circular_buffer</code>). | ||
\sa <code>\link push_front() push_front(const_reference)\endlink</code>, | ||
<code>pop_front()</code>, <code>emplace_back()</code> | ||
*/ | ||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES | ||
template <class ...Args> | ||
void emplace_front(BOOST_FWD_REF(Args) ...args) { | ||
emplace_front_impl(::boost::forward<Args>(args)...); | ||
} | ||
#else | ||
template <class V> | ||
void emplace_front(BOOST_FWD_REF(V) value) { | ||
emplace_front_impl(::boost::forward<V>(value)); | ||
} | ||
#endif | ||
|
||
//! Remove the last element from the <code>circular_buffer</code>. | ||
/*! | ||
\pre <code>!empty()</code> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has not been compiled with BOOST_NO_CXX11_VARIADIC_TEMPLATES defined because I do not think this would compile.
There is no variadic template parameter Args (args) here