Let's suppose I have a struct X and I want to fill out all fields depending on some conditions. I'd like to distinguish which parameter I want to pass to a function and based on provided parameters create and then return that object. I'm curious if I should use variadic templates in c++? Pseudo code.
#include <iostream>
using namespace std;
struct X
{
string a;
string b;
string c;
}
X generateTransaction(const string& e, const string& f, const string& g)
{
X one;
if (e)
one.a = e;
if (f)
one.b = f;
if (g)
one.c = g;
return one;
}
int main()
{
generateTransaction(e = "first");
generateTransaction(e = "abc", f = "second");
generateTransaction(g = "third");
generateTransaction(e = "test", g = "third");
generateTransaction("m", "n", "o");
return 0;
}