From f041e974c641d1aa5220a846413d1e43b4d4d75e Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Thu, 13 Aug 2015 18:45:05 +0200 Subject: [PATCH] investigation: Segfault in GDB (III) narrow down involved parts... --- research/try.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/research/try.cpp b/research/try.cpp index 6ea46275b..c41cd09ff 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -36,7 +36,10 @@ */ #include "lib/test/test-helper.hpp" -#include "lib/format-util.hpp" +//#include "lib/format-util.hpp" +#include "lib/meta/trait.hpp" +#include "lib/itertools.hpp" +#include "lib/symbol.hpp" #include #include @@ -48,6 +51,46 @@ using std::cout; using std::endl; + namespace { // helper to build range iterator on demand + template + struct _RangeIter + { + using StlIter = typename CON::const_iterator; + + lib::RangeIter iter; + + _RangeIter(CON const& collection) + : iter(begin(collection), end(collection)) + { } + }; + + } + + +template +inline string +join (CON&& coll, string const& delim =", ") +{ + using Coll = typename lib::meta::Strip::Type; + using Val = typename Coll::value_type; + + std::function toString = [] (Val const& val) { return string(val); }; + + _RangeIter range(std::forward(coll)); + auto strings = lib::transformIterator(range.iter, toString); + + if (!strings) return ""; + + std::ostringstream buffer; + for (string const& elm : strings) + buffer << elm << delim; + + // chop off last delimiter + size_t len = buffer.str().length(); + ASSERT (len > delim.length()); + return buffer.str().substr(0, len - delim.length()); +} + int @@ -62,7 +105,7 @@ main (int, char**) crew.push_back("Crusher"); crew.push_back("La Forge"); - cout << "enterprise = " << util::join(crew)<