除了問題是什麼標準說什麼編譯器應該能夠做到,這裏的一些TMP,使其在編譯GCC:
/** PackDiff:
* Template Metafunction to deduce the difference of two parameter packs.
* To distinguish two packs we have to brace them in two tuples
*/
template <class Tup1, class Tup2> struct PackDiff;
/** Basic algorithm: (T, X1...) - (T, X2...) = (X1...) - (X2...) */
template <class T, class... Pack1, class... Pack2>
struct PackDiff<std::tuple<T, Pack1...>, std::tuple<T, Pack2...>>
: PackDiff<std::tuple<Pack1...>, std::tuple<Pack2...>> {};
/** End of recursion: (X1...) -() = (X1...) */
template <class... Pack1>
struct PackDiff<std::tuple<Pack1...>, std::tuple<>>
{
typedef std::tuple<Pack1...> type;
};
/** Mismatch: (T, X1...) - (U, X2...) is undefined */
template <class T1, class... Pack1, class T2, class... Pack2>
struct PackDiff<std::tuple<T1, Pack1...>, std::tuple<T2, Pack2...>>
{ typedef struct PACK_MISMATCH {} type; };
/** Rest:() - (X2...) is undefined */
template <class... Pack2>
struct PackDiff<std::tuple<>, std::tuple<Pack2...>>
{ typedef struct LEFT_PACK_TOO_SHORT{} type; };
//make Runnable Type of T and a diff tuple:
template <class T, class Tup1> struct MakeRunnableType;
template <class T, class... Pack>
struct MakeRunnableType<T, std::tuple<Pack...>>
{ typedef Runnable<T, Pack...> type; };
template<typename... AllArgs, typename T, typename... SomeArgs>
auto makeRunnable(T (*FunctionType)(AllArgs...), SomeArgs... ct_args)
-> typename MakeRunnableType<T,
typename PackDiff<std::tuple<AllArgs...>,
std::tuple<SomeArgs...>
>::type
>::type*
{
typedef typename PackDiff<std::tuple<AllArgs...>,
std::tuple<SomeArgs...>
>::type PackDiff_t;
typedef typename MakeRunnableType<T, PackDiff_t>::type ReturnType;
return new ReturnType();
}
我知道。看起來不漂亮。但是works on GCC.
我不能真正地讓你的問題的頭或尾,但是std :: bind有什麼問題? – 111111 2013-03-07 14:02:52
沒有什麼,除了我試圖發展我自己的系統,並且我遇到了這個問題。 – Skeen 2013-03-07 14:06:35
@Ali:你的意思是'吸收',因爲我也想爲我的操作系統內核做一個小的工作實現。 – Skeen 2013-03-07 14:40:43