mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-29 00:19:00 +08:00
[Strings::join()] Modify to work for any container
This commit is contained in:
parent
174c264b44
commit
dc46f68f6a
@ -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; });
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user