From 201672a0ad4305c7c51f21782f47edc0f9470526 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 29 Sep 2023 02:44:44 +0200 Subject: [PATCH] Library: reconsider join / stringify API - it is not directly possible to provide a variadic join(args...), due to overload resolution ambiguities - as a remedy, simplify the invocation of stringify() for the typical cases, and provide some frequently used shortcuts --- src/lib/format-util.hpp | 29 +++++++++- src/lib/test/event-log.hpp | 12 ++-- src/lib/thread.hpp | 2 +- tests/library/format-helper-test.cpp | 4 +- tests/stage/test/placeholder-command.hpp | 3 +- wiki/thinkPad.ichthyo.mm | 70 +++++++++++++++++++++++- 6 files changed, 105 insertions(+), 15 deletions(-) diff --git a/src/lib/format-util.hpp b/src/lib/format-util.hpp index 77940543d..b712181db 100644 --- a/src/lib/format-util.hpp +++ b/src/lib/format-util.hpp @@ -117,13 +117,21 @@ namespace util { */ template inline CON - stringify(ELMS const& ...elms) + collectStr(ELMS const& ...elms) { SeqContainer storage; do_stringify (storage, elms...); return CON {move(storage)}; } + /** standard setup: convert to string into a vector */ + template + inline vector + stringify (ELMS const& ...elms) + { + return collectStr> (elms...); + } + /** convert to string as transforming step in a pipeline * @param src a "Lumiera Forward Iterator" with arbitrary result type * @return a "Lumiera Forward Iterator" with string elements @@ -214,13 +222,30 @@ namespace util { return join (ili, delim); } + // Note: offering a variant of join with var-args would create lots of ambiguities /** shortcut: List in parentheses, separated by comma, using temporary vector */ template inline string joinArgList (ARGS const& ...args) { - return "("+join (stringify> (args...))+")"; + return "("+join (stringify (args...))+")"; + } + + /** shortcut: join directly with dashes */ + template + inline string + joinDash (ARGS const& ...args) + { + return join (stringify (args...), "-"); + } + + /** shortcut: join directly with dashes */ + template + inline string + joinDot (ARGS const& ...args) + { + return join (stringify (args...), "."); } diff --git a/src/lib/test/event-log.hpp b/src/lib/test/event-log.hpp index 52da8cf5f..447b4eb7f 100644 --- a/src/lib/test/event-log.hpp +++ b/src/lib/test/event-log.hpp @@ -102,7 +102,7 @@ namespace test{ using lib::Symbol; using std::string; - using util::stringify; + using util::collectStr; namespace { using Entry = lib::diff::Record; @@ -206,7 +206,7 @@ namespace test{ EventMatch& arg (ARGS const& ...args) { - refineSerach_matchArguments (stringify (args...)); + refineSerach_matchArguments (collectStr (args...)); return *this; } @@ -225,8 +225,8 @@ namespace test{ EventMatch& argMatch (ARGS const& ...regExps) { - refineSerach_matchArgsRegExp (stringify (regExps...), - util::join(stringify(regExps...))); + refineSerach_matchArgsRegExp (collectStr (regExps...), + util::join(collectStr(regExps...))); return *this; } @@ -380,7 +380,7 @@ namespace test{ EventLog& call (string target, string function, ARGS const& ...args) { - return call (target, function, stringify(args...)); + return call (target, function, collectStr(args...)); } /** Log a function call on given object ("`this`")... */ @@ -402,7 +402,7 @@ namespace test{ EventLog& note (ELMS const& ...initialiser) { - log_->emplace_back (stringify (initialiser...)); + log_->emplace_back (collectStr (initialiser...)); return *this; } diff --git a/src/lib/thread.hpp b/src/lib/thread.hpp index 6f3eebd17..592baf39c 100644 --- a/src/lib/thread.hpp +++ b/src/lib/thread.hpp @@ -305,7 +305,7 @@ namespace lib { template ThreadLifecycle (RES (SUB::*memFun) (ARGS...), ARGS&& ...args) - : ThreadLifecycle{util::joinArgList (lib::meta::typeStr(), args...) + : ThreadLifecycle{util::joinDash (lib::meta::typeStr(), args...) ,std::move (memFun) ,static_cast (this) ,std::forward (args)... } diff --git a/tests/library/format-helper-test.cpp b/tests/library/format-helper-test.cpp index f89777895..e69fdcd99 100644 --- a/tests/library/format-helper-test.cpp +++ b/tests/library/format-helper-test.cpp @@ -156,8 +156,8 @@ namespace test { using VecS = vector; - // another variant: collect arbitrary number of arguments - VecS vals = stringify (short(12), 345L, "67", '8'); + // another variant: collect arbitrary heterogeneous arguments + VecS vals = stringify (short(12), 345L, "67", '8'); CHECK (vals == VecS({"12", "345", "67", "8"})); diff --git a/tests/stage/test/placeholder-command.hpp b/tests/stage/test/placeholder-command.hpp index 55741f1b9..3bf53c0be 100644 --- a/tests/stage/test/placeholder-command.hpp +++ b/tests/stage/test/placeholder-command.hpp @@ -102,8 +102,7 @@ namespace test{ static string capture (ARGS ...args) { - using VecS = std::vector; - return "Memento⧏" + util::join (util::stringify (args...),"⧓") + "⧐"; + return "Memento⧏" + util::join (util::stringify (args...),"⧓") + "⧐"; } static void diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 7722990a1..2059bb43a 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -79395,11 +79395,77 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + + + + + + + + + +

+ es ergeben sich zwei Schwierigkeiten... +

+
    +
  • + eine Varargs-Variante würde die bestehenden Overloads kanibalisieren bzw. würde für 1-2 Argumente einen "ambiguous overload" provozieren +
  • +
  • + mit einer Varargs-Variante gibt es keine Möglichkeit, den Delimiter anzugeben +
  • +
+ +
+ +
+ + + + + + + + + + + + +

+ Er ist aus mehreren Gründen gut +

+
    +
  • + er ist bereits konventionell; im Besonderen in der C-Marko-Form (die Lumiera auch verwendet) +
  • +
  • + er teilt sich sprachlich gut mit +
  • +
+

+ Aber es ist ein sehr fester Name; er ermöglicht kaum Verkürzungen oder Varianten +

+ +
+
+ + + + + + + +