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