nestlog: + tag(), use to tidy ex3

This commit is contained in:
Roland Conybeare 2023-09-14 17:09:07 -04:00
commit f7882b1ff2
2 changed files with 18 additions and 2 deletions

View file

@ -6,13 +6,13 @@ using namespace xo;
int
fib(int n) {
scope log(XO_ENTER0(), xtag("n", n));
scope log(XO_ENTER0(), tag("n", n));
int retval = 1;
if (n >= 2) {
retval = fib(n - 1) + fib(n - 2);
log(xtag("n", n));
log(tag("n", n));
}
log.end_scope("<-", xtag("retval", retval));

View file

@ -25,6 +25,8 @@ namespace xo {
struct tag_impl {
tag_impl(Name const & n, Value const & v)
: name_{n}, value_{v} {}
tag_impl(Name && n, Value && v)
: name_{std::move(n)}, value_{std::move(v)} {}
Name const & name() const { return name_; }
Value const & value() const { return value_; }
@ -67,6 +69,20 @@ namespace xo {
return tag_impl<true, char const *, char const *>(n, "");
} /*xtag_pre*/
template<typename Name, typename Value>
tag_impl<false, Name, Value>
tag(Name && n, Value && v)
{
return tag_impl<false, Name, Value>(n, v);
} /*tag*/
template<typename Value>
tag_impl<false, char const *, Value>
tag(char const * n, Value && v)
{
return tag_impl<false, char const *, Value>(n, v);
} /*tag*/
template <bool PrefixSpace, typename Name, typename Value>
inline std::ostream &
operator<<(std::ostream &s,