@@ -49,11 +49,13 @@ namespace rtl::detail {
4949 {
5050 case alloc::Stack:
5151 return { error::None,
52- RObjectBuilder::template build<_T, alloc::Stack>(_T (srcObj), true ) };
52+ RObjectBuilder::template build<_T, alloc::Stack, true >(_T (srcObj))
53+ };
5354
5455 case alloc::Heap:
5556 return { error::None,
56- RObjectBuilder::template build<_T*, alloc::Heap>(new _T (srcObj), true ) };
57+ RObjectBuilder::template build<_T*, alloc::Heap, true >(new _T (srcObj))
58+ };
5759
5860 default :
5961 return { error::EmptyRObject, RObject{} };
@@ -72,26 +74,31 @@ namespace rtl::detail {
7274
7375
7476
75- template <class T , rtl::alloc _allocOn>
76- inline RObject RObjectBuilder::build (T&& pVal, const bool pIsConstCastSafe )
77+ template <class T , rtl::alloc _allocOn, bool _isConstCastSafe >
78+ inline RObject RObjectBuilder::build (T&& pVal)
7779 {
7880 using _T = traits::raw_t <T>;
7981 constexpr bool isRawPointer = std::is_pointer_v<traits::remove_const_n_ref_t <T>>;
8082
8183 if constexpr (_allocOn == alloc::Heap)
8284 {
8385 static_assert (isRawPointer, " Invalid 'alloc' specified for non-pointer-type 'T'" );
84- return RObject (RObjectId::create<std::unique_ptr<_T>, _allocOn>(pIsConstCastSafe),
85- std::any (RObjectUPtr<_T>(std::unique_ptr<_T>(static_cast <_T*>(pVal)))),
86+ return RObject (RObjectId::create<std::unique_ptr<_T>, _allocOn, _isConstCastSafe>(),
87+ std::any {
88+ std::in_place_type<RObjectUPtr<_T>>,
89+ RObjectUPtr<_T>(std::unique_ptr<_T>(static_cast <_T*>(pVal)))
90+ },
8691 buildCloner<_T>(),
8792 getConverters<std::unique_ptr<_T>>());
8893 }
8994 else if constexpr (_allocOn == alloc::Stack)
9095 {
9196 if constexpr (isRawPointer)
9297 {
93- return RObject (RObjectId::create<T, _allocOn>(pIsConstCastSafe),
94- std::any (static_cast <const _T*>(pVal)),
98+ return RObject (RObjectId::create<T, _allocOn, _isConstCastSafe>(),
99+ std::any {
100+ static_cast <const _T*>(pVal)
101+ },
95102 buildCloner<_T>(),
96103 getConverters<T>());
97104 }
@@ -100,16 +107,22 @@ namespace rtl::detail {
100107 if constexpr (traits::std_wrapper<_T>::type == Wrapper::Unique)
101108 {
102109 using U = traits::std_wrapper<_T>::value_type;
103- return RObject (RObjectId::create<T, _allocOn>(pIsConstCastSafe),
104- std::any (RObjectUPtr<U>(std::move (pVal))),
110+ return RObject (RObjectId::create<T, _allocOn, _isConstCastSafe>(),
111+ std::any {
112+ std::in_place_type<RObjectUPtr<U>>,
113+ RObjectUPtr<U>(std::move (pVal))
114+ },
105115 buildCloner<_T>(),
106116 getConverters<T>());
107117 }
108- else
118+ else
109119 {
110120 static_assert (std::is_copy_constructible_v<_T>, " T must be copy-constructible (std::any requires this)." );
111- return RObject (RObjectId::create<T, _allocOn>(pIsConstCastSafe),
112- std::any (std::forward<T>(pVal)),
121+ return RObject (RObjectId::create<T, _allocOn, _isConstCastSafe>(),
122+ std::any {
123+ std::in_place_type<T>,
124+ std::forward<T>(pVal)
125+ },
113126 buildCloner<_T>(),
114127 getConverters<T>());
115128 }
0 commit comments