ARTICLE AD BOX
std::initializer_list is baked into the language. If std::tuple had the same treatment, std::initializer_list would become "speacial" case for std::tuple where all types are the same.
I wanted to simplify some code that calls the same function with different set or params:
auto val = QueryRegString(HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot10"); /// work with val val = QueryRegString(HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot81"); /// work with val val = QueryRegString(HKEY_LOCAL_MACHINE, L"Microsoft SDKs\\Windows\\v7.1", L"InstallationFolder"); /// work with valI wanted to rewrite it like that:
const auto regs[] = { {HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot10"}, {HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot81"}, {HKEY_LOCAL_MACHINE, L"Microsoft SDKs\\Windows\\v7.1", L"InstallationFolder"}, }; for (const auto& reg : regs) { auto val = QueryRegString(std::get<0>(reg), std::get<1>(reg), std::get<2>(reg)); /// work with val }this, however, doesn't work, as auto cannot be used with arrays. But this works:
const auto regs = { std::make_tuple(HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot10"), std::make_tuple(HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot81"), std::make_tuple(HKEY_LOCAL_MACHINE, L"Microsoft SDKs\\Windows\\v7.1", L"InstallationFolder"), };this basically becomes initializer_list of tuples. If tuples were baked into the language similar to initializer list then we could simply write stuff like this:
const auto regs = { {HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot10"}, {HKEY_LOCAL_MACHINE, L"Windows Kits\\Installed Roots", L"KitsRoot81"}, {HKEY_LOCAL_MACHINE, L"Microsoft SDKs\\Windows\\v7.1", L"InstallationFolder"}, }; for (const auto& reg : regs) { auto val = QueryRegString(std::get<0>(reg), std::get<1>(reg), std::get<2>(reg)); /// work with val }or even even better make array of deduced tuples:
const auto regs[] = { ... };Is there anything in c++ standard considered for to make it work in the future?
