epoc32/include/stdapis/boost/compressed_pair.hpp
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/stdapis/boost/detail/compressed_pair.hpp@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
//  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
williamr@2
     2
//  Use, modification and distribution are subject to the Boost Software License,
williamr@2
     3
//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
williamr@2
     4
//  http://www.boost.org/LICENSE_1_0.txt).
williamr@2
     5
//
williamr@2
     6
//  See http://www.boost.org/libs/utility for most recent version including documentation.
williamr@2
     7
williamr@2
     8
// compressed_pair: pair that "compresses" empty members
williamr@2
     9
// (see libs/utility/compressed_pair.htm)
williamr@2
    10
//
williamr@2
    11
// JM changes 25 Jan 2004:
williamr@2
    12
// For the case where T1 == T2 and both are empty, then first() and second()
williamr@2
    13
// should return different objects.
williamr@2
    14
// JM changes 25 Jan 2000:
williamr@2
    15
// Removed default arguments from compressed_pair_switch to get
williamr@2
    16
// C++ Builder 4 to accept them
williamr@2
    17
// rewriten swap to get gcc and C++ builder to compile.
williamr@2
    18
// added partial specialisations for case T1 == T2 to avoid duplicate constructor defs.
williamr@2
    19
williamr@2
    20
#ifndef BOOST_DETAIL_COMPRESSED_PAIR_HPP
williamr@2
    21
#define BOOST_DETAIL_COMPRESSED_PAIR_HPP
williamr@2
    22
williamr@2
    23
#include <algorithm>
williamr@2
    24
williamr@2
    25
#include <boost/type_traits/remove_cv.hpp>
williamr@2
    26
#include <boost/type_traits/is_empty.hpp>
williamr@2
    27
#include <boost/type_traits/is_same.hpp>
williamr@2
    28
#include <boost/call_traits.hpp>
williamr@2
    29
williamr@2
    30
#ifdef BOOST_MSVC
williamr@2
    31
# pragma warning(push)
williamr@2
    32
# pragma warning(disable:4512)
williamr@2
    33
#endif 
williamr@2
    34
namespace boost
williamr@2
    35
{
williamr@2
    36
williamr@2
    37
template <class T1, class T2>
williamr@2
    38
class compressed_pair;
williamr@2
    39
williamr@2
    40
williamr@2
    41
// compressed_pair
williamr@2
    42
williamr@2
    43
namespace details
williamr@2
    44
{
williamr@2
    45
   // JM altered 26 Jan 2000:
williamr@2
    46
   template <class T1, class T2, bool IsSame, bool FirstEmpty, bool SecondEmpty>
williamr@2
    47
   struct compressed_pair_switch;
williamr@2
    48
williamr@2
    49
   template <class T1, class T2>
williamr@2
    50
   struct compressed_pair_switch<T1, T2, false, false, false>
williamr@2
    51
      {static const int value = 0;};
williamr@2
    52
williamr@2
    53
   template <class T1, class T2>
williamr@2
    54
   struct compressed_pair_switch<T1, T2, false, true, true>
williamr@2
    55
      {static const int value = 3;};
williamr@2
    56
williamr@2
    57
   template <class T1, class T2>
williamr@2
    58
   struct compressed_pair_switch<T1, T2, false, true, false>
williamr@2
    59
      {static const int value = 1;};
williamr@2
    60
williamr@2
    61
   template <class T1, class T2>
williamr@2
    62
   struct compressed_pair_switch<T1, T2, false, false, true>
williamr@2
    63
      {static const int value = 2;};
williamr@2
    64
williamr@2
    65
   template <class T1, class T2>
williamr@2
    66
   struct compressed_pair_switch<T1, T2, true, true, true>
williamr@2
    67
      {static const int value = 4;};
williamr@2
    68
williamr@2
    69
   template <class T1, class T2>
williamr@2
    70
   struct compressed_pair_switch<T1, T2, true, false, false>
williamr@2
    71
      {static const int value = 5;};
williamr@2
    72
williamr@2
    73
   template <class T1, class T2, int Version> class compressed_pair_imp;
williamr@2
    74
williamr@2
    75
#ifdef __GNUC__
williamr@2
    76
   // workaround for GCC (JM):
williamr@2
    77
   using std::swap;
williamr@2
    78
#endif
williamr@2
    79
   //
williamr@2
    80
   // can't call unqualified swap from within classname::swap
williamr@2
    81
   // as Koenig lookup rules will find only the classname::swap
williamr@2
    82
   // member function not the global declaration, so use cp_swap
williamr@2
    83
   // as a forwarding function (JM):
williamr@2
    84
   template <typename T>
williamr@2
    85
   inline void cp_swap(T& t1, T& t2)
williamr@2
    86
   {
williamr@2
    87
#ifndef __GNUC__
williamr@2
    88
      using std::swap;
williamr@2
    89
#endif
williamr@2
    90
      swap(t1, t2);
williamr@2
    91
   }
williamr@2
    92
williamr@2
    93
   // 0    derive from neither
williamr@2
    94
williamr@2
    95
   template <class T1, class T2>
williamr@2
    96
   class compressed_pair_imp<T1, T2, 0>
williamr@2
    97
   {
williamr@2
    98
   public:
williamr@2
    99
      typedef T1                                                 first_type;
williamr@2
   100
      typedef T2                                                 second_type;
williamr@2
   101
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   102
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   103
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   104
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   105
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   106
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   107
williamr@2
   108
      compressed_pair_imp() {} 
williamr@2
   109
williamr@2
   110
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   111
         : first_(x), second_(y) {}
williamr@2
   112
williamr@2
   113
      compressed_pair_imp(first_param_type x)
williamr@2
   114
         : first_(x) {}
williamr@2
   115
williamr@2
   116
      compressed_pair_imp(second_param_type y)
williamr@2
   117
         : second_(y) {}
williamr@2
   118
williamr@2
   119
      first_reference       first()       {return first_;}
williamr@2
   120
      first_const_reference first() const {return first_;}
williamr@2
   121
williamr@2
   122
      second_reference       second()       {return second_;}
williamr@2
   123
      second_const_reference second() const {return second_;}
williamr@2
   124
williamr@2
   125
      void swap(::boost::compressed_pair<T1, T2>& y)
williamr@2
   126
      {
williamr@2
   127
         cp_swap(first_, y.first());
williamr@2
   128
         cp_swap(second_, y.second());
williamr@2
   129
      }
williamr@2
   130
   private:
williamr@2
   131
      first_type first_;
williamr@2
   132
      second_type second_;
williamr@2
   133
   };
williamr@2
   134
williamr@2
   135
   // 1    derive from T1
williamr@2
   136
williamr@2
   137
   template <class T1, class T2>
williamr@2
   138
   class compressed_pair_imp<T1, T2, 1>
williamr@2
   139
      : protected ::boost::remove_cv<T1>::type
williamr@2
   140
   {
williamr@2
   141
   public:
williamr@2
   142
      typedef T1                                                 first_type;
williamr@2
   143
      typedef T2                                                 second_type;
williamr@2
   144
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   145
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   146
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   147
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   148
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   149
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   150
williamr@2
   151
      compressed_pair_imp() {}
williamr@2
   152
williamr@2
   153
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   154
         : first_type(x), second_(y) {}
williamr@2
   155
williamr@2
   156
      compressed_pair_imp(first_param_type x)
williamr@2
   157
         : first_type(x) {}
williamr@2
   158
williamr@2
   159
      compressed_pair_imp(second_param_type y)
williamr@2
   160
         : second_(y) {}
williamr@2
   161
williamr@2
   162
      first_reference       first()       {return *this;}
williamr@2
   163
      first_const_reference first() const {return *this;}
williamr@2
   164
williamr@2
   165
      second_reference       second()       {return second_;}
williamr@2
   166
      second_const_reference second() const {return second_;}
williamr@2
   167
williamr@2
   168
      void swap(::boost::compressed_pair<T1,T2>& y)
williamr@2
   169
      {
williamr@2
   170
         // no need to swap empty base class:
williamr@2
   171
         cp_swap(second_, y.second());
williamr@2
   172
      }
williamr@2
   173
   private:
williamr@2
   174
      second_type second_;
williamr@2
   175
   };
williamr@2
   176
williamr@2
   177
   // 2    derive from T2
williamr@2
   178
williamr@2
   179
   template <class T1, class T2>
williamr@2
   180
   class compressed_pair_imp<T1, T2, 2>
williamr@2
   181
      : protected ::boost::remove_cv<T2>::type
williamr@2
   182
   {
williamr@2
   183
   public:
williamr@2
   184
      typedef T1                                                 first_type;
williamr@2
   185
      typedef T2                                                 second_type;
williamr@2
   186
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   187
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   188
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   189
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   190
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   191
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   192
williamr@2
   193
      compressed_pair_imp() {}
williamr@2
   194
williamr@2
   195
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   196
         : second_type(y), first_(x) {}
williamr@2
   197
williamr@2
   198
      compressed_pair_imp(first_param_type x)
williamr@2
   199
         : first_(x) {}
williamr@2
   200
williamr@2
   201
      compressed_pair_imp(second_param_type y)
williamr@2
   202
         : second_type(y) {}
williamr@2
   203
williamr@2
   204
      first_reference       first()       {return first_;}
williamr@2
   205
      first_const_reference first() const {return first_;}
williamr@2
   206
williamr@2
   207
      second_reference       second()       {return *this;}
williamr@2
   208
      second_const_reference second() const {return *this;}
williamr@2
   209
williamr@2
   210
      void swap(::boost::compressed_pair<T1,T2>& y)
williamr@2
   211
      {
williamr@2
   212
         // no need to swap empty base class:
williamr@2
   213
         cp_swap(first_, y.first());
williamr@2
   214
      }
williamr@2
   215
williamr@2
   216
   private:
williamr@2
   217
      first_type first_;
williamr@2
   218
   };
williamr@2
   219
williamr@2
   220
   // 3    derive from T1 and T2
williamr@2
   221
williamr@2
   222
   template <class T1, class T2>
williamr@2
   223
   class compressed_pair_imp<T1, T2, 3>
williamr@2
   224
      : protected ::boost::remove_cv<T1>::type,
williamr@2
   225
        protected ::boost::remove_cv<T2>::type
williamr@2
   226
   {
williamr@2
   227
   public:
williamr@2
   228
      typedef T1                                                 first_type;
williamr@2
   229
      typedef T2                                                 second_type;
williamr@2
   230
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   231
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   232
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   233
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   234
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   235
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   236
williamr@2
   237
      compressed_pair_imp() {}
williamr@2
   238
williamr@2
   239
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   240
         : first_type(x), second_type(y) {}
williamr@2
   241
williamr@2
   242
      compressed_pair_imp(first_param_type x)
williamr@2
   243
         : first_type(x) {}
williamr@2
   244
williamr@2
   245
      compressed_pair_imp(second_param_type y)
williamr@2
   246
         : second_type(y) {}
williamr@2
   247
williamr@2
   248
      first_reference       first()       {return *this;}
williamr@2
   249
      first_const_reference first() const {return *this;}
williamr@2
   250
williamr@2
   251
      second_reference       second()       {return *this;}
williamr@2
   252
      second_const_reference second() const {return *this;}
williamr@2
   253
      //
williamr@2
   254
      // no need to swap empty bases:
williamr@2
   255
      void swap(::boost::compressed_pair<T1,T2>&) {}
williamr@2
   256
   };
williamr@2
   257
williamr@2
   258
   // JM
williamr@2
   259
   // 4    T1 == T2, T1 and T2 both empty
williamr@2
   260
   //      Originally this did not store an instance of T2 at all
williamr@2
   261
   //      but that led to problems beause it meant &x.first() == &x.second()
williamr@2
   262
   //      which is not true for any other kind of pair, so now we store an instance
williamr@2
   263
   //      of T2 just in case the user is relying on first() and second() returning
williamr@2
   264
   //      different objects (albeit both empty).
williamr@2
   265
   template <class T1, class T2>
williamr@2
   266
   class compressed_pair_imp<T1, T2, 4>
williamr@2
   267
      : protected ::boost::remove_cv<T1>::type
williamr@2
   268
   {
williamr@2
   269
   public:
williamr@2
   270
      typedef T1                                                 first_type;
williamr@2
   271
      typedef T2                                                 second_type;
williamr@2
   272
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   273
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   274
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   275
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   276
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   277
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   278
williamr@2
   279
      compressed_pair_imp() {}
williamr@2
   280
williamr@2
   281
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   282
         : first_type(x), m_second(y) {}
williamr@2
   283
williamr@2
   284
      compressed_pair_imp(first_param_type x)
williamr@2
   285
         : first_type(x), m_second(x) {}
williamr@2
   286
williamr@2
   287
      first_reference       first()       {return *this;}
williamr@2
   288
      first_const_reference first() const {return *this;}
williamr@2
   289
williamr@2
   290
      second_reference       second()       {return m_second;}
williamr@2
   291
      second_const_reference second() const {return m_second;}
williamr@2
   292
williamr@2
   293
      void swap(::boost::compressed_pair<T1,T2>&) {}
williamr@2
   294
   private:
williamr@2
   295
      T2 m_second;
williamr@2
   296
   };
williamr@2
   297
williamr@2
   298
   // 5    T1 == T2 and are not empty:   //JM
williamr@2
   299
williamr@2
   300
   template <class T1, class T2>
williamr@2
   301
   class compressed_pair_imp<T1, T2, 5>
williamr@2
   302
   {
williamr@2
   303
   public:
williamr@2
   304
      typedef T1                                                 first_type;
williamr@2
   305
      typedef T2                                                 second_type;
williamr@2
   306
      typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   307
      typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   308
      typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   309
      typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   310
      typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   311
      typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   312
williamr@2
   313
      compressed_pair_imp() {}
williamr@2
   314
williamr@2
   315
      compressed_pair_imp(first_param_type x, second_param_type y)
williamr@2
   316
         : first_(x), second_(y) {}
williamr@2
   317
williamr@2
   318
      compressed_pair_imp(first_param_type x)
williamr@2
   319
         : first_(x), second_(x) {}
williamr@2
   320
williamr@2
   321
      first_reference       first()       {return first_;}
williamr@2
   322
      first_const_reference first() const {return first_;}
williamr@2
   323
williamr@2
   324
      second_reference       second()       {return second_;}
williamr@2
   325
      second_const_reference second() const {return second_;}
williamr@2
   326
williamr@2
   327
      void swap(::boost::compressed_pair<T1, T2>& y)
williamr@2
   328
      {
williamr@2
   329
         cp_swap(first_, y.first());
williamr@2
   330
         cp_swap(second_, y.second());
williamr@2
   331
      }
williamr@2
   332
   private:
williamr@2
   333
      first_type first_;
williamr@2
   334
      second_type second_;
williamr@2
   335
   };
williamr@2
   336
williamr@2
   337
}  // details
williamr@2
   338
williamr@2
   339
template <class T1, class T2>
williamr@2
   340
class compressed_pair
williamr@2
   341
   : private ::boost::details::compressed_pair_imp<T1, T2,
williamr@2
   342
             ::boost::details::compressed_pair_switch<
williamr@2
   343
                    T1,
williamr@2
   344
                    T2,
williamr@2
   345
                    ::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
williamr@2
   346
                    ::boost::is_empty<T1>::value,
williamr@2
   347
                    ::boost::is_empty<T2>::value>::value>
williamr@2
   348
{
williamr@2
   349
private:
williamr@2
   350
   typedef details::compressed_pair_imp<T1, T2,
williamr@2
   351
             ::boost::details::compressed_pair_switch<
williamr@2
   352
                    T1,
williamr@2
   353
                    T2,
williamr@2
   354
                    ::boost::is_same<typename remove_cv<T1>::type, typename remove_cv<T2>::type>::value,
williamr@2
   355
                    ::boost::is_empty<T1>::value,
williamr@2
   356
                    ::boost::is_empty<T2>::value>::value> base;
williamr@2
   357
public:
williamr@2
   358
   typedef T1                                                 first_type;
williamr@2
   359
   typedef T2                                                 second_type;
williamr@2
   360
   typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   361
   typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   362
   typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   363
   typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   364
   typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   365
   typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   366
williamr@2
   367
            compressed_pair() : base() {}
williamr@2
   368
            compressed_pair(first_param_type x, second_param_type y) : base(x, y) {}
williamr@2
   369
   explicit compressed_pair(first_param_type x) : base(x) {}
williamr@2
   370
   explicit compressed_pair(second_param_type y) : base(y) {}
williamr@2
   371
williamr@2
   372
   first_reference       first()       {return base::first();}
williamr@2
   373
   first_const_reference first() const {return base::first();}
williamr@2
   374
williamr@2
   375
   second_reference       second()       {return base::second();}
williamr@2
   376
   second_const_reference second() const {return base::second();}
williamr@2
   377
williamr@2
   378
   void swap(compressed_pair& y) { base::swap(y); }
williamr@2
   379
};
williamr@2
   380
williamr@2
   381
// JM
williamr@2
   382
// Partial specialisation for case where T1 == T2:
williamr@2
   383
//
williamr@2
   384
template <class T>
williamr@2
   385
class compressed_pair<T, T>
williamr@2
   386
   : private details::compressed_pair_imp<T, T,
williamr@2
   387
             ::boost::details::compressed_pair_switch<
williamr@2
   388
                    T,
williamr@2
   389
                    T,
williamr@2
   390
                    ::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
williamr@2
   391
                    ::boost::is_empty<T>::value,
williamr@2
   392
                    ::boost::is_empty<T>::value>::value>
williamr@2
   393
{
williamr@2
   394
private:
williamr@2
   395
   typedef details::compressed_pair_imp<T, T,
williamr@2
   396
             ::boost::details::compressed_pair_switch<
williamr@2
   397
                    T,
williamr@2
   398
                    T,
williamr@2
   399
                    ::boost::is_same<typename remove_cv<T>::type, typename remove_cv<T>::type>::value,
williamr@2
   400
                    ::boost::is_empty<T>::value,
williamr@2
   401
                    ::boost::is_empty<T>::value>::value> base;
williamr@2
   402
public:
williamr@2
   403
   typedef T                                                  first_type;
williamr@2
   404
   typedef T                                                  second_type;
williamr@2
   405
   typedef typename call_traits<first_type>::param_type       first_param_type;
williamr@2
   406
   typedef typename call_traits<second_type>::param_type      second_param_type;
williamr@2
   407
   typedef typename call_traits<first_type>::reference        first_reference;
williamr@2
   408
   typedef typename call_traits<second_type>::reference       second_reference;
williamr@2
   409
   typedef typename call_traits<first_type>::const_reference  first_const_reference;
williamr@2
   410
   typedef typename call_traits<second_type>::const_reference second_const_reference;
williamr@2
   411
williamr@2
   412
            compressed_pair() : base() {}
williamr@2
   413
            compressed_pair(first_param_type x, second_param_type y) : base(x, y) {}
williamr@2
   414
#if !(defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x530))
williamr@2
   415
   explicit 
williamr@2
   416
#endif
williamr@2
   417
      compressed_pair(first_param_type x) : base(x) {}
williamr@2
   418
williamr@2
   419
   first_reference       first()       {return base::first();}
williamr@2
   420
   first_const_reference first() const {return base::first();}
williamr@2
   421
williamr@2
   422
   second_reference       second()       {return base::second();}
williamr@2
   423
   second_const_reference second() const {return base::second();}
williamr@2
   424
williamr@2
   425
   void swap(::boost::compressed_pair<T,T>& y) { base::swap(y); }
williamr@2
   426
};
williamr@2
   427
williamr@2
   428
template <class T1, class T2>
williamr@2
   429
inline
williamr@2
   430
void
williamr@2
   431
swap(compressed_pair<T1, T2>& x, compressed_pair<T1, T2>& y)
williamr@2
   432
{
williamr@2
   433
   x.swap(y);
williamr@2
   434
}
williamr@2
   435
williamr@2
   436
} // boost
williamr@2
   437
williamr@2
   438
#ifdef BOOST_MSVC
williamr@2
   439
# pragma warning(pop)
williamr@2
   440
#endif 
williamr@2
   441
williamr@2
   442
#endif // BOOST_DETAIL_COMPRESSED_PAIR_HPP
williamr@2
   443