mercredi 30 mars 2016

Using braces with parameter packs in c++11

I'm trying to determine the rules for passing a template argument as a parameter or single argument. Depending on how the brackets are specified seems to determine whether the ... is required when passing the templated type to std::forward.

void test(int)
{

}

template<class... Args>
void foobar(Args&&... args)
{
  test(std::forward<Args...>(args)...);
  test(std::forward<Args>(args)...);
  test(std::forward<Args...>((args)...));
  test(std::forward<Args>((args)...)); // doesn't compile
}

int main()
{
  int x = 5;
  foobar(x);
}  

clang gives the following when trying to compile error: parameter packs not expanded with ‘...’: test(std::forward((args)...));

Aucun commentaire:

Enregistrer un commentaire