From f7882b1ff21211693aa2ee6cb2b8c2144cba9975 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 14 Sep 2023 17:09:07 -0400 Subject: [PATCH] nestlog: + tag(), use to tidy ex3 --- example/ex3/ex3.cpp | 4 ++-- include/nestlog/tag.hpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/example/ex3/ex3.cpp b/example/ex3/ex3.cpp index 05a3c9e4..b4d1e9e1 100644 --- a/example/ex3/ex3.cpp +++ b/example/ex3/ex3.cpp @@ -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)); diff --git a/include/nestlog/tag.hpp b/include/nestlog/tag.hpp index 16a3e21a..7ac62023 100644 --- a/include/nestlog/tag.hpp +++ b/include/nestlog/tag.hpp @@ -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(n, ""); } /*xtag_pre*/ + template + tag_impl + tag(Name && n, Value && v) + { + return tag_impl(n, v); + } /*tag*/ + + template + tag_impl + tag(char const * n, Value && v) + { + return tag_impl(n, v); + } /*tag*/ + template inline std::ostream & operator<<(std::ostream &s,