samedi 27 juin 2020

access and print data in a tuple and display it using a template function using C++14

i have a list like follows

my_mixed_list = {"Sample String", int_value, user_data_type}

I want to use C++11 std::tuple to display above list in simple white separated way. may be like this:

template <typename T>
    void display_mixed_items (std::tuple <T> mixed) {
         for (const auto& mixed_ele : mixed) std::cout << mixed_ele << " ";
}

I am aware that i would have to overload ostream operator to display the user defined data. But i hope you get the question. I'm not sure why compiler complains about argument list. what is proper way to accomplish above task. couldn't find exact answer on Stackoverflow so to mention.

in Python we could simple use list and tada! But if not tuple is there any other way to this may be using variadic templates or something.

Aucun commentaire:

Enregistrer un commentaire