一些元編程代碼開始:爲什麼類型推演失敗的(非指針到)函數類型
template<class... Ts>
class list {}; //a generic container for a list of types
template<class in_list_type>
class front //get the type of the first template parameter
{
template<template<class...> class in_list_less_template_type, class front_type, class... rest_types>
static front_type deduce_type(in_list_less_template_type<front_type, rest_types...>*);
public:
typedef decltype(deduce_type((in_list_type*)nullptr)) type;
};
此代碼工作正常此:
typedef typename front<list<int, float, char>>::type type; //type is int
但是編譯失敗時第一項是函數類型:
// no matching function for call to 'deduce_type'
typedef typename front<list<void(), float, char>>::type type;
我現在只能訪問XCode並且無法確認這是否是si mply一個XCode錯誤。我正在使用XCode 4.5.1,使用Apple LLVM編譯器4.1。
函數類型是否爲void(*)()? – imreal
@Nick這是指向函數類型的指針。 void()在C++中是一個奇怪的混蛋繼父類型,當你使用std :: function時,你可能會看到它。它基本上是你在取消引用函數指針時得到的類型。 –
Brent
@Brent C++不應該被使用。 :P(謝謝澄清,我不知道這件事。) – 2012-10-17 21:31:53