'How to pass a name for convenient use of tuple?

I would like to improve the code so that it is convenient to interact with it.

struct prototype {
  template <class... T1>
  prototype(T1&&... args) {
    auto p = std::tie(args...);

    std::cout << std::get<0>(p) << std::endl;

    if constexpr(std::tuple_size_v<decltype(p)> >= 3) {
      std::cout << std::get<2>(p) << std::endl;
    }
  }
};

int option_1 = 10;
std::string option_2 = "test2";
auto option_3 = 0.41;
std::vector<int> option_4(10);

int main() {
  prototype p1(option_1, option_2, option_3, option_4);
  prototype p2(option_1, option_2, option_3);
  prototype p3(option_1, option_2);
  prototype p4(option_1);
}

i would like to do so

std::cout << option_1 << std::endl;

if constexpr (std::tuple_size_v<decltype(p)> >= 3) {
   std::cout << option_2 << std::endl;
}

I don't like this option std::get<0>(p)

Any ideas how to replace the call to tuple?

You can also see the option on https://godbolt.org/z/bT4Wzjco8



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source