I am trying to create a way to directly expand multiple parameter packages. I created a function template<size_t X,typename F> auto sequenceFunc(F&& f) that calls the given function f with extended integer_sequence .
This works well for small functions such as:
template<typename T, size_t A,size_t B> vec<B,T> col(const mat<A,B,T>& a,const size_t& i){ return sequenceFunc<A>([&](auto... J) -> vec<B,T>{ return { a[J][i]... }; //expands to a[0][i], a[1][i], ... a[A-1][i] }); }
Unfortunately, I cannot extend several parameter packages, even if I follow the rule that only one parameter package can be inside an expression ... This is my attempt to use this function for matrix multiplication:
template<typename S,typename T, size_t A,size_t B,size_t C> mat<C,B,S> mul(const mat<A,B,S>& a,const mat<C,A,T>& b){ return sequenceFunc<B>([&](auto... I)->mat<C,B,S>{ //for all B rows in a... return { sequenceFunc<C>([&](auto... J)->vec<C,S>{ // ... look at all C columns in b and calculate dot product. auto i = I; //putting "I" outside the expansion of "J" return { dot(row(a,i),col(b,J))... //expands J }; })... //expands I }; }); }
This is mistake:
error: parameter packs not expanded with '...': auto i = I; ^
I do not understand why the extension is necessary, because beyond the expression there is still ... I am using GCC 5.1.0.
The vec and mat info is just using -declarations for std::array and nested std::array<std::array<A,T>,B>