-2

I copied block on below from https://en.cppreference.com/w/cpp/language/type_alias

template<typename...>
using void_t = void;
template<typename T>
void_t<typename T::foo> f();
f<int>(); // error, int does not have a nested type foo

I dont understand some of lines of it such us:

template<typename...> why type of name not defined in parameter list?

and

void_t<typename T::foo> f(); why f() called instead declare?

What does it mean this part? void_t<typename T::foo>

Kad
  • 542
  • 1
  • 5
  • 18
  • 1
    Possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Joseph D. Jun 23 '18 at 01:32

2 Answers2

1
template<typename...>
using void_t = void;

is a template alias, typename... is for any number of type. resulting type is void.

template<typename T> void_t<typename T::foo> f();

is a function declaration. the return type is void_t<typename T::foo> so void but if T::foo is not a valid type, thanks to SFINAE, that overload is discarded.

Jarod42
  • 203,559
  • 14
  • 181
  • 302
0

why type of name not defined in parameter list?

The ellipsis could be in the template and/or the parameter list. The former is called variadic template and the latter is called variadic function. So what's the difference?

Variadic template allows you to pass in any number of types to the function whereas variadic function allows you to pass in any number of arguments into the function. You could use both of them if you want your function to take in any number of types and arguments.

why f() called instead declare?

f() is a function declaration. I guess it can indeed look confusing. Think of it as f(void) instead.

Nyque
  • 351
  • 3
  • 10