Question

How can I write method getValue? Is it possible? Please, help me.

template <typename... Args>
    class Base
    {
      private:
      std::tuple<Args...> v_tuple;

       public:
       /.../ getValue(const int a){
       return std::get<a>(v_tuple);
    }

    };
Was it helpful?

Solution

No, you can't because a would need to be a constexpr when passed to the function (and no, constructing a const int in the function body is not gonna help). You can use a template argument instead:

template<std::size_t I>
auto getValue() -> decltype(std::get<I>(v_tuple)) {
   return std::get<I>(v_tuple);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top