29
29
* THE SOFTWARE.
30
30
*/
31
31
#include < typeindex>
32
+ #include < vector>
32
33
#include " add_ons.hpp"
33
34
#include " call_traits.hpp"
34
35
@@ -55,7 +56,7 @@ class any {
55
56
56
57
template <typename ValueType>
57
58
any (const ValueType &value)
58
- : content(new holder<ValueType>(value)) {
59
+ : content(new holder<typename std::remove_cvref< ValueType>::type >(value)) {
59
60
}
60
61
61
62
template <typename RET, typename ...ARG>
@@ -67,6 +68,20 @@ class any {
67
68
: content(other.content ? other.content->clone () : 0) {
68
69
}
69
70
71
+ // Move constructor
72
+ any (any &&other)
73
+ : content(other.content) {
74
+ other.content = 0 ;
75
+ }
76
+
77
+ // Perfect forwarding of ValueType
78
+ template <typename ValueType>
79
+ any (ValueType &&value
80
+ , typename std::enable_if<!std::is_same<any &, ValueType>::value>::type* = nullptr // disable if value has type `any&`
81
+ , typename std::enable_if<!std::is_const<ValueType>::value>::type* = nullptr ) // disable if value has type `const ValueType&&`
82
+ : content(new holder<typename std::remove_cvref<ValueType>::type>(static_cast <ValueType &&>(value))) {
83
+ }
84
+
70
85
~any () {
71
86
if (content != nullptr ) {
72
87
delete (content);
@@ -262,8 +277,8 @@ struct any_call_t<RET, std::tuple<NOCVR_ARG>, FUNC> {
262
277
: any_cast<any_arguemnt_type &>(arg));
263
278
if (args.size () < 1 )
264
279
throw bad_any_cast (arg.type (), typeid (nocvr_argument_type));
265
- // printf("[%s] [%s]\n", args[0] .type().name(), typeid(NOCVR_ARG).name());
266
- return func (any_cast<NOCVR_ARG &>(args[ 0 ] ));
280
+ // printf("[%s] [%s]\n", args.front() .type().name(), typeid(NOCVR_ARG).name());
281
+ return func (any_cast<NOCVR_ARG &>(args. front () ));
267
282
}
268
283
};
269
284
@@ -281,7 +296,7 @@ struct any_call_t<RET, std::tuple<any>, FUNC> {
281
296
return (func (empty));
282
297
}
283
298
else if (args.size () == 1 )
284
- return (func (args[ 0 ] ));
299
+ return (func (args. front () ));
285
300
else
286
301
return (func (const_cast <any &>(arg)));
287
302
}
0 commit comments