Skip to main content
added 101 characters in body
Source Link
Ted Lyngmo
  • 115.8k
  • 7
  • 80
  • 129

footup is a variable template and not an instance variable. You can't pass it around as-if it was an instance.

You could instantiate a variable with it and use that in the call to bar:

#include <iostream>
#include <tuple>

template <typename... Args>
std::tuple<Args...> footup;

template <class... Args>
void bar(std::tuple<Args...>& instance, Args&&... args) {
    instance = std::make_tuple(std::forward<Args>(args)...);
}

int main() {
    auto& instance = footup<int, int, int, int, int, int, int>;
    // or if you'd like a copy:
    // auto instance = footup<int, int, int, int, int, int, int>;

    bar(instance, 1, 2, 3, 4, 5, 6, 7);
    std::cout << std::get<0>(instance) << ' ' << std::get<1>(instance) << ' '
              << std::get<2>(instance) << '\n';
}

footup is a variable template and not an instance variable. You can't pass it around as-if it was an instance.

You could instantiate a variable with it and use that in the call to bar:

#include <iostream>
#include <tuple>

template <typename... Args>
std::tuple<Args...> footup;

template <class... Args>
void bar(std::tuple<Args...>& instance, Args&&... args) {
    instance = std::make_tuple(std::forward<Args>(args)...);
}

int main() {
    auto instance = footup<int, int, int, int, int, int, int>;

    bar(instance, 1, 2, 3, 4, 5, 6, 7);
    std::cout << std::get<0>(instance) << ' ' << std::get<1>(instance) << ' '
              << std::get<2>(instance) << '\n';
}

footup is a variable template and not an instance variable. You can't pass it around as-if it was an instance.

You could instantiate a variable with it and use that in the call to bar:

#include <iostream>
#include <tuple>

template <typename... Args>
std::tuple<Args...> footup;

template <class... Args>
void bar(std::tuple<Args...>& instance, Args&&... args) {
    instance = std::make_tuple(std::forward<Args>(args)...);
}

int main() {
    auto& instance = footup<int, int, int, int, int, int, int>;
    // or if you'd like a copy:
    // auto instance = footup<int, int, int, int, int, int, int>;

    bar(instance, 1, 2, 3, 4, 5, 6, 7);
    std::cout << std::get<0>(instance) << ' ' << std::get<1>(instance) << ' '
              << std::get<2>(instance) << '\n';
}
Source Link
Ted Lyngmo
  • 115.8k
  • 7
  • 80
  • 129

footup is a variable template and not an instance variable. You can't pass it around as-if it was an instance.

You could instantiate a variable with it and use that in the call to bar:

#include <iostream>
#include <tuple>

template <typename... Args>
std::tuple<Args...> footup;

template <class... Args>
void bar(std::tuple<Args...>& instance, Args&&... args) {
    instance = std::make_tuple(std::forward<Args>(args)...);
}

int main() {
    auto instance = footup<int, int, int, int, int, int, int>;

    bar(instance, 1, 2, 3, 4, 5, 6, 7);
    std::cout << std::get<0>(instance) << ' ' << std::get<1>(instance) << ' '
              << std::get<2>(instance) << '\n';
}