Skip to content

Commit 975891d

Browse files
committed
new constructor api- wip.
1 parent d710333 commit 975891d

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

ReflectionTemplateLib/rtl/dispatch/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ set(LOCAL_HEADERS
66
"${CMAKE_CURRENT_SOURCE_DIR}/functor.h"
77

88
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr.h"
9-
"${CMAKE_CURRENT_SOURCE_DIR}/function_ptr.h"
9+
"${CMAKE_CURRENT_SOURCE_DIR}/function_ptr.h"
10+
"${CMAKE_CURRENT_SOURCE_DIR}/constructor_ptr.h"
1011
"${CMAKE_CURRENT_SOURCE_DIR}/method_ptr_const.h"
1112

1213
"${CMAKE_CURRENT_SOURCE_DIR}/lambda_base.h"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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

Comments
 (0)