[Strings::join()] Modify to work for any container

This commit is contained in:
Alexander Karatarakis 2017-08-28 18:36:25 -07:00
parent 174c264b44
commit dc46f68f6a

View File

@ -65,20 +65,20 @@ namespace vcpkg::Strings
template<class Container, class Transformer, class CharType>
std::basic_string<CharType> 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<CharType>();
}
std::basic_string<CharType> 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<class Container, class CharType>
std::basic_string<CharType> 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; });
}