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