mirror of
https://github.com/boostorg/container.git
synced 2026-02-22 15:22:14 +00:00
Changed return type of erase/erase_if/unique members of list and slist to size_type to follow C++20 changes to std::list.
This commit is contained in:
@@ -1401,6 +1401,7 @@ collect them containers and build [*Boost.Container], a library targeted to a wi
|
||||
* If available, uses C++17's utilities under the `__cpp_aligned_new` feature.
|
||||
* Uses alternative aligned allocation functions (`posix_memalign`, `aligned_alloc`, `_aligned_malloc`...) otherwise.
|
||||
* Implemented overaligned allocation support for `adaptive_pool`and `node_allocator`
|
||||
* Changed return type of `erase`/`erase_if`/`unique` members of `list` and `slist` to `size_type` to follow C++20 changes to `std::list`.
|
||||
* Updated `basic_string`:
|
||||
* Added missing `string_view` members and updated `operator[]` to be able to return the terminating null.
|
||||
* Added C++20 `starts_with`/`ends_with` and C++23 `contains` overloads.
|
||||
|
||||
@@ -1168,10 +1168,12 @@ class list
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
void remove(const T& value)
|
||||
{ this->remove_if(equal_to_value_type(value)); }
|
||||
size_type remove(const T& value)
|
||||
{ return this->remove_if(equal_to_value_type(value)); }
|
||||
|
||||
//! <b>Effects</b>: Removes all the elements for which a specified
|
||||
//! predicate is satisfied.
|
||||
@@ -1180,30 +1182,36 @@ class list
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
template <class Pred>
|
||||
void remove_if(Pred pred)
|
||||
size_type remove_if(Pred pred)
|
||||
{
|
||||
typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
|
||||
this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
return this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
}
|
||||
|
||||
//! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
|
||||
//! elements that are equal from the list.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If comparison throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
void unique()
|
||||
{ this->unique(value_equal_t()); }
|
||||
size_type unique()
|
||||
{ return this->unique(value_equal_t()); }
|
||||
|
||||
//! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
|
||||
//! elements that satisfy some binary predicate from the list.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If pred throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
|
||||
@@ -1211,10 +1219,10 @@ class list
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
template <class BinaryPredicate>
|
||||
void unique(BinaryPredicate binary_pred)
|
||||
size_type unique(BinaryPredicate binary_pred)
|
||||
{
|
||||
typedef value_to_node_compare<Node, BinaryPredicate> value_to_node_compare_type;
|
||||
this->icont().unique_and_dispose(value_to_node_compare_type(binary_pred), Destroyer(this->node_alloc()));
|
||||
return this->icont().unique_and_dispose(value_to_node_compare_type(binary_pred), Destroyer(this->node_alloc()));
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: The lists x and *this must be distinct.
|
||||
@@ -1492,22 +1500,14 @@ class list
|
||||
//! <b>Complexity</b>: Linear.
|
||||
template <class T, class A, class U>
|
||||
inline typename list<T, A>::size_type erase(list<T, A>& c, const U& v)
|
||||
{
|
||||
typename list<T, A>::size_type old_size = c.size();
|
||||
c.remove_if(equal_to_value<U>(v));
|
||||
return old_size - c.size();
|
||||
}
|
||||
{ return c.remove_if(equal_to_value<U>(v)); }
|
||||
|
||||
//! <b>Effects</b>: Erases all elements that satisfy the predicate pred from the container c.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear.
|
||||
template <class T, class A, class Pred>
|
||||
inline typename list<T, A>::size_type erase_if(list<T, A>& c, Pred pred)
|
||||
{
|
||||
typename list<T, A>::size_type old_size = c.size();
|
||||
c.remove_if(pred);
|
||||
return old_size - c.size();
|
||||
}
|
||||
{ return c.remove_if(pred); }
|
||||
|
||||
#ifndef BOOST_CONTAINER_NO_CXX17_CTAD
|
||||
template <typename InputIterator>
|
||||
|
||||
@@ -1126,10 +1126,12 @@ class slist
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time. It performs exactly size() comparisons for equality.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
void remove(const T& value)
|
||||
{ this->remove_if(equal_to_value_type(value)); }
|
||||
size_type remove(const T& value)
|
||||
{ return this->remove_if(equal_to_value_type(value)); }
|
||||
|
||||
//! <b>Effects</b>: Removes all the elements for which a specified
|
||||
//! predicate is satisfied.
|
||||
@@ -1138,30 +1140,36 @@ class slist
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time. It performs exactly size() calls to the predicate.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
template <class Pred>
|
||||
void remove_if(Pred pred)
|
||||
size_type remove_if(Pred pred)
|
||||
{
|
||||
typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
|
||||
this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
return this->icont().remove_and_dispose_if(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
}
|
||||
|
||||
//! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
|
||||
//! elements that are equal from the list.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If comparison throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time (size()-1 comparisons equality comparisons).
|
||||
//!
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
void unique()
|
||||
{ this->unique(value_equal_t()); }
|
||||
size_type unique()
|
||||
{ return this->unique(value_equal_t()); }
|
||||
|
||||
//! <b>Effects</b>: Removes adjacent duplicate elements or adjacent
|
||||
//! elements that satisfy some binary predicate from the list.
|
||||
//!
|
||||
//! <b>Returns</b>: The number of removed elements.
|
||||
//!
|
||||
//! <b>Throws</b>: If pred throws.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear time (size()-1 comparisons calls to pred()).
|
||||
@@ -1169,10 +1177,10 @@ class slist
|
||||
//! <b>Note</b>: The relative order of elements that are not removed is unchanged,
|
||||
//! and iterators to elements that are not removed remain valid.
|
||||
template <class Pred>
|
||||
void unique(Pred pred)
|
||||
size_type unique(Pred pred)
|
||||
{
|
||||
typedef value_to_node_compare<Node, Pred> value_to_node_compare_type;
|
||||
this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
return this->icont().unique_and_dispose(value_to_node_compare_type(pred), Destroyer(this->node_alloc()));
|
||||
}
|
||||
|
||||
//! <b>Requires</b>: The lists x and *this must be distinct.
|
||||
@@ -1663,22 +1671,14 @@ class slist
|
||||
//! <b>Complexity</b>: Linear.
|
||||
template <class T, class A, class U>
|
||||
inline typename slist<T, A>::size_type erase(slist<T, A>& c, const U& v)
|
||||
{
|
||||
typename slist<T, A>::size_type old_size = c.size();
|
||||
c.remove_if(equal_to_value<U>(v));
|
||||
return old_size - c.size();
|
||||
}
|
||||
{ return c.remove_if(equal_to_value<U>(v)); }
|
||||
|
||||
//! <b>Effects</b>: Erases all elements that satisfy the predicate pred from the container c.
|
||||
//!
|
||||
//! <b>Complexity</b>: Linear.
|
||||
template <class T, class A, class Pred>
|
||||
inline typename slist<T, A>::size_type erase_if(slist<T, A>& c, Pred pred)
|
||||
{
|
||||
typename slist<T, A>::size_type old_size = c.size();
|
||||
c.remove_if(pred);
|
||||
return old_size - c.size();
|
||||
}
|
||||
{ return c.remove_if(pred); }
|
||||
|
||||
#ifndef BOOST_CONTAINER_NO_CXX17_CTAD
|
||||
|
||||
|
||||
@@ -119,6 +119,24 @@ bool list_copyable_only(V1 &boostlist, V2 &stdlist, boost::container::dtl::true_
|
||||
return 1;
|
||||
stdlist.erase(boost::container::find(stdlist.begin(), stdlist.end(), 24));
|
||||
if(!test::CheckEqualContainers(boostlist, stdlist)) return false;
|
||||
|
||||
//remove
|
||||
if (1 != boostlist.remove(IntType(23)))
|
||||
return 1;
|
||||
if (0 != boostlist.remove(IntType(23)))
|
||||
return 1;
|
||||
|
||||
stdlist.erase(boost::container::find(stdlist.begin(), stdlist.end(), 23));
|
||||
if(!test::CheckEqualContainers(boostlist, stdlist)) return false;
|
||||
|
||||
//remove_if
|
||||
if (1 != boostlist.remove_if(equal_to_value<int>(22)))
|
||||
return 1;
|
||||
if (0 != boostlist.remove_if(equal_to_value<int>(22)))
|
||||
return 1;
|
||||
stdlist.erase(boost::container::find(stdlist.begin(), stdlist.end(), 22));
|
||||
if(!test::CheckEqualContainers(boostlist, stdlist)) return false;
|
||||
|
||||
}
|
||||
{ //List(const List &, alloc)
|
||||
::boost::movelib::unique_ptr<V1> const pv1 = ::boost::movelib::make_unique<V1>(boostlist, typename V1::allocator_type());
|
||||
@@ -377,8 +395,13 @@ int list_test (bool copied_allocators_equal = true)
|
||||
return 1;
|
||||
}
|
||||
|
||||
boostlist.unique();
|
||||
stdlist.unique();
|
||||
{
|
||||
std::size_t old_sz = boostlist.size();
|
||||
std::size_t bremoved = boostlist.unique();
|
||||
if (bremoved != (old_sz - boostlist.size()))
|
||||
return 1;
|
||||
stdlist.unique();
|
||||
}
|
||||
if(!CheckEqualContainers(boostlist, stdlist))
|
||||
return 1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user