epoc32/include/stdapis/boost/detail/compressed_pair.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/detail/compressed_pair.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,443 @@
     1.4 +//  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
     1.5 +//  Use, modification and distribution are subject to the Boost Software License,
     1.6 +//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     1.7 +//  http://www.boost.org/LICENSE_1_0.txt).
     1.8 +//
     1.9 +//  See http://www.boost.org/libs/utility for most recent version including documentation.
    1.10 +
    1.11 +// compressed_pair: pair that "compresses" empty members
    1.12 +// (see libs/utility/compressed_pair.htm)
    1.13 +//
    1.14 +// JM changes 25 Jan 2004:
    1.15 +// For the case where T1 == T2 and both are empty, then first() and second()
    1.16 +// should return different objects.
    1.17 +// JM changes 25 Jan 2000:
    1.18 +// Removed default arguments from compressed_pair_switch to get
    1.19 +// C++ Builder 4 to accept them
    1.20 +// rewriten swap to get gcc and C++ builder to compile.
    1.21 +// added partial specialisations for case T1 == T2 to avoid duplicate constructor defs.
    1.22 +
    1.23 +#ifndef BOOST_DETAIL_COMPRESSED_PAIR_HPP
    1.24 +#define BOOST_DETAIL_COMPRESSED_PAIR_HPP
    1.25 +
    1.26 +#include <algorithm>
    1.27 +
    1.28 +#include <boost/type_traits/remove_cv.hpp>
    1.29 +#include <boost/type_traits/is_empty.hpp>
    1.30 +#include <boost/type_traits/is_same.hpp>
    1.31 +#include <boost/call_traits.hpp>
    1.32 +
    1.33 +#ifdef BOOST_MSVC
    1.34 +# pragma warning(push)
    1.35 +# pragma warning(disable:4512)
    1.36 +#endif 
    1.37 +namespace boost
    1.38 +{
    1.39 +
    1.40 +template <class T1, class T2>
    1.41 +class compressed_pair;
    1.42 +
    1.43 +
    1.44 +// compressed_pair
    1.45 +
    1.46 +namespace details
    1.47 +{
    1.48 +   // JM altered 26 Jan 2000:
    1.49 +   template <class T1, class T2, bool IsSame, bool FirstEmpty, bool SecondEmpty>
    1.50 +   struct compressed_pair_switch;
    1.51 +
    1.52 +   template <class T1, class T2>
    1.53 +   struct compressed_pair_switch<T1, T2, false, false, false>
    1.54 +      {static const int value = 0;};
    1.55 +
    1.56 +   template <class T1, class T2>
    1.57 +   struct compressed_pair_switch<T1, T2, false, true, true>
    1.58 +      {static const int value = 3;};
    1.59 +
    1.60 +   template <class T1, class T2>
    1.61 +   struct compressed_pair_switch<T1, T2, false, true, false>
    1.62 +      {static const int value = 1;};
    1.63 +
    1.64 +   template <class T1, class T2>
    1.65 +   struct compressed_pair_switch<T1, T2, false, false, true>
    1.66 +      {static const int value = 2;};
    1.67 +
    1.68 +   template <class T1, class T2>
    1.69 +   struct compressed_pair_switch<T1, T2, true, true, true>
    1.70 +      {static const int value = 4;};
    1.71 +
    1.72 +   template <class T1, class T2>
    1.73 +   struct compressed_pair_switch<T1, T2, true, false, false>
    1.74 +      {static const int value = 5;};
    1.75 +
    1.76 +   template <class T1, class T2, int Version> class compressed_pair_imp;
    1.77 +
    1.78 +#ifdef __GNUC__
    1.79 +   // workaround for GCC (JM):
    1.80 +   using std::swap;
    1.81 +#endif
    1.82 +   //
    1.83 +   // can't call unqualified swap from within classname::swap
    1.84 +   // as Koenig lookup rules will find only the classname::swap
    1.85 +   // member function not the global declaration, so use cp_swap
    1.86 +   // as a forwarding function (JM):
    1.87 +   template <typename T>
    1.88 +   inline void cp_swap(T& t1, T& t2)
    1.89 +   {
    1.90 +#ifndef __GNUC__
    1.91 +      using std::swap;
    1.92 +#endif
    1.93 +      swap(t1, t2);
    1.94 +   }
    1.95 +
    1.96 +   // 0    derive from neither
    1.97 +
    1.98 +   template <class T1, class T2>
    1.99 +   class compressed_pair_imp<T1, T2, 0>
   1.100 +   {
   1.101 +   public:
   1.102 +      typedef T1                                                 first_type;
   1.103 +      typedef T2                                                 second_type;
   1.104 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.105 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.106 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.107 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.108 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.109 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.110 +
   1.111 +      compressed_pair_imp() {} 
   1.112 +
   1.113 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.114 +         : first_(x), second_(y) {}
   1.115 +
   1.116 +      compressed_pair_imp(first_param_type x)
   1.117 +         : first_(x) {}
   1.118 +
   1.119 +      compressed_pair_imp(second_param_type y)
   1.120 +         : second_(y) {}
   1.121 +
   1.122 +      first_reference       first()       {return first_;}
   1.123 +      first_const_reference first() const {return first_;}
   1.124 +
   1.125 +      second_reference       second()       {return second_;}
   1.126 +      second_const_reference second() const {return second_;}
   1.127 +
   1.128 +      void swap(::boost::compressed_pair<T1, T2>& y)
   1.129 +      {
   1.130 +         cp_swap(first_, y.first());
   1.131 +         cp_swap(second_, y.second());
   1.132 +      }
   1.133 +   private:
   1.134 +      first_type first_;
   1.135 +      second_type second_;
   1.136 +   };
   1.137 +
   1.138 +   // 1    derive from T1
   1.139 +
   1.140 +   template <class T1, class T2>
   1.141 +   class compressed_pair_imp<T1, T2, 1>
   1.142 +      : protected ::boost::remove_cv<T1>::type
   1.143 +   {
   1.144 +   public:
   1.145 +      typedef T1                                                 first_type;
   1.146 +      typedef T2                                                 second_type;
   1.147 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.148 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.149 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.150 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.151 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.152 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.153 +
   1.154 +      compressed_pair_imp() {}
   1.155 +
   1.156 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.157 +         : first_type(x), second_(y) {}
   1.158 +
   1.159 +      compressed_pair_imp(first_param_type x)
   1.160 +         : first_type(x) {}
   1.161 +
   1.162 +      compressed_pair_imp(second_param_type y)
   1.163 +         : second_(y) {}
   1.164 +
   1.165 +      first_reference       first()       {return *this;}
   1.166 +      first_const_reference first() const {return *this;}
   1.167 +
   1.168 +      second_reference       second()       {return second_;}
   1.169 +      second_const_reference second() const {return second_;}
   1.170 +
   1.171 +      void swap(::boost::compressed_pair<T1,T2>& y)
   1.172 +      {
   1.173 +         // no need to swap empty base class:
   1.174 +         cp_swap(second_, y.second());
   1.175 +      }
   1.176 +   private:
   1.177 +      second_type second_;
   1.178 +   };
   1.179 +
   1.180 +   // 2    derive from T2
   1.181 +
   1.182 +   template <class T1, class T2>
   1.183 +   class compressed_pair_imp<T1, T2, 2>
   1.184 +      : protected ::boost::remove_cv<T2>::type
   1.185 +   {
   1.186 +   public:
   1.187 +      typedef T1                                                 first_type;
   1.188 +      typedef T2                                                 second_type;
   1.189 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.190 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.191 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.192 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.193 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.194 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.195 +
   1.196 +      compressed_pair_imp() {}
   1.197 +
   1.198 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.199 +         : second_type(y), first_(x) {}
   1.200 +
   1.201 +      compressed_pair_imp(first_param_type x)
   1.202 +         : first_(x) {}
   1.203 +
   1.204 +      compressed_pair_imp(second_param_type y)
   1.205 +         : second_type(y) {}
   1.206 +
   1.207 +      first_reference       first()       {return first_;}
   1.208 +      first_const_reference first() const {return first_;}
   1.209 +
   1.210 +      second_reference       second()       {return *this;}
   1.211 +      second_const_reference second() const {return *this;}
   1.212 +
   1.213 +      void swap(::boost::compressed_pair<T1,T2>& y)
   1.214 +      {
   1.215 +         // no need to swap empty base class:
   1.216 +         cp_swap(first_, y.first());
   1.217 +      }
   1.218 +
   1.219 +   private:
   1.220 +      first_type first_;
   1.221 +   };
   1.222 +
   1.223 +   // 3    derive from T1 and T2
   1.224 +
   1.225 +   template <class T1, class T2>
   1.226 +   class compressed_pair_imp<T1, T2, 3>
   1.227 +      : protected ::boost::remove_cv<T1>::type,
   1.228 +        protected ::boost::remove_cv<T2>::type
   1.229 +   {
   1.230 +   public:
   1.231 +      typedef T1                                                 first_type;
   1.232 +      typedef T2                                                 second_type;
   1.233 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.234 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.235 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.236 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.237 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.238 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.239 +
   1.240 +      compressed_pair_imp() {}
   1.241 +
   1.242 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.243 +         : first_type(x), second_type(y) {}
   1.244 +
   1.245 +      compressed_pair_imp(first_param_type x)
   1.246 +         : first_type(x) {}
   1.247 +
   1.248 +      compressed_pair_imp(second_param_type y)
   1.249 +         : second_type(y) {}
   1.250 +
   1.251 +      first_reference       first()       {return *this;}
   1.252 +      first_const_reference first() const {return *this;}
   1.253 +
   1.254 +      second_reference       second()       {return *this;}
   1.255 +      second_const_reference second() const {return *this;}
   1.256 +      //
   1.257 +      // no need to swap empty bases:
   1.258 +      void swap(::boost::compressed_pair<T1,T2>&) {}
   1.259 +   };
   1.260 +
   1.261 +   // JM
   1.262 +   // 4    T1 == T2, T1 and T2 both empty
   1.263 +   //      Originally this did not store an instance of T2 at all
   1.264 +   //      but that led to problems beause it meant &x.first() == &x.second()
   1.265 +   //      which is not true for any other kind of pair, so now we store an instance
   1.266 +   //      of T2 just in case the user is relying on first() and second() returning
   1.267 +   //      different objects (albeit both empty).
   1.268 +   template <class T1, class T2>
   1.269 +   class compressed_pair_imp<T1, T2, 4>
   1.270 +      : protected ::boost::remove_cv<T1>::type
   1.271 +   {
   1.272 +   public:
   1.273 +      typedef T1                                                 first_type;
   1.274 +      typedef T2                                                 second_type;
   1.275 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.276 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.277 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.278 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.279 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.280 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.281 +
   1.282 +      compressed_pair_imp() {}
   1.283 +
   1.284 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.285 +         : first_type(x), m_second(y) {}
   1.286 +
   1.287 +      compressed_pair_imp(first_param_type x)
   1.288 +         : first_type(x), m_second(x) {}
   1.289 +
   1.290 +      first_reference       first()       {return *this;}
   1.291 +      first_const_reference first() const {return *this;}
   1.292 +
   1.293 +      second_reference       second()       {return m_second;}
   1.294 +      second_const_reference second() const {return m_second;}
   1.295 +
   1.296 +      void swap(::boost::compressed_pair<T1,T2>&) {}
   1.297 +   private:
   1.298 +      T2 m_second;
   1.299 +   };
   1.300 +
   1.301 +   // 5    T1 == T2 and are not empty:   //JM
   1.302 +
   1.303 +   template <class T1, class T2>
   1.304 +   class compressed_pair_imp<T1, T2, 5>
   1.305 +   {
   1.306 +   public:
   1.307 +      typedef T1                                                 first_type;
   1.308 +      typedef T2                                                 second_type;
   1.309 +      typedef typename call_traits<first_type>::param_type       first_param_type;
   1.310 +      typedef typename call_traits<second_type>::param_type      second_param_type;
   1.311 +      typedef typename call_traits<first_type>::reference        first_reference;
   1.312 +      typedef typename call_traits<second_type>::reference       second_reference;
   1.313 +      typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.314 +      typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.315 +
   1.316 +      compressed_pair_imp() {}
   1.317 +
   1.318 +      compressed_pair_imp(first_param_type x, second_param_type y)
   1.319 +         : first_(x), second_(y) {}
   1.320 +
   1.321 +      compressed_pair_imp(first_param_type x)
   1.322 +         : first_(x), second_(x) {}
   1.323 +
   1.324 +      first_reference       first()       {return first_;}
   1.325 +      first_const_reference first() const {return first_;}
   1.326 +
   1.327 +      second_reference       second()       {return second_;}
   1.328 +      second_const_reference second() const {return second_;}
   1.329 +
   1.330 +      void swap(::boost::compressed_pair<T1, T2>& y)
   1.331 +      {
   1.332 +         cp_swap(first_, y.first());
   1.333 +         cp_swap(second_, y.second());
   1.334 +      }
   1.335 +   private:
   1.336 +      first_type first_;
   1.337 +      second_type second_;
   1.338 +   };
   1.339 +
   1.340 +}  // details
   1.341 +
   1.342 +template <class T1, class T2>
   1.343 +class compressed_pair
   1.344 +   : private ::boost::details::compressed_pair_imp<T1, T2,
   1.345 +             ::boost::details::compressed_pair_switch<
   1.346 +                    T1,
   1.347 +                    T2,
   1.348 +                    ::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
   1.349 +                    ::boost::is_empty<T1>::value,
   1.350 +                    ::boost::is_empty<T2>::value>::value>
   1.351 +{
   1.352 +private:
   1.353 +   typedef details::compressed_pair_imp<T1, T2,
   1.354 +             ::boost::details::compressed_pair_switch<
   1.355 +                    T1,
   1.356 +                    T2,
   1.357 +                    ::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
   1.358 +                    ::boost::is_empty<T1>::value,
   1.359 +                    ::boost::is_empty<T2>::value>::value> base;
   1.360 +public:
   1.361 +   typedef T1                                                 first_type;
   1.362 +   typedef T2                                                 second_type;
   1.363 +   typedef typename call_traits<first_type>::param_type       first_param_type;
   1.364 +   typedef typename call_traits<second_type>::param_type      second_param_type;
   1.365 +   typedef typename call_traits<first_type>::reference        first_reference;
   1.366 +   typedef typename call_traits<second_type>::reference       second_reference;
   1.367 +   typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.368 +   typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.369 +
   1.370 +            compressed_pair() : base() {}
   1.371 +            compressed_pair(first_param_type x, second_param_type y) : base(x, y) {}
   1.372 +   explicit compressed_pair(first_param_type x) : base(x) {}
   1.373 +   explicit compressed_pair(second_param_type y) : base(y) {}
   1.374 +
   1.375 +   first_reference       first()       {return base::first();}
   1.376 +   first_const_reference first() const {return base::first();}
   1.377 +
   1.378 +   second_reference       second()       {return base::second();}
   1.379 +   second_const_reference second() const {return base::second();}
   1.380 +
   1.381 +   void swap(compressed_pair& y) { base::swap(y); }
   1.382 +};
   1.383 +
   1.384 +// JM
   1.385 +// Partial specialisation for case where T1 == T2:
   1.386 +//
   1.387 +template <class T>
   1.388 +class compressed_pair<T, T>
   1.389 +   : private details::compressed_pair_imp<T, T,
   1.390 +             ::boost::details::compressed_pair_switch<
   1.391 +                    T,
   1.392 +                    T,
   1.393 +                    ::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
   1.394 +                    ::boost::is_empty<T>::value,
   1.395 +                    ::boost::is_empty<T>::value>::value>
   1.396 +{
   1.397 +private:
   1.398 +   typedef details::compressed_pair_imp<T, T,
   1.399 +             ::boost::details::compressed_pair_switch<
   1.400 +                    T,
   1.401 +                    T,
   1.402 +                    ::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
   1.403 +                    ::boost::is_empty<T>::value,
   1.404 +                    ::boost::is_empty<T>::value>::value> base;
   1.405 +public:
   1.406 +   typedef T                                                  first_type;
   1.407 +   typedef T                                                  second_type;
   1.408 +   typedef typename call_traits<first_type>::param_type       first_param_type;
   1.409 +   typedef typename call_traits<second_type>::param_type      second_param_type;
   1.410 +   typedef typename call_traits<first_type>::reference        first_reference;
   1.411 +   typedef typename call_traits<second_type>::reference       second_reference;
   1.412 +   typedef typename call_traits<first_type>::const_reference  first_const_reference;
   1.413 +   typedef typename call_traits<second_type>::const_reference second_const_reference;
   1.414 +
   1.415 +            compressed_pair() : base() {}
   1.416 +            compressed_pair(first_param_type x, second_param_type y) : base(x, y) {}
   1.417 +#if !(defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530))
   1.418 +   explicit 
   1.419 +#endif
   1.420 +      compressed_pair(first_param_type x) : base(x) {}
   1.421 +
   1.422 +   first_reference       first()       {return base::first();}
   1.423 +   first_const_reference first() const {return base::first();}
   1.424 +
   1.425 +   second_reference       second()       {return base::second();}
   1.426 +   second_const_reference second() const {return base::second();}
   1.427 +
   1.428 +   void swap(::boost::compressed_pair<T,T>& y) { base::swap(y); }
   1.429 +};
   1.430 +
   1.431 +template <class T1, class T2>
   1.432 +inline
   1.433 +void
   1.434 +swap(compressed_pair<T1, T2>& x, compressed_pair<T1, T2>& y)
   1.435 +{
   1.436 +   x.swap(y);
   1.437 +}
   1.438 +
   1.439 +} // boost
   1.440 +
   1.441 +#ifdef BOOST_MSVC
   1.442 +# pragma warning(pop)
   1.443 +#endif 
   1.444 +
   1.445 +#endif // BOOST_DETAIL_COMPRESSED_PAIR_HPP
   1.446 +