I am looking for a solution with templates which allows me to pass values as template parameters just like its done by specializing templates with particular data types. For ex.
template <std::string... Args>
struct MOptional
{
MOptional()
{
possibilities.push_back(std::forward(Args)...);
}
std::vector<std::string> possibilities;
};
The way I want to use it is something like this.
MOptional<"string1", "string2", "string3"> optional;
and so the possibilities field in the class should get auto populated with string1,string2 and string3. I know I could do it with a constructor but I am looking for something like the above. I would like the number of strings to be variable.
Obviously this code doesn't compile but just to convey how I want it...
Any Ideas ?
Aucun commentaire:
Enregistrer un commentaire