Skip to content

Commit 37dbb23

Browse files
Merge pull request #5 from contour-terminal/minor-improvements
Put curly brackets around nested inspected values and provide formatter for StringLiteral
2 parents c6b5488 + 22f2dba commit 37dbb23

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
@@ -559,7 +559,9 @@ std::string Inspect(Object const& object)
559559
}
560560
else
561561
{
562+
str += '{';
562563
str += Inspect(arg);
564+
str += '}';
563565
}
564566
};
565567
if (!str.empty())
@@ -585,3 +587,12 @@ std::string Inspect(std::vector<Object> const& objects)
585587
return str;
586588
}
587589
} // namespace Reflection
590+
591+
template <std::size_t N>
592+
struct std::formatter<Reflection::StringLiteral<N>>: std::formatter<std::string_view>
593+
{
594+
auto format(Reflection::StringLiteral<N> const& value, auto& ctx) const
595+
{
596+
return formatter<std::string_view>::format(value.sv(), ctx);
597+
}
598+
};

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)