Skip to content

Commit a62e214

Browse files
First improvements
Signed-off-by: Christian Parpart <[email protected]>
1 parent 9230d97 commit a62e214

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

.vimspector.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://puremourning.github.io/vimspector/schema/vimspector.schema.json#",
3+
"configurations": {
4+
"test-clang": {
5+
"adapter": "vscode-cpptools",
6+
"configuration": {
7+
"request": "launch",
8+
"program": "${workspaceRoot}/out/build/linux-clang-debug/test-reflection-cpp",
9+
"args": [
10+
],
11+
"cwd": "${workspaceRoot}",
12+
"externalConsole": true,
13+
"stopAtEntry": false,
14+
"MIMode": "gdb"
15+
},
16+
"breakpoints": {
17+
"exception": {
18+
"caught": "Y",
19+
"uncaught": "Y"
20+
}
21+
}
22+
}
23+
}
24+
}

include/reflection-cpp/Reflection.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,9 @@ consteval auto GetName()
383383
return str.substr(0, str.find('>'));
384384
#else
385385
std::string_view str = REFLECTION_PRETTY_FUNCTION;
386-
str = str.substr(str.rfind("::") + 2);
387-
return str.substr(0, str.find(']'));
386+
str = str.substr(str.rfind("::") + 2 + 15);
387+
str = str.substr(0, str.find(']'));
388+
return str;
388389
#endif
389390
}
390391

test-reflection-cpp.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,29 @@ std::string inspect(Object const& object)
2828
}(std::make_index_sequence<Reflection::CountMembers<Object>> {});
2929
}
3030

31+
enum Color
32+
{
33+
Red,
34+
Green,
35+
Blue
36+
};
37+
38+
TEST_CASE("GetName", "[reflection]")
39+
{
40+
auto const enumValue = Reflection::GetName<Color::Red>();
41+
CHECK(enumValue == "Red");
42+
43+
auto const enumValue2 = Reflection::GetName<Color::Green>();
44+
CHECK(enumValue2 == "Green");
45+
46+
auto const person = Person { "John Doe", "[email protected]", 42 };
47+
auto const memberName1 = Reflection::GetName<&Person::email>();
48+
CHECK(memberName1 == "email");
49+
}
50+
3151
TEST_CASE("core", "[reflection]")
3252
{
33-
auto p = Person { "John Doe", "jon@doe.com", 42 };
53+
auto p = Person { "John Doe", "john@doe.com", 42 };
3454
std::cout << "Elements: " << Reflection::CountMembers<Person> << '\n';
3555
std::cout << inspect(p);
3656

0 commit comments

Comments
 (0)