Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81807 - in trunk: boost/bimap/detail boost/bimap/relation libs/bimap/doc/html libs/bimap/test
From: matias.capeletto_at_[hidden]
Date: 2012-12-09 07:02:52


Author: matias
Date: 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
New Revision: 81807
URL: http://svn.boost.org/trac/boost/changeset/81807

Log:
[bimap] Fix replace_(left/right/key/data) bug when using relations with info.
Added:
   trunk/libs/bimap/doc/html/standalone_HTML.manifest (contents, props changed)
Text files modified:
   trunk/boost/bimap/detail/map_view_base.hpp | 6 ++-
   trunk/boost/bimap/detail/set_view_base.hpp | 4 +-
   trunk/boost/bimap/relation/mutant_relation.hpp | 46 +++++++++++++++++++++++++++
   trunk/boost/bimap/relation/structured_pair.hpp | 43 ++++++++++++++++++++++++++
   trunk/libs/bimap/test/test_bimap_extra.cpp | 3 -
   trunk/libs/bimap/test/test_bimap_modify.cpp | 66 ++++++++++++++++++++++++++++++++++++++++
   6 files changed, 161 insertions(+), 7 deletions(-)

Modified: trunk/boost/bimap/detail/map_view_base.hpp
==============================================================================
--- trunk/boost/bimap/detail/map_view_base.hpp (original)
+++ trunk/boost/bimap/detail/map_view_base.hpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -133,7 +133,8 @@
         return derived().base().replace(
             derived().template functor<iterator_to_base_>()(position),
             derived().template functor<value_to_base_>()(
- value_type_(k,position->second)
+ ::boost::bimaps::relation::detail::
+ copy_with_first_replaced(*position,k)
             )
         );
     }
@@ -144,7 +145,8 @@
         return derived().base().replace(
             derived().template functor<iterator_to_base_>()(position),
             derived().template functor<value_to_base_>()(
- value_type_(position->first,d)
+ ::boost::bimaps::relation::detail::
+ copy_with_second_replaced(*position,d)
             )
         );
     }

Modified: trunk/boost/bimap/detail/set_view_base.hpp
==============================================================================
--- trunk/boost/bimap/detail/set_view_base.hpp (original)
+++ trunk/boost/bimap/detail/set_view_base.hpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -199,7 +199,7 @@
     {
         return derived().base().replace(
             derived().template functor<iterator_to_base_>()(position),
- value_type_(l,position->right)
+ ::boost::bimaps::relation::detail::copy_with_left_replaced(*position,l)
         );
     }
 
@@ -209,7 +209,7 @@
     {
         return derived().base().replace(
             derived().template functor<iterator_to_base_>()(position),
- value_type_(position->left,r)
+ ::boost::bimaps::relation::detail::copy_with_right_replaced(*position,r)
         );
     }
 

Modified: trunk/boost/bimap/relation/mutant_relation.hpp
==============================================================================
--- trunk/boost/bimap/relation/mutant_relation.hpp (original)
+++ trunk/boost/bimap/relation/mutant_relation.hpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -346,7 +346,7 @@
     {
         return ::boost::bimaps::relation::support::get<Tag>(*this);
     }
-
+
     #ifndef BOOST_BIMAP_DISABLE_SERIALIZATION
 
     private:
@@ -422,6 +422,50 @@
              (( a.left == b.left ) && ( a.right >= b.right )));
 }
 
+namespace detail {
+
+template< class TA, class TB, class Info, bool force_mutable>
+mutant_relation<TA,TB,Info,force_mutable>
+ copy_with_left_replaced(mutant_relation<TA,TB,Info,force_mutable> const& rel,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ mutant_relation<TA,TB,Info,force_mutable>::left_value_type>
+ ::param_type l)
+{
+ return mutant_relation<TA,TB,Info,force_mutable>(l,rel.right,rel.info);
+}
+
+template< class TA, class TB, bool force_mutable>
+mutant_relation<TA,TB,::boost::mpl::na,force_mutable>
+ copy_with_left_replaced(mutant_relation<TA,TB,::boost::mpl::na,force_mutable> const& rel,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ mutant_relation<TA,TB,::boost::mpl::na,force_mutable>::left_value_type>
+ ::param_type l)
+{
+ return mutant_relation<TA,TB,::boost::mpl::na,force_mutable>(l,rel.right);
+}
+
+template< class TA, class TB, class Info, bool force_mutable>
+mutant_relation<TA,TB,Info,force_mutable>
+ copy_with_right_replaced(mutant_relation<TA,TB,Info,force_mutable> const& rel,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ mutant_relation<TA,TB,Info,force_mutable>::right_value_type>
+ ::param_type r)
+{
+ return mutant_relation<TA,TB,Info,force_mutable>(rel.left,r,rel.info);
+}
+
+template< class TA, class TB, bool force_mutable>
+mutant_relation<TA,TB,::boost::mpl::na,force_mutable>
+ copy_with_right_replaced(mutant_relation<TA,TB,::boost::mpl::na,force_mutable> const& rel,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ mutant_relation<TA,TB,::boost::mpl::na,force_mutable>::right_value_type>
+ ::param_type r)
+{
+ return mutant_relation<TA,TB,::boost::mpl::na,force_mutable>(rel.left,r);
+}
+
+}
+
 } // namespace relation
 } // namespace bimaps
 } // namespace boost

Modified: trunk/boost/bimap/relation/structured_pair.hpp
==============================================================================
--- trunk/boost/bimap/relation/structured_pair.hpp (original)
+++ trunk/boost/bimap/relation/structured_pair.hpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -499,6 +499,49 @@
 }
 
 
+namespace detail {
+
+template< class FirstType, class SecondType, class Info, class Layout>
+structured_pair<FirstType,SecondType,Info,Layout>
+ copy_with_first_replaced(structured_pair<FirstType,SecondType,Info,Layout> const& p,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ structured_pair<FirstType,SecondType,Info,Layout>::first_type>
+ ::param_type f)
+{
+ return structured_pair<FirstType,SecondType,Info,Layout>(f,p.second,p.info);
+}
+
+template< class FirstType, class SecondType, class Layout>
+structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>
+ copy_with_first_replaced(structured_pair<FirstType,SecondType,::boost::mpl::na,Layout> const& p,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>::first_type>
+ ::param_type f)
+{
+ return structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>(f,p.second);
+}
+
+template< class FirstType, class SecondType, class Info, class Layout>
+structured_pair<FirstType,SecondType,Info,Layout>
+ copy_with_second_replaced(structured_pair<FirstType,SecondType,Info,Layout> const& p,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ structured_pair<FirstType,SecondType,Info,Layout>::second_type>
+ ::param_type s)
+{
+ return structured_pair<FirstType,SecondType,Info,Layout>(p.first,s,p.info);
+}
+
+template< class FirstType, class SecondType, class Layout>
+structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>
+ copy_with_second_replaced(structured_pair<FirstType,SecondType,::boost::mpl::na,Layout> const& p,
+ BOOST_DEDUCED_TYPENAME ::boost::call_traits< BOOST_DEDUCED_TYPENAME
+ structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>::second_type>
+ ::param_type s)
+{
+ return structured_pair<FirstType,SecondType,::boost::mpl::na,Layout>(p.first,s);
+}
+}
+
 
 } // namespace relation
 } // namespace bimaps

Added: trunk/libs/bimap/doc/html/standalone_HTML.manifest
==============================================================================
--- (empty file)
+++ trunk/libs/bimap/doc/html/standalone_HTML.manifest 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -0,0 +1,40 @@
+index.html
+boost_bimap/introduction.html
+boost_bimap/one_minute_tutorial.html
+boost_bimap/the_tutorial.html
+boost_bimap/the_tutorial/discovering_the_bimap_framework.html
+boost_bimap/the_tutorial/controlling_collection_types.html
+boost_bimap/the_tutorial/the_collection_of_relations_type.html
+boost_bimap/the_tutorial/differences_with_standard_maps.html
+boost_bimap/the_tutorial/useful_functions.html
+boost_bimap/the_tutorial/bimaps_with_user_defined_names.html
+boost_bimap/the_tutorial/unconstrained_sets.html
+boost_bimap/the_tutorial/additional_information.html
+boost_bimap/the_tutorial/complete_instantiation_scheme.html
+boost_bimap/bimap_and_boost.html
+boost_bimap/bimap_and_boost/boost_libraries_that_work_well_with_boost_bimap.html
+boost_bimap/bimap_and_boost/dependencies.html
+boost_bimap/reference.html
+boost_bimap/reference/bimap_reference.html
+boost_bimap/reference/set_of_reference.html
+boost_bimap/reference/unordered_set_of_reference.html
+boost_bimap/reference/list_of_reference.html
+boost_bimap/reference/vector_of_reference.html
+boost_bimap/reference/unconstrained_set_of_reference.html
+boost_bimap/compiler_specifics.html
+boost_bimap/performance.html
+boost_bimap/examples.html
+boost_bimap/examples/simple_bimap.html
+boost_bimap/examples/mighty_bimap.html
+boost_bimap/examples/multiindex_to_bimap_path___bidirectional_map.html
+boost_bimap/examples/multiindex_to_bimap_path___hashed_indices.html
+boost_bimap/test_suite.html
+boost_bimap/future_work.html
+boost_bimap/release_notes.html
+boost_bimap/rationale.html
+boost_bimap/rationale/additional_features.html
+boost_bimap/rationale/code.html
+boost_bimap/rationale/the_student_and_the_mentor.html
+boost_bimap/history.html
+boost_bimap/history/multiindex_and_bimap.html
+boost_bimap/acknowledgements.html

Modified: trunk/libs/bimap/test/test_bimap_extra.cpp
==============================================================================
--- trunk/libs/bimap/test/test_bimap_extra.cpp (original)
+++ trunk/libs/bimap/test/test_bimap_extra.cpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -70,8 +70,7 @@
 
     typedef boost::is_same
     <
- pair_type_by< member_at::left,
- BOOST_DEDUCED_TYPENAME bm_type::relation>::type,
+ pair_type_by< member_at::left, bm_type::relation>::type,
         value_type_by< member_at::left , bm_type >::type
 
>::type test_metafunction_4;

Modified: trunk/libs/bimap/test/test_bimap_modify.cpp
==============================================================================
--- trunk/libs/bimap/test/test_bimap_modify.cpp (original)
+++ trunk/libs/bimap/test/test_bimap_modify.cpp 2012-12-09 07:02:51 EST (Sun, 09 Dec 2012)
@@ -174,10 +174,76 @@
 
 }
 
+void test_bimap_replace_with_info()
+{
+ using namespace boost::bimaps;
+ typedef bimap<int,long,with_info<int> > bm;
+
+ bm b;
+ b.insert( bm::value_type(2,200,-2) );
+
+ BOOST_CHECK( b.left.at(2) == 200 );
+ BOOST_CHECK( b.left.info_at(2) == -2 );
+
+ // Use set view
+ {
+ bm::iterator i = b.begin();
+
+ bool result = b.replace( i, bm::value_type(1,100,-1) );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.size() == 1 );
+ BOOST_CHECK( i->left == 1 && i->right == 100 );
+ BOOST_CHECK( i->info == -1 );
+
+ result = b.replace_left( i, 2 );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.size() == 1 );
+ BOOST_CHECK( i->left == 2 && i->right == 100 );
+ BOOST_CHECK( i->info == -1 );
+
+ result = b.replace_right( i, 200 );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.size() == 1 );
+ BOOST_CHECK( i->left == 2 && i->right == 200 );
+ BOOST_CHECK( i->info == -1 );
+ }
+
+ // Use map view
+ {
+ bm::left_iterator i = b.left.begin();
+
+ bool result = b.left.replace( i, bm::left_value_type(1,100,-1) );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.left.size() == 1 );
+ BOOST_CHECK( i->first == 1 && i->second == 100 );
+ BOOST_CHECK( i->info == -1 );
+
+ result = b.left.replace_key( i, 2 );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.left.size() == 1 );
+ BOOST_CHECK( i->first == 2 && i->second == 100 );
+ BOOST_CHECK( i->info == -1 );
+
+ result = b.left.replace_data( i, 200 );
+
+ BOOST_CHECK( result );
+ BOOST_CHECK( b.left.size() == 1 );
+ BOOST_CHECK( i->first == 2 && i->second == 200 );
+ BOOST_CHECK( i->info == -1 );
+ }
+}
+
 int test_main( int, char* [] )
 {
     test_bimap_modify();
 
+ test_bimap_replace_with_info();
+
     return 0;
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk