Skip to content

Commit cf7918f

Browse files
committed
Add template specialisation
1 parent 6c0facb commit cf7918f

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

include/reflection-cpp/reflection.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <tuple>
1010
#include <type_traits>
1111
#include <utility>
12+
#include <vector>
1213

1314
#if __has_include(<source_location>)
1415
#include <source_location>
@@ -459,4 +460,15 @@ std::string Inspect(Object const& object)
459460
return str;
460461
}
461462

463+
template <typename Object>
464+
std::string Inspect(std::vector<Object> const& objects)
465+
{
466+
std::string str;
467+
for (auto const& object: objects)
468+
{
469+
str += Inspect(object);
470+
str += '\n';
471+
}
472+
return str;
473+
}
462474
} // namespace Reflection

test-reflection-cpp.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ TEST_CASE("core", "[reflection]")
5050
CHECK(result == R"(name="John Doe" email="[email protected]" age=42)");
5151
}
5252

53+
TEST_CASE("vector", "[reflection]")
54+
{
55+
auto v = std::vector<Person> {};
56+
v.emplace_back("John Doe", "[email protected]", 42);
57+
v.emplace_back("John Doe", "[email protected]", 43);
58+
auto const result = Reflection::Inspect(v);
59+
CHECK(result == R"(name="John Doe" email="[email protected]" age=42
60+
name="John Doe" email="[email protected]" age=43
61+
)");
62+
//clang-format on
63+
}
64+
5365
TEST_CASE("nested", "[reflection]")
5466
{
5567
auto ts = TestStruct { 1, 2.0f, 3.0, "hello", { "John Doe", "[email protected]", 42 } };

0 commit comments

Comments
 (0)