Skip to content

Commit

Permalink
fixed #68
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquintides committed May 21, 2023
1 parent 0e55b48 commit f8143b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
14 changes: 13 additions & 1 deletion doc/release_notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ <h1><img src="../../../boost.png" alt="boost.png (6897 bytes)" align=
<h2>Contents</h2>

<ul>
<li><a href="#boost_1_83">Boost 1.83 release</a></li>
<li><a href="#boost_1_82">Boost 1.82 release</a></li>
<li><a href="#boost_1_81">Boost 1.81 release</a></li>
<li><a href="#boost_1_80">Boost 1.80 release</a></li>
Expand Down Expand Up @@ -69,6 +70,17 @@ <h2>Contents</h2>
<li><a href="#boost_1_33">Boost 1.33 release</a></li>
</ul>

<h2><a name="boost_1_83">Boost 1.83 release</a></h2>

<p>
<ul>
<li>Updated range <code>insert</code> in non-unique ordered indices to preserve insertion order
of equivalent elements
(<a href="https://github.com/boostorg/multi_index/issues/68">issue #68</a>).
</li>
</ul>
</p>

<h2><a name="boost_1_82">Boost 1.82 release</a></h2>

<p>
Expand Down Expand Up @@ -774,7 +786,7 @@ <h2><a name="boost_1_33">Boost 1.33 release</a></h2>

<br>

<p>Revised February 26th 2023</p>
<p>Revised May 21st 2023</p>

<p>&copy; Copyright 2003-2023 Joaqu&iacute;n M L&oacute;pez Mu&ntilde;oz.
Distributed under the Boost Software
Expand Down
7 changes: 1 addition & 6 deletions include/boost/multi_index/detail/ord_index_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,7 @@ class ordered_index_impl:
void insert(InputIterator first,InputIterator last)
{
BOOST_MULTI_INDEX_ORD_INDEX_CHECK_INVARIANT;
index_node_type* hint=header(); /* end() */
for(;first!=last;++first){
hint=this->final_insert_ref_(
*first,static_cast<final_node_type*>(hint)).first;
index_node_type::increment(hint);
}
for(;first!=last;++first)this->final_insert_ref_(*first);
}

#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
Expand Down
35 changes: 35 additions & 0 deletions test/test_iterators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
#include "test_iterators.hpp"

#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include "pair_of_ints.hpp"
#include "pre_multi_index.hpp"
#include "employee.hpp"
#include <algorithm>
#include <boost/detail/lightweight_test.hpp>
#include <boost/next_prior.hpp>
#include <boost/foreach.hpp>
#include <vector>

using namespace boost::multi_index;

Expand Down Expand Up @@ -272,4 +275,36 @@ void test_iterators()
test_non_const_rnd_iterators (get<5>(es),target);
test_const_rnd_iterators (get<5>(es),target);
test_boost_for_each (get<5>(es),target);

/* testcase for https://github.com/boostorg/multi_index/issues/68 */

{
typedef multi_index_container<
pair_of_ints,
indexed_by<
ordered_non_unique<member<pair_of_ints,int,&pair_of_ints::first> >
>
> container;
typedef typename container::iterator iterator;

container c1,c2;

std::vector<pair_of_ints> input;
input.push_back(pair_of_ints(1,0));
input.push_back(pair_of_ints(1,1));
input.push_back(pair_of_ints(1,2));
input.push_back(pair_of_ints(0,0));
input.push_back(pair_of_ints(1,3));

c1.insert(input.begin(),input.end());
for(std::size_t i=0;i<input.size();++i)c2.insert(input[i]);

std::pair<iterator,iterator> rng1=c1.equal_range(1),
rng2=c2.equal_range(1);

BOOST_TEST(
std::distance(rng1.first,rng1.second)==
std::distance(rng2.first,rng2.second));
BOOST_TEST(std::equal(rng1.first,rng1.second,rng2.first));
}
}

0 comments on commit f8143b9

Please sign in to comment.