#Iterating through a variadic template

6 messages · Page 1 of 1 (latest)

sullen epoch
#

I have a 2D array holding data, and want a function that can extract a certain number of columns of data at a specific index.

template<typename T, int... columns>
    void Data<T, columns...>::update(int index)
    {
        /*
        // Iterate through each column given in template parameter
        // Start at the least index and iterate to the highest index
        */
       
    }

Where T is the type of data in the given columns, and columns holds the indices of the columns I want to extract. index is the given row of data at which to extract data.
The reason I have the columns as a template parameter is because the Data class is responsible for always extracting data at the same columns, but at different rows.

How would this be possible?

velvet owlBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

sullen epoch
#

If not, I will probably just store the columns in a vector and extract from there

cosmic phoenix
#

I think this should work

for (int c : std::initializer_list<int> { columns... }) {
  
}
sullen epoch
#

awesome thanks!

#

!solved