epoc32/include/tools/stlport/stl/_move_construct_fwk.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000 (2010-03-16)
branchSymbian2
changeset 2 2fe1408b6811
permissions -rw-r--r--
Final list of Symbian^2 public API header files
williamr@2
     1
/*
williamr@2
     2
 *
williamr@2
     3
 * Copyright (c) 2003
williamr@2
     4
 * François Dumont
williamr@2
     5
 *
williamr@2
     6
 * This material is provided "as is", with absolutely no warranty expressed
williamr@2
     7
 * or implied. Any use is at your own risk.
williamr@2
     8
 *
williamr@2
     9
 * Permission to use or copy this software for any purpose is hereby granted
williamr@2
    10
 * without fee, provided the above notices are retained on all copies.
williamr@2
    11
 * Permission to modify the code and to distribute modified code is granted,
williamr@2
    12
 * provided the above notices are retained, and a notice that the code was
williamr@2
    13
 * modified is included with the above copyright notice.
williamr@2
    14
 *
williamr@2
    15
 */
williamr@2
    16
williamr@2
    17
#ifndef _STLP_MOVE_CONSTRUCT_FWK_H
williamr@2
    18
#define _STLP_MOVE_CONSTRUCT_FWK_H
williamr@2
    19
williamr@2
    20
#ifndef _STLP_TYPE_TRAITS_H
williamr@2
    21
#  include <stl/type_traits.h>
williamr@2
    22
#endif
williamr@2
    23
williamr@2
    24
_STLP_BEGIN_NAMESPACE
williamr@2
    25
williamr@2
    26
/*************************************************************
williamr@2
    27
 * Move constructor framework
williamr@2
    28
 *************************************************************/
williamr@2
    29
williamr@2
    30
/*************************************************************
williamr@2
    31
 *Partial move:
williamr@2
    32
 *The source HAS to be a valid instance after the move!
williamr@2
    33
 *************************************************************/
williamr@2
    34
template <class _Tp>
williamr@2
    35
class __move_source {
williamr@2
    36
public:
williamr@2
    37
  explicit __move_source (_Tp &_src) : _M_data(_src)
williamr@2
    38
  {}
williamr@2
    39
williamr@2
    40
  _Tp& get() const
williamr@2
    41
  { return _M_data; }
williamr@2
    42
private:
williamr@2
    43
  _Tp &_M_data;
williamr@2
    44
williamr@2
    45
  //We explicitely forbid assignment to avoid warning:
williamr@2
    46
  typedef __move_source<_Tp> _Self;
williamr@2
    47
  _Self& operator = (_Self const&);
williamr@2
    48
};
williamr@2
    49
williamr@2
    50
//Class used to signal move constructor support, implementation and type.
williamr@2
    51
template <class _Tp>
williamr@2
    52
struct __move_traits {
williamr@2
    53
  /*
williamr@2
    54
   * implemented tells if a the special move constructor has to be called or the classic
williamr@2
    55
   * copy constructor is just fine. Most of the time the copy constructor is fine only
williamr@2
    56
   * if the following info is true.
williamr@2
    57
   */
williamr@2
    58
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && \
williamr@2
    59
   !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && \
williamr@2
    60
   !defined (_STLP_NO_MOVE_SEMANTIC)
williamr@2
    61
  typedef typename _IsSTLportClass<_Tp>::_Ret implemented;
williamr@2
    62
#else
williamr@2
    63
  typedef __false_type implemented;
williamr@2
    64
#endif
williamr@2
    65
  /*
williamr@2
    66
   * complete tells if the move is complete or partial, that is to say, does the source
williamr@2
    67
   * needs to be destroyed once it has been moved.
williamr@2
    68
   */
williamr@2
    69
  typedef typename __type_traits<_Tp>::has_trivial_destructor complete;
williamr@2
    70
};
williamr@2
    71
williamr@2
    72
#if !defined (_STLP_NO_MOVE_SEMANTIC)
williamr@2
    73
typedef __true_type __stlp_movable;
williamr@2
    74
#else
williamr@2
    75
typedef __false_type __stlp_movable;
williamr@2
    76
#endif
williamr@2
    77
williamr@2
    78
_STLP_MOVE_TO_PRIV_NAMESPACE
williamr@2
    79
williamr@2
    80
/*
williamr@2
    81
 * This struct should never be used if the user has not explicitely stipulated
williamr@2
    82
 * that its class support the full move concept. To check that the return type
williamr@2
    83
 * in such a case will be __invalid_source<_Tp> to generate a compile error
williamr@2
    84
 * revealing the configuration problem.
williamr@2
    85
 */
williamr@2
    86
template <class _Tp>
williamr@2
    87
struct _MoveSourceTraits {
williamr@2
    88
  typedef typename __move_traits<_Tp>::implemented _MvImpRet;
williamr@2
    89
#if defined (__BORLANDC__)
williamr@2
    90
  typedef typename __selectT<_MvImpRet,
williamr@2
    91
#else
williamr@2
    92
  enum {_MvImp = __type2bool<_MvImpRet>::_Ret};
williamr@2
    93
  typedef typename __select<_MvImp,
williamr@2
    94
#endif
williamr@2
    95
                            __move_source<_Tp>,
williamr@2
    96
                            _Tp const&>::_Ret _Type;
williamr@2
    97
};
williamr@2
    98
williamr@2
    99
//The helper function
williamr@2
   100
template <class _Tp>
williamr@2
   101
inline _STLP_TYPENAME_ON_RETURN_TYPE _MoveSourceTraits<_Tp>::_Type
williamr@2
   102
_AsMoveSource (_Tp &src) {
williamr@2
   103
  typedef typename _MoveSourceTraits<_Tp>::_Type _SrcType;
williamr@2
   104
  return _SrcType(src);
williamr@2
   105
}
williamr@2
   106
williamr@2
   107
//Helper structs used for many class.
williamr@2
   108
template <class _Tp>
williamr@2
   109
struct __move_traits_aux {
williamr@2
   110
  typedef typename __move_traits<_Tp>::implemented implemented;
williamr@2
   111
  typedef typename __move_traits<_Tp>::complete complete;
williamr@2
   112
};
williamr@2
   113
williamr@2
   114
template <class _Tp1, class _Tp2>
williamr@2
   115
struct __move_traits_aux2 {
williamr@2
   116
  typedef __move_traits<_Tp1> _MoveTraits1;
williamr@2
   117
  typedef __move_traits<_Tp2> _MoveTraits2;
williamr@2
   118
williamr@2
   119
  typedef typename _Lor2<typename _MoveTraits1::implemented,
williamr@2
   120
                         typename _MoveTraits2::implemented>::_Ret implemented;
williamr@2
   121
  typedef typename _Land2<typename _MoveTraits1::complete,
williamr@2
   122
                          typename _MoveTraits2::complete>::_Ret complete;
williamr@2
   123
};
williamr@2
   124
williamr@2
   125
/*
williamr@2
   126
 * Most of the time a class implement a move constructor but its use depends
williamr@2
   127
 * on a third party, this is what the following struct are for.
williamr@2
   128
 */
williamr@2
   129
template <class _Tp>
williamr@2
   130
struct __move_traits_help {
williamr@2
   131
  typedef __true_type implemented;
williamr@2
   132
  typedef typename __move_traits<_Tp>::complete complete;
williamr@2
   133
};
williamr@2
   134
williamr@2
   135
template <class _Tp1, class _Tp2>
williamr@2
   136
struct __move_traits_help1 {
williamr@2
   137
  typedef __move_traits<_Tp1> _MoveTraits1;
williamr@2
   138
  typedef __move_traits<_Tp2> _MoveTraits2;
williamr@2
   139
williamr@2
   140
  typedef typename _Lor2<typename _MoveTraits1::implemented,
williamr@2
   141
                         typename _MoveTraits2::implemented>::_Ret implemented;
williamr@2
   142
  typedef typename _Land2<typename _MoveTraits1::complete,
williamr@2
   143
                          typename _MoveTraits2::complete>::_Ret complete;
williamr@2
   144
};
williamr@2
   145
williamr@2
   146
template <class _Tp1, class _Tp2>
williamr@2
   147
struct __move_traits_help2 {
williamr@2
   148
  typedef __move_traits<_Tp1> _MoveTraits1;
williamr@2
   149
  typedef __move_traits<_Tp2> _MoveTraits2;
williamr@2
   150
williamr@2
   151
  typedef __stlp_movable implemented;
williamr@2
   152
  typedef typename _Land2<typename _MoveTraits1::complete,
williamr@2
   153
                          typename _MoveTraits2::complete>::_Ret complete;
williamr@2
   154
};
williamr@2
   155
williamr@2
   156
_STLP_MOVE_TO_STD_NAMESPACE
williamr@2
   157
williamr@2
   158
_STLP_END_NAMESPACE
williamr@2
   159
williamr@2
   160
#endif /* _STLP_MOVE_CONSTRUCT_FWK_H */