类型萃取与特化
输出类型名称
#include <cxxabi.h> std::cout<<abi::__cxa_demangle(typeid(Sum<std::vector<uint64_t> >).name(),NULL, NULL, NULL)<< std::endl;
函数模板变长参数
终止函数需要写在递归函数之前
void print() { return; } template <typename T, typename... Args> void print(T head, Args... rest) { std::cout << head << std::endl; print(rest...); }
复杂模板语法
//c++ template #include <iostream> #include <string> #include <typeinfo> using namespace std; template <typename... Elem> class EventQueue { public: EventQueue(); ~EventQueue(); void test(); template <typename... Args> void Func(); }; template <typename... Elem> EventQueue<Elem...>::EventQueue() { cout << __FUNCTION__ << endl; }; template <typename... Elem> void EventQueue<Elem...>::test() { cout << __FUNCTION__ << endl; } template <typename... Elem> EventQueue<Elem...>::~EventQueue() { cout << __FUNCTION__ << endl; } template <typename... Elem> template <typename... Args> void EventQueue<Elem...>::Func() { cout << __FUNCTION__ << endl; }//模版类中的模板函数 int main() { EventQueue<int, int, int> w; w.test(); w.Func<int, int, char, double*>(); return 0; }