Fixes #221 ("flat_set and friends should offer a const sequence_type& sequence() const method (...)")

This commit is contained in:
Ion Gaztañaga
2022-06-25 20:29:16 +02:00
parent 4ea5cd7911
commit 34cd414280
6 changed files with 69 additions and 18 deletions

View File

@ -1341,6 +1341,7 @@ use [*Boost.Container]? There are several reasons for that:
[section:release_notes_boost_1_80_00 Boost 1.80 Release]
* Fixed bugs/issues:
* [@https://github.com/boostorg/container/issues/221 GitHub #221: ['"flat_set and friends should offer a const sequence_type& sequence() const method (...)"]].
* [@https://github.com/boostorg/container/pull/222 GitHub #222: ['"Fix incomplete type error when using list with pair"]].
* [@https://github.com/boostorg/container/issues/223 GitHub #223: ['"Possible copypaste typo"]].

View File

@ -1396,15 +1396,15 @@ class flat_tree
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
container_type extract_sequence()
{
return boost::move(m_data.m_seq);
}
{ return boost::move(m_data.m_seq); }
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
container_type &get_sequence_ref()
{
return m_data.m_seq;
}
{ return m_data.m_seq; }
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
const container_type &get_sequence_cref() const
{ return m_data.m_seq; }
BOOST_CONTAINER_FORCEINLINE void adopt_sequence_equal(BOOST_RV_REF(container_type) seq)
{

View File

@ -64,6 +64,10 @@ template<class D, class S>
BOOST_CONTAINER_FORCEINLINE static D &force(S &s)
{ return *move_detail::force_ptr<D*>(&s); }
template<class D, class S>
BOOST_CONTAINER_FORCEINLINE static const D &force(const S &s)
{ return *move_detail::force_ptr<const D*>(&s); }
template<class D, class S>
BOOST_CONTAINER_FORCEINLINE static D force_copy(const S &s)
{
@ -104,7 +108,7 @@ BOOST_CONTAINER_FORCEINLINE static D force_copy(const S &s)
//! - The allocator to allocate <code>value_type</code>s (e.g. <i>allocator< std::pair<Key, T> > </i>).
//! (in this case <i>sequence_type</i> will be vector<value_type, AllocatorOrContainer>)
//! - The SequenceContainer to be used as the underlying <i>sequence_type</i>. It must be a vector-like
//! sequence container with random-access iterators..
//! sequence container with random-access iterators.
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
template <class Key, class T, class Compare = std::less<Key>, class AllocatorOrContainer = new_allocator< std::pair< Key, T> > >
#else
@ -1569,6 +1573,14 @@ class flat_map
BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_unique_range_t, BOOST_RV_REF(sequence_type) seq)
{ this->m_flat_tree.adopt_sequence_unique(ordered_unique_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
//! <b>Effects</b>: Returns a const view of the underlying sequence.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing
BOOST_CONTAINER_FORCEINLINE const sequence_type & sequence() const BOOST_NOEXCEPT
{ return dtl::force<sequence_type>(m_flat_tree.get_sequence_cref()); }
//! <b>Effects</b>: Returns true if x and y are equal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.
@ -2887,9 +2899,7 @@ class flat_multimap
//! <b>Throws</b>: If secuence_type's move constructor throws
BOOST_CONTAINER_ATTRIBUTE_NODISCARD BOOST_CONTAINER_FORCEINLINE
sequence_type extract_sequence()
{
return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref()));
}
{ return boost::move(dtl::force<sequence_type>(m_flat_tree.get_sequence_ref())); }
//! <b>Effects</b>: Discards the internally hold sequence container and adopts the
//! one passed externally using the move assignment.
@ -2911,6 +2921,14 @@ class flat_multimap
BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_range_t, BOOST_RV_REF(sequence_type) seq)
{ this->m_flat_tree.adopt_sequence_equal(ordered_range_t(), boost::move(dtl::force<impl_sequence_type>(seq))); }
//! <b>Effects</b>: Returns a const view of the underlying sequence.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing
BOOST_CONTAINER_FORCEINLINE const sequence_type & sequence() const BOOST_NOEXCEPT
{ return dtl::force<sequence_type>(m_flat_tree.get_sequence_cref()); }
//! <b>Effects</b>: Returns true if x and y are equal
//!
//! <b>Complexity</b>: Linear to the number of elements in the container.

View File

@ -1122,6 +1122,14 @@ class flat_set
//! <b>Throws</b>: If the move assignment throws
BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_unique_range_t, BOOST_RV_REF(sequence_type) seq)
{ this->tree_t::adopt_sequence_unique(ordered_unique_range_t(), boost::move(seq)); }
//! <b>Effects</b>: Returns a const view of the underlying sequence.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing
BOOST_CONTAINER_FORCEINLINE const sequence_type & sequence() const BOOST_NOEXCEPT
{ return this->get_sequence_cref(); }
};
#ifndef BOOST_CONTAINER_NO_CXX17_CTAD
@ -1845,6 +1853,14 @@ class flat_multiset
//! <b>Throws</b>: If the move assignment throws
BOOST_CONTAINER_FORCEINLINE void adopt_sequence(ordered_range_t, BOOST_RV_REF(sequence_type) seq)
{ this->tree_t::adopt_sequence_equal(ordered_range_t(), boost::move(seq)); }
//! <b>Effects</b>: Returns a const view of the underlying sequence.
//!
//! <b>Complexity</b>: Constant
//!
//! <b>Throws</b>: Nothing
BOOST_CONTAINER_FORCEINLINE const sequence_type & sequence() const BOOST_NOEXCEPT
{ return this->get_sequence_cref(); }
};
#ifndef BOOST_CONTAINER_NO_CXX17_CTAD

View File

@ -306,7 +306,7 @@ bool flat_tree_extract_adopt_test()
fmap.emplace(static_cast<int>(i), -static_cast<int>(i));
}
flat_map<int, int> fmap_copy(fmap);
const flat_map<int, int> fmap_copy(fmap);
flat_map<int, int>::sequence_type seq(fmap.extract_sequence());
if(!fmap.empty())
return false;
@ -318,6 +318,8 @@ bool flat_tree_extract_adopt_test()
fmap.adopt_sequence(boost::move(seq));
if(!CheckEqualContainers(fmap, fmap_copy))
return false;
if (!CheckEqualContainers(fmap.sequence(), fmap_copy.sequence()))
return false;
}
//extract/adopt map, ordered_unique_range
@ -329,7 +331,7 @@ bool flat_tree_extract_adopt_test()
fmap.emplace(static_cast<int>(i), -static_cast<int>(i));
}
flat_map<int, int> fmap_copy(fmap);
const flat_map<int, int> fmap_copy(fmap);
flat_map<int, int>::sequence_type seq(fmap.extract_sequence());
if(!fmap.empty())
return false;
@ -339,6 +341,8 @@ bool flat_tree_extract_adopt_test()
fmap.adopt_sequence(ordered_unique_range, boost::move(seq));
if(!CheckEqualContainers(fmap, fmap_copy))
return false;
if (!CheckEqualContainers(fmap.sequence(), fmap_copy.sequence()))
return false;
}
//extract/adopt multimap
@ -351,7 +355,7 @@ bool flat_tree_extract_adopt_test()
fmmap.emplace(static_cast<int>(i), -static_cast<int>(i));
}
flat_multimap<int, int> fmmap_copy(fmmap);
const flat_multimap<int, int> fmmap_copy(fmmap);
flat_multimap<int, int>::sequence_type seq(fmmap.extract_sequence());
if(!fmmap.empty())
return false;
@ -362,6 +366,8 @@ bool flat_tree_extract_adopt_test()
fmmap.adopt_sequence(boost::move(seq));
if(!CheckEqualContainers(fmmap, fmmap_copy))
return false;
if (!CheckEqualContainers(fmmap.sequence(), fmmap_copy.sequence()))
return false;
}
//extract/adopt multimap, ordered_range
@ -374,7 +380,7 @@ bool flat_tree_extract_adopt_test()
fmmap.emplace(static_cast<int>(i), -static_cast<int>(i));
}
flat_multimap<int, int> fmmap_copy(fmmap);
const flat_multimap<int, int> fmmap_copy(fmmap);
flat_multimap<int, int>::sequence_type seq(fmmap.extract_sequence());
if(!fmmap.empty())
return false;
@ -384,6 +390,8 @@ bool flat_tree_extract_adopt_test()
fmmap.adopt_sequence(ordered_range, boost::move(seq));
if(!CheckEqualContainers(fmmap, fmmap_copy))
return false;
if (!CheckEqualContainers(fmmap.sequence(), fmmap_copy.sequence()))
return false;
}
return true;

View File

@ -404,7 +404,7 @@ bool flat_tree_extract_adopt_test()
fset.insert(static_cast<int>(i));
}
flat_set<int> fset_copy(fset);
const flat_set<int> fset_copy(fset);
flat_set<int>::sequence_type seq(fset.extract_sequence());
if(!fset.empty())
return false;
@ -416,6 +416,8 @@ bool flat_tree_extract_adopt_test()
fset.adopt_sequence(boost::move(seq));
if(!CheckEqualContainers(fset, fset_copy))
return false;
if (!CheckEqualContainers(fset.sequence(), fset_copy.sequence()))
return false;
}
//extract/adopt set, ordered_unique_range
@ -427,7 +429,7 @@ bool flat_tree_extract_adopt_test()
fset.insert(static_cast<int>(i));
}
flat_set<int> fset_copy(fset);
const flat_set<int> fset_copy(fset);
flat_set<int>::sequence_type seq(fset.extract_sequence());
if(!fset.empty())
return false;
@ -437,6 +439,8 @@ bool flat_tree_extract_adopt_test()
fset.adopt_sequence(ordered_unique_range, boost::move(seq));
if(!CheckEqualContainers(fset, fset_copy))
return false;
if (!CheckEqualContainers(fset.sequence(), fset_copy.sequence()))
return false;
}
//extract/adopt multiset
@ -449,7 +453,7 @@ bool flat_tree_extract_adopt_test()
fmset.insert(static_cast<int>(i));
}
flat_multiset<int> fmset_copy(fmset);
const flat_multiset<int> fmset_copy(fmset);
flat_multiset<int>::sequence_type seq(fmset.extract_sequence());
if(!fmset.empty())
return false;
@ -460,6 +464,8 @@ bool flat_tree_extract_adopt_test()
fmset.adopt_sequence(boost::move(seq));
if(!CheckEqualContainers(fmset, fmset_copy))
return false;
if (!CheckEqualContainers(fmset.sequence(), fmset_copy.sequence()))
return false;
}
//extract/adopt multiset, ordered_range
@ -472,7 +478,7 @@ bool flat_tree_extract_adopt_test()
fmset.insert(static_cast<int>(i));
}
flat_multiset<int> fmset_copy(fmset);
const flat_multiset<int> fmset_copy(fmset);
flat_multiset<int>::sequence_type seq(fmset.extract_sequence());
if(!fmset.empty())
return false;
@ -482,6 +488,8 @@ bool flat_tree_extract_adopt_test()
fmset.adopt_sequence(ordered_range, boost::move(seq));
if(!CheckEqualContainers(fmset, fmset_copy))
return false;
if (!CheckEqualContainers(fmset.sequence(), fmset_copy.sequence()))
return false;
}
return true;