diff options
Diffstat (limited to 'libs/multi_index')
-rw-r--r-- | libs/multi_index/doc/release_notes.html | 30 | ||||
-rw-r--r-- | libs/multi_index/doc/tutorial/basics.html | 28 | ||||
-rw-r--r-- | libs/multi_index/test/test_set_ops.cpp | 71 |
3 files changed, 117 insertions, 12 deletions
diff --git a/libs/multi_index/doc/release_notes.html b/libs/multi_index/doc/release_notes.html index b467dc0e0..423905c11 100644 --- a/libs/multi_index/doc/release_notes.html +++ b/libs/multi_index/doc/release_notes.html @@ -30,6 +30,7 @@ Acknowledgements <h2>Contents</h2> <ul> + <li><a href="#boost_1_58">Boost 1.58 release</a></li> <li><a href="#boost_1_57">Boost 1.57 release</a></li> <li><a href="#boost_1_56">Boost 1.56 release</a></li> <li><a href="#boost_1_55">Boost 1.55 release</a></li> @@ -50,6 +51,33 @@ Acknowledgements <li><a href="#boost_1_33">Boost 1.33 release</a></li> </ul> +<h2><a name="boost_1_58">Boost 1.58 release</a></h2> + +<p> +<ul> + <li>The efficiency of lookup operations has improved in situations where they involve + the generation of temporary values of <code>key_type</code>. Consider for instance + the following code: +<blockquote><pre> +<span class=keyword>typedef</span> <span class=identifier>multi_index_container</span><span class=special><</span> + <span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>,</span> + <span class=identifier>indexed_by</span><span class=special><</span> + <span class=identifier>ordered_unique</span><span class=special><</span><span class=identifier>identity</span><span class=special><</span><span class=identifier>std</span><span class=special>::</span><span class=identifier>string</span><span class=special>></span> <span class=special>></span> + <span class=special>></span> +<span class=special>></span> <span class=identifier>multi_t</span><span class=special>;</span> +<span class=special>...</span> +<span class=identifier>multi_t</span> <span class=identifier>m</span><span class=special>=...;</span> +<span class=identifier>m</span><span class=special>.</span><span class=identifier>find</span><span class=special>(</span><span class=string>"boost"</span><span class=special>);</span> <span class=comment>// passed a const char*, not a std::string</span> +</pre></blockquote> + In previous versions of the library, the <code>find</code> operation generates + several temporary <code>std::string</code>s (one every time an internal comparison is made). + In sufficiently advanced compilers, this is now avoided so that only one temporary is + created. + </li> + <li>Maintenance fixes.</li> +</ul> +</p> + <h2><a name="boost_1_57">Boost 1.57 release</a></h2> <p> @@ -463,7 +491,7 @@ Acknowledgements <br> -<p>Revised August 20th 2014</p> +<p>Revised November 12th 2014</p> <p>© Copyright 2003-2014 Joaquín M López Muñoz. Distributed under the Boost Software diff --git a/libs/multi_index/doc/tutorial/basics.html b/libs/multi_index/doc/tutorial/basics.html index f05d4218c..14ed98f17 100644 --- a/libs/multi_index/doc/tutorial/basics.html +++ b/libs/multi_index/doc/tutorial/basics.html @@ -474,6 +474,18 @@ means of user-defined <code>typedef</code>s: <span class=identifier>es</span><span class=special>.</span><span class=identifier>get</span><span class=special><</span><span class=number>1</span><span class=special>>().</span><span class=identifier>find</span><span class=special>(</span><span class=string>"Judy Smith"</span><span class=special>);</span> </pre></blockquote> +<p> +The iterators provided by every index are <i>constant</i>, that is, the elements they point to +cannot be mutated directly. This follows the interface of <code>std::set</code> for ordered +indices but might come as a surprise for other types such as sequenced indices, which are modeled after +<code>std::list</code>, where this limitation does not happen. This seemingly odd behavior +is imposed by the way <code>multi_index_container</code>s work; if elements were +allowed to be mutated indiscriminately, we could introduce inconsistencies +in the ordered indices of the <code>multi_index_container</code> without the container +being notified about it. Element modification is properly done by means of +<a href="#ord_updating">update operations</a> on any index. +</p> + <h2> <a name="index_types">Index types</a> </h2> @@ -1060,9 +1072,9 @@ same way as <code>std::list</code> permits. The interface of sequenced indices is thus designed upon that of <code>std::list</code>; nearly every operation provided in the standard container is replicated here, occasionally with changes in the syntax and/or semantics to cope with the constraints imposed by -Boost.MultiIndex. In particular, there is an important limitation of sequenced -indices with respect to <code>std::list</code>s, namely that elements of an -<code>multi_index_container</code> are not mutable through an iterator: +Boost.MultiIndex. An important difference, commented <a href="#iterator_access">above</a>, +is the fact that the values pointed to by sequenced index iterators are treated +as <i>constant</i>: </p> <blockquote><pre> @@ -1076,11 +1088,7 @@ indices with respect to <code>std::list</code>s, namely that elements of an </pre></blockquote> <p> -That is, iterators of a sequenced index (of all types of indices, actually) -point to constant elements. This limitation might come as a surprise, but -it is imposed by the way <code>multi_index_container</code>s work; if elements were -allowed to be changed in this manner, we could introduce inconsistencies -in other ordered indices of the <code>multi_index_container</code>. Element modification +As with any other type of index, element modification can nevertheless be done by means of <a href="#seq_updating">update operations</a>. </p> @@ -1240,9 +1248,9 @@ Index types <br> -<p>Revised November 7th 2008</p> +<p>Revised November 11th 2014</p> -<p>© Copyright 2003-2008 Joaquín M López Muñoz. +<p>© Copyright 2003-2014 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file <a href="../../../../LICENSE_1_0.txt"> LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt"> diff --git a/libs/multi_index/test/test_set_ops.cpp b/libs/multi_index/test/test_set_ops.cpp index 0057ab41c..0e9a70da8 100644 --- a/libs/multi_index/test/test_set_ops.cpp +++ b/libs/multi_index/test/test_set_ops.cpp @@ -1,6 +1,6 @@ /* Boost.MultiIndex test for standard set operations. * - * Copyright 2003-2013 Joaquin M Lopez Munoz. + * Copyright 2003-2014 Joaquin M Lopez Munoz. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) @@ -19,6 +19,41 @@ using namespace boost::multi_index; +struct type1{}; + +struct type2 +{ +private: + operator type1()const{return type1();} +}; + +struct type3 +{ + operator type1()const{return type1();} +}; + +struct less_type12 +{ + bool operator()(type1,type1)const{return false;} + bool operator()(type1,type2)const{return false;} + bool operator()(type2,type1)const{return false;} +}; + +bool less_type1_f(type1,type1){return false;} + +struct hash_type12 +{ + std::size_t operator()(type1)const{return 0;} + std::size_t operator()(type2)const{return 0;} +}; + +struct eq_type12 +{ + bool operator()(type1,type1)const{return true;} + bool operator()(type1,type2)const{return true;} + bool operator()(type2,type1)const{return true;} +}; + void test_set_ops() { employee_set es; @@ -55,4 +90,38 @@ void test_set_ops() std::pair<employee_set_by_age::iterator,employee_set_by_age::iterator> p2= i2.equal_range(30); BOOST_TEST(p2.first==p2.second&&p2.first->age==31); + + /* check promotion detection plays nice with private conversion */ + + multi_index_container< + type1, + indexed_by< + ordered_unique<identity<type1>,less_type12>, + hashed_unique<identity<type1>,hash_type12,eq_type12> + > + > c; + c.insert(type1()); + + BOOST_TEST(c.find(type2())==c.begin()); + BOOST_TEST(c.count(type2())==1); + BOOST_TEST(c.lower_bound(type2())==c.begin()); + BOOST_TEST(c.upper_bound(type2())==c.end()); + BOOST_TEST(c.equal_range(type2())==std::make_pair(c.begin(),c.end())); + + BOOST_TEST(c.get<1>().find(type2())==c.get<1>().begin()); + BOOST_TEST(c.get<1>().count(type2())==1); + BOOST_TEST(c.get<1>().equal_range(type2())== + std::make_pair(c.get<1>().begin(),c.get<1>().end())); + + /* check promotion detection does not break with functions */ + + multi_index_container< + type1, + indexed_by< + ordered_unique<identity<type1>,bool(*)(type1,type1)> + > + > c2(boost::make_tuple(boost::make_tuple(identity<type1>(),&less_type1_f))); + c2.insert(type1()); + + BOOST_TEST(c2.find(type3())==c2.begin()); } |