os/ossrv/ossrv_pub/boost_apis/boost/tuple/tuple_comparison.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/tuple/tuple_comparison.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,175 @@
     1.4 +// tuple_comparison.hpp -----------------------------------------------------
     1.5 +//  
     1.6 +// Copyright (C) 2001 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
     1.7 +// Copyright (C) 2001 Gary Powell (gary.powell@sierra.com)
     1.8 +//
     1.9 +// Distributed under the Boost Software License, Version 1.0. (See
    1.10 +// accompanying file LICENSE_1_0.txt or copy at
    1.11 +// http://www.boost.org/LICENSE_1_0.txt)
    1.12 +// 
    1.13 +// For more information, see http://www.boost.org
    1.14 +// 
    1.15 +// (The idea and first impl. of comparison operators was from Doug Gregor)
    1.16 +
    1.17 +// ----------------------------------------------------------------- 
    1.18 +
    1.19 +#ifndef BOOST_TUPLE_COMPARISON_HPP
    1.20 +#define BOOST_TUPLE_COMPARISON_HPP
    1.21 +
    1.22 +#include "boost/tuple/tuple.hpp"
    1.23 +
    1.24 +// -------------------------------------------------------------
    1.25 +// equality and comparison operators 
    1.26 +//
    1.27 +// == and != compare tuples elementwise
    1.28 +// <, >, <= and >= use lexicographical ordering
    1.29 +//
    1.30 +// Any operator between tuples of different length fails at compile time
    1.31 +// No dependencies between operators are assumed 
    1.32 +// (i.e. !(a<b)  does not imply a>=b, a!=b does not imply a==b etc.
    1.33 +// so any weirdnesses of elementary operators are respected).
    1.34 +//
    1.35 +// -------------------------------------------------------------
    1.36 +
    1.37 +
    1.38 +namespace boost {
    1.39 +namespace tuples {
    1.40 +
    1.41 +inline bool operator==(const null_type&, const null_type&) { return true; }
    1.42 +inline bool operator>=(const null_type&, const null_type&) { return true; }
    1.43 +inline bool operator<=(const null_type&, const null_type&) { return true; }
    1.44 +inline bool operator!=(const null_type&, const null_type&) { return false; }
    1.45 +inline bool operator<(const null_type&, const null_type&) { return false; }
    1.46 +inline bool operator>(const null_type&, const null_type&) { return false; }
    1.47 +
    1.48 +
    1.49 +namespace detail {
    1.50 +  // comparison operators check statically the length of its operands and
    1.51 +  // delegate the comparing task to the following functions. Hence
    1.52 +  // the static check is only made once (should help the compiler).  
    1.53 +  // These functions assume tuples to be of the same length.
    1.54 +
    1.55 +
    1.56 +template<class T1, class T2>
    1.57 +inline bool eq(const T1& lhs, const T2& rhs) {
    1.58 +  return lhs.get_head() == rhs.get_head() &&
    1.59 +         eq(lhs.get_tail(), rhs.get_tail());
    1.60 +}
    1.61 +template<>
    1.62 +inline bool eq<null_type,null_type>(const null_type&, const null_type&) { return true; }
    1.63 +
    1.64 +template<class T1, class T2>
    1.65 +inline bool neq(const T1& lhs, const T2& rhs) {
    1.66 +  return lhs.get_head() != rhs.get_head()  ||
    1.67 +         neq(lhs.get_tail(), rhs.get_tail());
    1.68 +}
    1.69 +template<>
    1.70 +inline bool neq<null_type,null_type>(const null_type&, const null_type&) { return false; }
    1.71 +
    1.72 +template<class T1, class T2>
    1.73 +inline bool lt(const T1& lhs, const T2& rhs) {
    1.74 +  return lhs.get_head() < rhs.get_head()  ||
    1.75 +            !(rhs.get_head() < lhs.get_head()) &&
    1.76 +            lt(lhs.get_tail(), rhs.get_tail());
    1.77 +}
    1.78 +template<>
    1.79 +inline bool lt<null_type,null_type>(const null_type&, const null_type&) { return false; }
    1.80 +
    1.81 +template<class T1, class T2>
    1.82 +inline bool gt(const T1& lhs, const T2& rhs) {
    1.83 +  return lhs.get_head() > rhs.get_head()  ||
    1.84 +            !(rhs.get_head() > lhs.get_head()) &&
    1.85 +            gt(lhs.get_tail(), rhs.get_tail());
    1.86 +}
    1.87 +template<>
    1.88 +inline bool gt<null_type,null_type>(const null_type&, const null_type&) { return false; }
    1.89 +
    1.90 +template<class T1, class T2>
    1.91 +inline bool lte(const T1& lhs, const T2& rhs) {
    1.92 +  return lhs.get_head() <= rhs.get_head()  &&
    1.93 +          ( !(rhs.get_head() <= lhs.get_head()) ||
    1.94 +            lte(lhs.get_tail(), rhs.get_tail()));
    1.95 +}
    1.96 +template<>
    1.97 +inline bool lte<null_type,null_type>(const null_type&, const null_type&) { return true; }
    1.98 +
    1.99 +template<class T1, class T2>
   1.100 +inline bool gte(const T1& lhs, const T2& rhs) {
   1.101 +  return lhs.get_head() >= rhs.get_head()  &&
   1.102 +          ( !(rhs.get_head() >= lhs.get_head()) ||
   1.103 +            gte(lhs.get_tail(), rhs.get_tail()));
   1.104 +}
   1.105 +template<>
   1.106 +inline bool gte<null_type,null_type>(const null_type&, const null_type&) { return true; }
   1.107 +
   1.108 +} // end of namespace detail
   1.109 +
   1.110 +
   1.111 +// equal ----
   1.112 +
   1.113 +template<class T1, class T2, class S1, class S2>
   1.114 +inline bool operator==(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.115 +{
   1.116 +  // check that tuple lengths are equal
   1.117 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.118 +
   1.119 +  return  detail::eq(lhs, rhs);
   1.120 +}
   1.121 +
   1.122 +// not equal -----
   1.123 +
   1.124 +template<class T1, class T2, class S1, class S2>
   1.125 +inline bool operator!=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.126 +{
   1.127 +
   1.128 +  // check that tuple lengths are equal
   1.129 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.130 +
   1.131 +  return detail::neq(lhs, rhs);
   1.132 +}
   1.133 +
   1.134 +// <
   1.135 +template<class T1, class T2, class S1, class S2>
   1.136 +inline bool operator<(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.137 +{
   1.138 +  // check that tuple lengths are equal
   1.139 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.140 +
   1.141 +  return detail::lt(lhs, rhs);
   1.142 +}
   1.143 +
   1.144 +// >
   1.145 +template<class T1, class T2, class S1, class S2>
   1.146 +inline bool operator>(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.147 +{
   1.148 +  // check that tuple lengths are equal
   1.149 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.150 +
   1.151 +  return detail::gt(lhs, rhs);
   1.152 +}
   1.153 +
   1.154 +// <=
   1.155 +template<class T1, class T2, class S1, class S2>
   1.156 +inline bool operator<=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.157 +{
   1.158 +  // check that tuple lengths are equal
   1.159 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.160 +
   1.161 +  return detail::lte(lhs, rhs);
   1.162 +}
   1.163 +
   1.164 +// >=
   1.165 +template<class T1, class T2, class S1, class S2>
   1.166 +inline bool operator>=(const cons<T1, T2>& lhs, const cons<S1, S2>& rhs)
   1.167 +{
   1.168 +  // check that tuple lengths are equal
   1.169 +  BOOST_STATIC_ASSERT(length<T2>::value == length<S2>::value);
   1.170 +
   1.171 +  return detail::gte(lhs, rhs);
   1.172 +}
   1.173 +
   1.174 +} // end of namespace tuples
   1.175 +} // end of namespace boost
   1.176 +
   1.177 +
   1.178 +#endif // BOOST_TUPLE_COMPARISON_HPP