Last active
December 5, 2017 22:21
-
-
Save HalCanary/cda7cc92ae762a524690c3f6d212a96a to your computer and use it in GitHub Desktop.
std::string path_join(...);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
inline void path_join_append(std::ostringstream* o) { } | |
template<class... Types> | |
void path_join_append(std::ostringstream* o, const char* v, Types... args) { | |
constexpr char kPathSeparator[] = "/"; | |
*o << kPathSeparator << v; | |
path_join_append(o, args...); | |
} | |
template<class... Types> | |
std::string path_join(const char* value, Types... args) { | |
std::ostringstream o; | |
o << value; | |
path_join_append(&o, args...); | |
return o.str(); | |
} | |
int main() { | |
std::cout << path_join("A") << '\n'; | |
std::cout << path_join("A", "B") << '\n'; | |
std::cout << path_join("A", "B", "C") << '\n'; | |
std::cout << path_join("A", "B", "C", "D") << '\n'; | |
std::cout << path_join("A", "B", "C", "D", "E") << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment