1+ /* ************************************************************************
2+ * *
3+ * Reflection Template Library (RTL) - Modern C++ Reflection Framework *
4+ * https://github.com/ReflectCxx/ReflectionTemplateLibrary-CPP *
5+ * *
6+ * Copyright (c) 2025 Neeraj Singh <[email protected] > * 7+ * SPDX-License-Identifier: MIT *
8+ * *
9+ *************************************************************************/
10+
11+
12+ #pragma once
13+
14+ #include " rtl_errors.h"
15+ #include " RObjectBuilder.hpp"
16+
17+ namespace rtl ::dispatch
18+ {
19+ template <class record_t >
20+ struct constructor_ptr
21+ {
22+ template <class ...args_t >
23+ static rtl::RObject create (args_t ...params)
24+ {
25+ if constexpr (sizeof ...(args_t ) == 0 && !std::is_default_constructible_v<record_t >)
26+ { // default constructor, private or deleted.
27+ return { error::TypeNotDefaultConstructible, RObject{} };
28+ }
29+ else
30+ {
31+ if (pAllocType == alloc::Stack) {
32+
33+ if constexpr (!std::is_copy_constructible_v<record_t >)
34+ {
35+ return {
36+ error::TypeNotCopyConstructible, RObject{}
37+ };
38+ }
39+ else
40+ {
41+ return {
42+ error::None,
43+ RObjectBuilder<record_t >::template
44+ build<alloc::Stack>(record_t (std::forward<_signature>(params)...), pClonerId, true )
45+ };
46+ }
47+ }
48+ else if (pAllocType == alloc::Heap)
49+ {
50+ return {
51+ error::None,
52+ RObjectBuilder<record_t *>::template
53+ build<alloc::Heap>(new record_t (std::forward<_signature>(params)...), pClonerId, true )
54+ };
55+ }
56+ }
57+ return { error::EmptyRObject, RObject{} }; // dead code. compiler warning omitted.
58+ }
59+ };
60+ }
0 commit comments