0

As part of learning to use templates I tried to do the following:

#include <iostream>

template< size_t ...A >
struct Test;

//base
template< size_t a >
struct Test< a >{
    template< size_t b >
    constexpr static void compare(){
        //Do something with a, b
        //static_assert( a==b, "" )
        std::cout << a << "==" << b << "? " << ((a==b) ? "yes":"no") << "\n";
    }
};

//recursion
template< size_t a, size_t ...A >
struct Test<a , A...> {
    template< size_t b, size_t ...B >
    constexpr static void compare(){
        //Do something with a, b
        //static_assert( a==b, "" )
        std::cout << a << "==" << b << "? " << ((a==b) ? "yes":"no") << "\n";

        //Compile error
        Test<A...>::compare<B...>();
    }
};

int main()
{
    Test< 2 >::compare< 2 >();

    Test< 2, 3 >::compare< 2, 1 >();   
}

In the hope of comparing two parameter packs. But I get the following compile error:

In static member function ‘static constexpr void Test<a, A ...>::compare()’:
error: expected ‘;’ before ‘...’ token
      |         Test<A...>::compare<B...>();
      |                              ^~~
      |                              ;
error: parameter packs not expanded with ‘...’:
      |         Test<A...>::compare<B...>();
      |                     ~~~~~~~^~   

Most sources online seem to deal with type parameters or with just one parameter pack. Simply googling the errors didn't yield much either.

Sam Coutteau
  • 111
  • 5

0 Answers0