X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fstlplus%2Fstrings%2Fstring_sequence.tpp;fp=src%2Fstlplus%2Fstrings%2Fstring_sequence.tpp;h=0bc522e355093fc1cf5bf6276696bbaf6f7c051c;hb=6b0a0d0efafe34d48ab344fca3b479553bd4e62c;hp=0000000000000000000000000000000000000000;hpb=85783316365181491a3e3c0c63659972477cebba;p=chaz%2Fyoink diff --git a/src/stlplus/strings/string_sequence.tpp b/src/stlplus/strings/string_sequence.tpp new file mode 100644 index 0000000..0bc522e --- /dev/null +++ b/src/stlplus/strings/string_sequence.tpp @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////////////////////////// + +// Author: Andy Rushton +// Copyright: (c) Southampton University 1999-2004 +// (c) Andy Rushton 2004-2009 +// License: BSD License, see ../docs/license.html + +//////////////////////////////////////////////////////////////////////////////// +#include "string_pair.hpp" + +namespace stlplus +{ + + //////////////////////////////////////////////////////////////////////////////// + // any forward iterator sequence + + template + std::string sequence_to_string(I begin, + I end, + S to_string, + const std::string& separator) + { + std::string result; + for (I i = begin; i != end; i++) + { + if (i != begin) result += separator; + result += to_string(*i); + } + return result; + } + + //////////////////////////////////////////////////////////////////////////////// + // any sequence where the value is a pair + + template + std::string pair_sequence_to_string(I begin, + I end, + S1 to_string_fn1, + S2 to_string_fn2, + const std::string& pair_separator, + const std::string& separator) + { + std::string result; + for (I i = begin; i != end; i++) + { + if (i != begin) result += separator; + result += pair_to_string(*i, to_string_fn1, to_string_fn2, pair_separator); + } + return result; + } + + //////////////////////////////////////////////////////////////////////////////// + +} // end namespace stlplus