1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <string>
const std::string DelimiterArg = ",";
// Base case for template recursion, print with delimiters only
template <typename T>
void PrintDelimiters(std::string DelimiterArg, T arg) {
DelimiterArg = "";
std::cout << arg << "\n";
}
template <typename T, typename... Types>
void PrintDelimiters (std::string Delimiter, T FirstArg, Types... args) {
std::cout << FirstArg << Delimiter << " ";
PrintDelimiters( DelimiterArg, args...);
}
// Base case for template recursion, print with delimiters and begin / end tags
template <typename T>
void PrintDelimiters(std::string DelimiterArg,
std::string BeginTag,
std::string EndTag,
T arg)
{
DelimiterArg = "";
std::cout << BeginTag << arg << EndTag << "\n";
}
template <typename T, typename... Types>
void PrintDelimiters (std::string Delimiter,
std::string BeginTag,
std::string EndTag,
T FirstArg, Types... args
)
{
std::cout << BeginTag << FirstArg << EndTag << Delimiter << " ";
PrintDelimiters( DelimiterArg, BeginTag, EndTag, args...);
}
int main() {
//auto Fred = std::make_tuple("Fed Dagg", 2.0, 47);
PrintDelimiters(DelimiterArg, "Fred", "Dag", 2.0, 47);
const std::string BeginTag = "[ code]";
const std::string EndTag = "[/ code]";
PrintDelimiters(DelimiterArg, BeginTag, EndTag, "Fred", "Dag", 2.0, 47);
return 0;
}
|