我查看了libstdc ++(g ++ 4.7.1)中<functional>
的来源,并找到了以下代码(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; };
虽然我认识到通常的包扩展...
(1)[temp.variadic],但我不知道......
是什么。
......
(2)在这种情况下的含义是什么?
在以下minimal example中,我TEST_PARAM_3
需要哪种类型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";
}
答案 0 :(得分:1)