Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58187 - in sandbox/itl: boost/itl/detail libs/itl/test/test_casual_
From: afojgo_at_[hidden]
Date: 2009-12-06 09:14:19


Author: jofaber
Date: 2009-12-06 09:14:18 EST (Sun, 06 Dec 2009)
New Revision: 58187
URL: http://svn.boost.org/trac/boost/changeset/58187

Log:
Added some enable_ifs and meta predicates to manage overloading of mapped_reference. Stable {msvc-9.0}

Text files modified:
   sandbox/itl/boost/itl/detail/mapped_reference.hpp | 212 +++++++++++++++++++++++++--------------
   sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp | 28 +++--
   2 files changed, 154 insertions(+), 86 deletions(-)

Modified: sandbox/itl/boost/itl/detail/mapped_reference.hpp
==============================================================================
--- sandbox/itl/boost/itl/detail/mapped_reference.hpp (original)
+++ sandbox/itl/boost/itl/detail/mapped_reference.hpp 2009-12-06 09:14:18 EST (Sun, 06 Dec 2009)
@@ -9,12 +9,53 @@
 #define BOOST_ITL_DETAIL_MAPPED_REFERENCE_HPP_JOFA_091108
 
 #include <boost/type_traits/is_const.hpp>
+#include <boost/type_traits/remove_const.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/itl/type_traits/is_concept_equivalent.hpp>
 
 namespace boost{namespace itl
 {
 
+template<class FirstT, class SecondT> class mapped_reference;
+
+//------------------------------------------------------------------------------
+template<class Type>
+struct is_mapped_reference_combinable{
+ typedef is_mapped_reference_combinable type;
+ BOOST_STATIC_CONSTANT(bool, value = false);
+};
+
+template<class FirstT, class SecondT>
+struct is_mapped_reference_combinable<std::pair<const FirstT,SecondT> >
+{
+ typedef is_mapped_reference_combinable<std::pair<const FirstT,SecondT> > type;
+ BOOST_STATIC_CONSTANT(bool, value = true);
+};
+
+template<class FirstT, class SecondT>
+struct is_mapped_reference_combinable<std::pair<FirstT,SecondT> >
+{
+ typedef is_mapped_reference_combinable<std::pair<FirstT,SecondT> > type;
+ BOOST_STATIC_CONSTANT(bool, value = true);
+};
+
+//------------------------------------------------------------------------------
+template<class Type>
+struct is_mapped_reference_or_combinable{
+ typedef is_mapped_reference_or_combinable type;
+ BOOST_STATIC_CONSTANT(bool, value = is_mapped_reference_combinable<Type>::value);
+};
+
+template<class FirstT, class SecondT>
+struct is_mapped_reference_or_combinable<mapped_reference<FirstT,SecondT> >
+{
+ typedef is_mapped_reference_or_combinable<mapped_reference<FirstT,SecondT> > type;
+ BOOST_STATIC_CONSTANT(bool, value = true);
+};
+
+
+
+//------------------------------------------------------------------------------
 template<class FirstT, class SecondT>
 class mapped_reference
 {
@@ -24,12 +65,16 @@
     typedef FirstT first_type;
     typedef SecondT second_type;
     typedef mapped_reference type;
+
     typedef typename
         mpl::if_<is_const<second_type>,
                        second_type&,
                  const second_type&>::type second_reference_type;
 
- const FirstT& first;
+ typedef std::pair< first_type, second_type> std_pair_type;
+ typedef std::pair<const first_type, second_type> key_std_pair_type;
+
+ const first_type& first ;
     second_reference_type second;
 
     mapped_reference(const FirstT& fst, second_reference_type snd) : first(fst), second(snd){}
@@ -40,86 +85,103 @@
 
     template<class FstT, class SndT>
     operator std::pair<FstT,SndT>(){ return std::pair<FstT,SndT>(first, second); }
-};
-
-
-template<class FirstT, class SecondT>
-inline bool operator == (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return left.first == right.first && left.second == right.second; }
 
-template<class FirstT, class SecondT>
-inline bool operator == (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return left.first == right.first && left.second == right.second; }
-
-template<class FirstT, class SecondT>
-inline bool operator == (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return left.first == right.first && left.second == right.second; }
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator == (const Comparand& right)const
+ { return first == right.first && second == right.second; }
+
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator != (const Comparand& right)const
+ { return !(*this == right); }
+
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator < (const Comparand& right)const
+ {
+ return first < right.first
+ ||(!(right.first < first) && second < right.second);
+ }
+
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator > (const Comparand& right)const
+ {
+ return first > right.first
+ ||(!(right.first > first) && second > right.second);
+ }
+
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator <= (const Comparand& right)const
+ {
+ return !(*this > right);
+ }
+
+ template<class Comparand>
+ typename enable_if<is_mapped_reference_or_combinable<Comparand>, bool>::type
+ operator >= (const Comparand& right)const
+ {
+ return !(*this < right);
+ }
 
-//------------------------------------------------------------------------------
-template<class FirstT, class SecondT>
-inline bool operator < (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return left.first < right.first || (!(right.first < left.first) && left.second < right.second); }
-
-template<class FirstT, class SecondT>
-inline bool operator < (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return left.first < right.first || (!(right.first < left.first) && left.second < right.second); }
-
-template<class FirstT, class SecondT>
-inline bool operator < (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return left.first < right.first || (!(right.first < left.first) && left.second < right.second); }
-
-//------------------------------------------------------------------------------
-template<class FirstT, class SecondT>
-inline bool operator != (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(left == right); }
-
-template<class FirstT, class SecondT>
-inline bool operator != (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return !(left == right); }
-
-template<class FirstT, class SecondT>
-inline bool operator != (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(left == right); }
-
-//------------------------------------------------------------------------------
-template<class FirstT, class SecondT>
-inline bool operator > (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return right < left; }
-
-template<class FirstT, class SecondT>
-inline bool operator > (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return right < left; }
-
-template<class FirstT, class SecondT>
-inline bool operator > (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return right < left; }
+};
 
 //------------------------------------------------------------------------------
-template<class FirstT, class SecondT>
-inline bool operator <= (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(right < left); }
-
-template<class FirstT, class SecondT>
-inline bool operator <= (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return !(right < left); }
-
-template<class FirstT, class SecondT>
-inline bool operator <= (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(right < left); }
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator == ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return right == left;
+}
+
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator != ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return !(right == left);
+}
+
+//------------------------------------------------------------------------------
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator < ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return right > left;
+}
+
+//------------------------------------------------------------------------------
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator > ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return right < left;
+}
+
+//------------------------------------------------------------------------------
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator <= ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return !(right < left);
+}
+
+//------------------------------------------------------------------------------
+template<class FirstT, class SecondT, class StdPairT>
+inline typename enable_if<is_mapped_reference_combinable<StdPairT>, bool>::type
+operator >= ( const StdPairT& left,
+ const mapped_reference<FirstT, SecondT>& right)
+{
+ return !(left < right);
+}
 
 //------------------------------------------------------------------------------
-template<class FirstT, class SecondT>
-inline bool operator >= (const mapped_reference<FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(left < right); }
-
-template<class FirstT, class SecondT>
-inline bool operator >= (const mapped_reference<FirstT, SecondT>& left, const std::pair<const FirstT, SecondT>& right)
-{ return !(left < right); }
-
-template<class FirstT, class SecondT>
-inline bool operator >= (const std::pair<const FirstT, SecondT>& left, const mapped_reference<FirstT, SecondT>& right)
-{ return !(left < right); }
-
 //------------------------------------------------------------------------------
 template<class FirstT, class SecondT>
 inline mapped_reference<FirstT, SecondT> make_mapped_reference(const FirstT& left, SecondT& right)

Modified: sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp
==============================================================================
--- sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp (original)
+++ sandbox/itl/libs/itl/test/test_casual_/test_casual.cpp 2009-12-06 09:14:18 EST (Sun, 06 Dec 2009)
@@ -41,16 +41,22 @@
 
 BOOST_AUTO_TEST_CASE(reverse_iter)
 {
- itl::list<int> list_a, list_b;
- list_a.push_back(1);
- list_a.push_back(2);
- cout << list_a << endl;
- //std::copy_backward(list_a.begin(), list_a.end(), std::inserter(list_b, list_b.end()));
- fill_n(std::inserter(list_b, list_b.end()) , 2, -1);
- //list_b.push_back(-1);
- //list_b.push_back(-1);
- itl::list<int>::iterator ins = list_b.end();
- std::copy_backward(list_a.begin(), list_a.end(), ins);
- cout << list_b << endl;
+ interval_map<int,int> map_a;
+ map_a += make_pair(interval<int>::rightopen(0,3),1);
+ cout << map_a << endl;
+
+ for(interval_map<int,int>::element_iterator elem = map_a.elements_begin();
+ elem != map_a.elements_end(); elem++)
+ cout << "(" << elem->first << "," << elem->second << ")";
+ cout << "\n-------------------------------------\n";
+
+ std::pair<const int, int> search_pair(2,1);
+
+ interval_map<int,int>::element_const_iterator found
+ = std::find(map_a.elements_begin(), map_a.elements_end(), search_pair);
+ cout << "(" << found->first << "," << found->second << ")\n";
+
+ const_cast<int&>(found->second) = 2;
+ cout << map_a << endl;
 }
 


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