From dc46f68f6a2e7a4079c6ad1e1545705d379b9a51 Mon Sep 17 00:00:00 2001 From: Alexander Karatarakis Date: Mon, 28 Aug 2017 18:36:25 -0700 Subject: [PATCH] [Strings::join()] Modify to work for any container --- toolsrc/include/vcpkg_Strings.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/toolsrc/include/vcpkg_Strings.h b/toolsrc/include/vcpkg_Strings.h index 7cea636765..a7c6148d7c 100644 --- a/toolsrc/include/vcpkg_Strings.h +++ b/toolsrc/include/vcpkg_Strings.h @@ -65,20 +65,20 @@ namespace vcpkg::Strings template std::basic_string join(const CharType* delimiter, const Container& v, Transformer transformer) { - if (v.size() == 0) + const auto begin = v.begin(); + const auto end = v.end(); + + if (begin == end) { return std::basic_string(); } std::basic_string output; - const size_t size = v.size(); - - output.append(transformer(v[0])); - - for (size_t i = 1; i < size; ++i) + output.append(transformer(*begin)); + for (auto it = std::next(begin); it != end; ++it) { output.append(delimiter); - output.append(transformer(v[i])); + output.append(transformer(*it)); } return output; @@ -86,7 +86,7 @@ namespace vcpkg::Strings template std::basic_string join(const CharType* delimiter, const Container& v) { - using Element = decltype(v[0]); + using Element = decltype(*v.begin()); return join(delimiter, v, [](const Element& x) -> const Element& { return x; }); }