Skip to content

Commit 22f2dba

Browse files
Put curly brackets around nested inspected values and provide formatter for StringLiteral
Signed-off-by: Christian Parpart <christian@parpart.family>
1 parent 9091dbd commit 22f2dba

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

include/reflection-cpp/reflection.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ std::string Inspect(Object const& object)
446446
}
447447
else
448448
{
449+
str += '{';
449450
str += Inspect(arg);
451+
str += '}';
450452
}
451453
};
452454
if (!str.empty())
@@ -472,3 +474,12 @@ std::string Inspect(std::vector<Object> const& objects)
472474
return str;
473475
}
474476
} // namespace Reflection
477+
478+
template <std::size_t N>
479+
struct std::formatter<Reflection::StringLiteral<N>>: std::formatter<std::string_view>
480+
{
481+
auto format(Reflection::StringLiteral<N> const& value, auto& ctx) const
482+
{
483+
return formatter<std::string_view>::format(value.sv(), ctx);
484+
}
485+
};

test-reflection-cpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ TEST_CASE("nested", "[reflection]")
6666
{
6767
auto ts = TestStruct { 1, 2.0f, 3.0, "hello", { "John Doe", "john@doe.com", 42 } };
6868
auto const result = Reflection::Inspect(ts);
69-
CHECK(result == R"(a=1 b=2 c=3 d="hello" e=name="John Doe" email="john@doe.com" age=42)");
69+
CHECK(result == R"(a=1 b=2 c=3 d="hello" e={name="John Doe" email="john@doe.com" age=42})");
7070
}

0 commit comments

Comments
 (0)