Вариативный шаблон класса
Мне понадобилось создать вариативный класс принимающий список имен. У меня получилось следущее:
#include <MY/myTemplate.h>
#include <string>
#include <deque>
#include <map>
//^^^^^^^^^^^^^^^^^^^^^^^
enum class Names
{
one = 1,
two,
three
};
//***********************
std::map<Names, std::string> fNames{};
std::map<Names, std::string>::iterator f_Names{}, f_N{};
//***********************
template <typename... T>
class MyNames
{
int x{}, y{};
std::deque<std::string> name_str{};
public:
explicit MyNames() = default;
explicit MyNames(T &&...t)
{
x = sizeof...(T);
y = sizeof...(t);
printMy("%d - %d\n\n", x, y);
for (int i = 0; i < y; i++)
{
f_N = fNames.find((Names)(i + 1));
name_str.push_back(f_N->second);
printMy("%s\n", name_str.back());
}
}
};
//=======================
int main()
{
//fNames.emplace(Names::one, "one");
//fNames.emplace(Names::two, "two");
//fNames.emplace(Names::three, "three");
fNames[Names::one] = "one";
fNames[Names::two] = "two";
fNames[Names::three] = "three";
MyNames(Names::one, Names::two, Names::three);
}
/*
Output:
3 - 3
one
two
three
*/