template
struct Foo
{
std::tuple bars;
auto get_labels(const std::array& indices) const
{
// construct tuple from bar labels
return [&](std::index_sequence) {
return std::make_tuple(std::get(bars).get_label(indices[Is])...);
}(std::index_sequence_for{});
}
};
Пример Compiler Explorer
Есть ли относительно элегантный способ сделать это в C++17 или C++14? Или мне следует просто сделать C++20 обязательным требованием прямо сейчас?
Я начал использовать этот тип конструкции, который зависит от явных параметров шаблона C++20 для лямбда-выражений: [code]template struct Foo { std::tuple bars;
auto get_labels(const std::array& indices) const { // construct tuple from bar labels return [&](std::index_sequence) { return std::make_tuple(std::get(bars).get_label(indices[Is])...); }(std::index_sequence_for{}); } }; [/code] Пример Compiler Explorer Есть ли относительно элегантный способ сделать это в C++17 или C++14? Или мне следует просто сделать C++20 обязательным требованием прямо сейчас?