You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**RTL** provides type-safe run-time reflection for modern C++ – combining compile-time guarantees with controlled run-time flexibility.
16
18
@@ -61,13 +63,13 @@ First, create an instance of `CxxMirror` –
61
63
auto cxx_mirror = rtl::CxxMirror({ /* ...register all types here... */ });
62
64
```
63
65
The `cxx_mirror` object provides access to the runtime reflection system. It enables querying, introspection, and instantiation of registered types without requiring compile-time type knowledge at the call site.
64
-
It can reside in any translation unit and is initialized on first use. To make it globally accessible in a controlled manner, a singleton interface can be used –
66
+
It can reside in any translation unit. To make it globally accessible in a controlled manner and ensure it is initialized only when needed, a singleton interface can be used –
65
67
```c++
66
68
// MyReflection.h
67
69
namespace rtl { class CxxMirror; } // Forward declaration, no includes here!
68
70
struct cxx { static rtl::CxxMirror& mirror(); }; // The Singleton.
69
71
```
70
-
define and register everything in an isolated translation unit,
72
+
define and register everything in an isolated translation unit –
@@ -100,28 +102,28 @@ if (!classPerson) { /* Class not registered. */ }
100
102
From `rtl::Record`, registered member functions can be queried as `rtl::Method`. These are metadata descriptors (not callables) and are returned as `std::optional`, which will be empty if the requested entity is not found.
101
103
102
104
Callables are materialized by explicitly providing the argument types we intend to pass. If the signature is valid, the resulting callable can be invoked safely.
103
-
For example, the overloaded constructor `Person(std::string, int)` -
105
+
For example, the overloaded constructor `Person(std::string, int)` –
Instances can be created on the `Heap` or `Stack` with automatic lifetime management:
114
+
Instances can be created on the `Heap` or `Stack` with automatic lifetime management –
113
115
```c++
114
116
auto [err, robj] = personCtor(rtl::alloc::Stack, "John", 42);
115
117
if (err != rtl::error::None) { std::cerr << rtl::to_string(err); } // Construction failed.
116
118
```
117
119
The constructed object is returned wrapped in `rtl::RObject`. Heap-allocated objects are internally managed via `std::unique_ptr`, while stack-allocated objects are stored directly in `std::any`.
The above `getName` invocation is effectively a native function-pointer hop, since all types are known at compile time.
137
139
138
-
If the concrete type `Person` is not accessible at the call site, its member functions can still be invoked by erasing the target type and using `rtl::RObject` instead. The previously constructed instance (`robj`) is passed as the target.
140
+
If the concrete type `Person` is not accessible at the call site, its member functions can still be invoked by erasing the target type and using `rtl::RObject` instead. The previously constructed instance (`robj`) is passed as the target –
@@ -160,31 +162,51 @@ At a high level, every registered C++ type is encapsulated as an `rtl::Record`.
160
162
161
163
RTL provides the following callable wrappers, designed to be as lightweight and performant as `std::function` (and in many micro-benchmarks, faster when fully type-aware):
`rtl::const_method<...>` – Const-qualified member functions
171
+
`rtl::const_method<>` – Const-qualified member functions
170
172
171
-
`rtl::static_method<...>` – Static member functions
173
+
`rtl::static_method<>` – Static member functions
172
174
173
175
These callable types are regular value types: they can be copied, moved, stored in standard containers, and passed around like any other lightweight object.
174
176
175
177
When invoked, only type-erased callables return an `rtl::error`, with results provided as `rtl::RObject` when both the return and target types are erased or as `std::optional<T>` when only the target type is erased, while fully type-aware callables return `T` directly with no error wrapper.
176
178
177
-
### Allocation and Lifetime Management
179
+
### How to Build (Windows / Linux)
180
+
```sh
181
+
mkdir build &&cd build
182
+
cmake -G "<Generator>"# Use a C++20-compatible compiler
183
+
cmake --build .
184
+
```
185
+
Run the generated binaries from `bin/`:
186
+
187
+
*`RTLTestRunApp` – Reflection tests and examples
188
+
*`RTLBenchmarkApp` – Performance benchmarks
189
+
190
+
Additional resources:
178
191
179
-
* Heap (`alloc::Heap`) – objects are owned by an internal `std::unique_ptr` and destroyed when their `rtl::RObject` wrapper goes out of scope.
Reflection Template Library (RTL) is an actively maintained, production-oriented C++ runtime reflection system focused on performance, type safety, and real-world usability.
184
200
185
-
* Return values – All returns are propagated back wrapped in `rtl::RObject`, cleaned up automatically at scope exit.
201
+
Sponsorship supports continued improvement of RTL’s core reflection capabilities, along with:
186
202
187
-
RTL doesn’t invent a new paradigm – it extends C++ itself. You create objects, call methods, and work with types as usual, but now safely at run-time.
203
+
* Production-ready examples
204
+
* Tooling and documentation
205
+
* Cross-platform CI and testing
206
+
207
+
If you’re interested in advancing practical runtime reflection in C++ and supporting the continued evolution of RTL’s core capabilities, consider sponsoring the project.
0 commit comments