Skip to content

Instantly share code, notes, and snippets.

@RauliL
Created August 30, 2021 16:13
Show Gist options
  • Save RauliL/54f7c8b5cf20c12b248159442e48b609 to your computer and use it in GitHub Desktop.
Save RauliL/54f7c8b5cf20c12b248159442e48b609 to your computer and use it in GitHub Desktop.
#include <initializer_list>
#include <string>
std::string JoinPath(const std::initializer_list<std::string>& parts)
{
#if defined(_WIN32)
static const char separator = '\\';
#else
static const char separator = '/';
#endif
std::string result;
for (const auto& part : parts)
{
if (!result.empty() && result[result.length() - 1] != separator)
{
result.append(1, separator);
}
result.append(part);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment