2

I had a look at the source of <functional> in libstdc++ (g++ 4.7.1) and found the following code (l. 91 - 98):

/// Retrieve the result type for a function type.
template<typename _Res, typename... _ArgTypes>
struct _Weak_result_type_impl<_Res(_ArgTypes...)>    // (1)
{ typedef _Res result_type; };

template<typename _Res, typename... _ArgTypes>
struct _Weak_result_type_impl<_Res(_ArgTypes......)> // (2) line 97
{ typedef _Res result_type; };

While I recognize the usual pack expansion ... (1) [temp.variadic], I have no idea what ...... is.

What does ...... (2) mean in this context?

Follow-up question

In the following minimal example, what type would I need for TEST_PARAM_3 such that tester<TEST_PARAM_3>::value == 2?

#include <iostream>
#include <type_traits>
#include <iomanip>

template <typename Functor>
struct tester : std::integral_constant<int, 0>{};

template <typename Res, typename... Args>
struct tester<Res(Args...)> : std::integral_constant<int, 1>{};

template <typename Res, typename... Args>
struct tester<Res(Args......)> : std::integral_constant<int, 2>{};

#define STR_EXPAND(tok) #tok
#define STR(tok) STR_EXPAND(tok)
#define TEST_PARAM_1 void(*)(int, int)
#define TEST_PARAM_2 void(int, char, std::ostream&)
#define TEST_PARAM_3 void()

int main(){
    using std::setw;
    std::cout
    << setw(65)<< STR(TEST_PARAM_1) ": " << tester<TEST_PARAM_1>::value << "\n"
    << setw(65)<< STR(TEST_PARAM_2) ": " << tester<TEST_PARAM_2>::value << "\n"
    << setw(65)<< STR(TEST_PARAM_3) ": " << tester<TEST_PARAM_3>::value << "\n";
}
Zeta
  • 103,620
  • 13
  • 194
  • 236
  • [C11 variadic template arguments](http://lbrandy.com/blog/2013/02/c11s-six-dots/) –  Jun 12 '13 at 08:15
  • For your follow-up question: [`void(...)`](http://ideone.com/vU1ZSa) – gx_ Jun 12 '13 at 08:16
  • @Yuushi: Indeed. `......` doesn't seem to play well with the search function and search engines. – Zeta Jun 12 '13 at 08:16
  • @Zeta I just searched for `C++ "six dots"` in Google and it worked :P –  Jun 12 '13 at 08:16
  • @Zeta To be fair, it is definitely one of the stranger corners of C++. I stumbled upon that answer not too long ago, so it was relatively fresh in my memory... – Yuushi Jun 12 '13 at 08:19
  • @Yuushi But not so strange anymore if you consider `_ArgTypes...` as a "single" type, like `int`, then you can read `_Res(int...)` which reminds of a certain "`printf`" signature... (But yes, they could have inserted a space between the two `...` for readability...) – gx_ Jun 12 '13 at 08:24

1 Answers1

1

The the last ... is actually equivalent to , ....

Which makes the template parameter:

Res(Args..., ...)

Which means this is a variadic function, with a template variadic number of fixed arguments.

rubenvb
  • 74,642
  • 33
  • 187
  • 332