Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54622 - in sandbox/cloneable: boost/cloneable/detail libs/cloneable/test
From: christian.schladetsch_at_[hidden]
Date: 2009-07-03 18:45:08


Author: cschladetsch
Date: 2009-07-03 18:45:07 EDT (Fri, 03 Jul 2009)
New Revision: 54622
URL: http://svn.boost.org/trac/boost/changeset/54622

Log:
added relational operators for associtive_container_base<>

Text files modified:
   sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp | 13 +++++++++++++
   sandbox/cloneable/boost/cloneable/detail/container_base.hpp | 14 ++++++++++----
   sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp | 13 +++++++------
   sandbox/cloneable/libs/cloneable/test/tests.cpp | 11 +++++++----
   4 files changed, 37 insertions(+), 14 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/associative_container_base.hpp 2009-07-03 18:45:07 EDT (Fri, 03 Jul 2009)
@@ -16,6 +16,7 @@
         {
                 namespace detail
                 {
+ /// common base for associative containers
                         template <class Cont, class Pred, class Base, class Alloc>
                         struct associative_container_base
                                 : container_base<Cont,Base,Alloc>
@@ -96,6 +97,18 @@
 
                         };
 
+ template <class Cont, class Pred, class Base, class Alloc>
+ bool operator==(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
+ {
+ return left.size() == right.size() && std::equal(left.begin(), left.end(), right.begin());
+ }
+
+ template <class Cont, class Pred, class Base, class Alloc>
+ bool operator<(const associative_container_base<Cont,Pred,Base,Alloc> &left, const associative_container_base<Cont,Pred,Base,Alloc> &right)
+ {
+ return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
+ }
+
                 } // namespace detail
 
         } // namespace cloneable

Modified: sandbox/cloneable/boost/cloneable/detail/container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/container_base.hpp 2009-07-03 18:45:07 EDT (Fri, 03 Jul 2009)
@@ -55,11 +55,15 @@
                                         : cloneable::instance<Derived, Base, Alloc, typename traits<Derived>::construction_tag>
                                 {
                                         typedef cloneable::instance<Derived, Base, Alloc, typename traits<Derived>::construction_tag> parent_type;
+
                                         instance(allocator_type &a) : parent_type(a) { }
+
                                         template <class A0>
                                         instance(allocator_type &a, A0 a0) : parent_type(a, a0) { }
+
                                         template <class A0, class A1>
                                         instance(allocator_type &a, A0 a0, A1 a1) : parent_type(a, a0, a1) { }
+
                                         template <class A0, class A1, class A2>
                                         instance(allocator_type &a, A0 a0, A1 a1, A2 a2) : parent_type(a, a0, a1, a2) { }
                                 };
@@ -68,7 +72,6 @@
                                 allocator_type alloc;
 
                         protected:
-
                                 template <class U>
                                 instance<U> new_instance()
                                 {
@@ -91,9 +94,13 @@
                                 }
 
                         public:
- container_base() { }
+ container_base()
+ {
+ }
                                 container_base(allocator_type &a)
- : alloc(a) { }
+ : alloc(a)
+ {
+ }
 
                                 const allocator_type &get_allocator() const
                                 {
@@ -106,7 +113,6 @@
 
                         };
 
-
                 } // namespace detail
 
         } // namespace cloneable

Modified: sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/detail/sequence_container_base.hpp 2009-07-03 18:45:07 EDT (Fri, 03 Jul 2009)
@@ -16,6 +16,7 @@
         {
                 namespace detail
                 {
+ /// common base for sequence containers
                         template <class Cont, class Base, class Alloc>
                         struct sequence_container_base : container_base<Cont,Base,Alloc>
                         {
@@ -56,11 +57,6 @@
                                 {
                                 }
 
- size_t size() const
- {
- return container.size();
- }
-
                                 template <class Ty, class Fun>
                                 Fun for_each(Fun fun)
                                 {
@@ -87,6 +83,11 @@
                                         return fun;
                                 }
 
+ size_t size() const
+ {
+ return container.size();
+ }
+
                                 bool empty() const
                                 {
                                         return impl().empty();
@@ -190,7 +191,6 @@
                                 }
                         };
 
-
                         template <class Cont, class Base, class Alloc>
                         bool operator==(const sequence_container_base<Cont,Base,Alloc> &left, const sequence_container_base<Cont,Base,Alloc> &right)
                         {
@@ -202,6 +202,7 @@
                         {
                                 return std::lexicographical_compare(left.begin(), left.end(), right.begin(), right.end());
                         }
+
                 } // namespace detail
 
         } // namespace cloneable

Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-07-03 18:45:07 EDT (Fri, 03 Jul 2009)
@@ -582,9 +582,13 @@
         {
                 int number;
                 set_base(int n = 0) : number(n) { }
- bool operator<(const set_base &other) const
+ friend bool operator==(const set_base &left, const set_base &right)
                 {
- return number < other.number;
+ return left.number == right.number;
+ }
+ friend bool operator<(const set_base &left, const set_base &right)
+ {
+ return left.number < right.number;
                 }
         };
         struct S0 : base<S0, set_base>
@@ -627,6 +631,7 @@
         BOOST_ASSERT(set.find<set_base>(1) != set.end());
 
         Set copy = set;
+ BOOST_ASSERT(copy == set);
 
         BOOST_ASSERT(copy.size() == 4);
         BOOST_ASSERT(copy.find<S0>(1) != copy.end());
@@ -638,8 +643,6 @@
         BOOST_ASSERT(&*found == s0);
 }
 
-
 //EOF
 
-
  
\ No newline at end of file


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