您好,登錄后才能下訂單哦!
Clang3.6版本的Checker
一,Clang源碼如下:
template <typename CHECK1, typename CHECK2=check::_VoidCheck, typename CHECK3=check::_VoidCheck, typename CHECK4=check::_VoidCheck, typename CHECK5=check::_VoidCheck, typename CHECK6=check::_VoidCheck, typename CHECK7=check::_VoidCheck, typename CHECK8=check::_VoidCheck, typename CHECK9=check::_VoidCheck, typename CHECK10=check::_VoidCheck, typename CHECK11=check::_VoidCheck,typename CHECK12=check::_VoidCheck, typename CHECK13=check::_VoidCheck,typename CHECK14=check::_VoidCheck, typename CHECK15=check::_VoidCheck,typename CHECK16=check::_VoidCheck, typename CHECK17=check::_VoidCheck,typename CHECK18=check::_VoidCheck, typename CHECK19=check::_VoidCheck,typename CHECK20=check::_VoidCheck, typename CHECK21=check::_VoidCheck,typename CHECK22=check::_VoidCheck, typename CHECK23=check::_VoidCheck,typename CHECK24=check::_VoidCheck> class Checker; template <> class Checker<check::_VoidCheck> : public CheckerBase { virtual void anchor(); public: static void _register(void *checker, CheckerManager &mgr) { } }; template <typename CHECK1, typename CHECK2, typename CHECK3, typename CHECK4, typename CHECK5, typename CHECK6, typename CHECK7, typename CHECK8, typename CHECK9, typename CHECK10,typename CHECK11,typename CHECK12, typename CHECK13,typename CHECK14,typename CHECK15,typename CHECK16, typename CHECK17,typename CHECK18,typename CHECK19,typename CHECK20, typename CHECK21,typename CHECK22,typename CHECK23,typename CHECK24> class Checker : public CHECK1, public Checker<CHECK2, CHECK3, CHECK4, CHECK5, CHECK6, CHECK7, CHECK8, CHECK9, CHECK10,CHECK11,CHECK12,CHECK13, CHECK14,CHECK15,CHECK16,CHECK17,CHECK18,CHECK19, CHECK20,CHECK21,CHECK22,CHECK23,CHECK24> { public: template <typename CHECKER> static void _register(CHECKER *checker, CheckerManager &mgr) { CHECK1::_register(checker, mgr); Checker<CHECK2, CHECK3, CHECK4, CHECK5, CHECK6, CHECK7, CHECK8, CHECK9, CHECK10,CHECK11,CHECK12,CHECK13, CHECK14,CHECK15,CHECK16,CHECK17,CHECK18,CHECK19, CHECK20,CHECK21,CHECK22,CHECK23,CHECK24>::_register(checker, mgr); } };
二,模擬實現Checker
頭文件
/******************************** * * Author : szyu * * Date : 2016.12.27 * ********************************/ #ifndef __SZYU_CLANG__ #define __SZYU_CLANG__ #include <iostream> class DefaultClass { public: static void _register() { std::cout << "In DefaultClass::_register()" << std::endl; } }; class FunctionClass1 { public: static void _register() { std::cout << "In FunctionClass1::_register()" << std::endl; } }; class FunctionClass2 { public: static void _register() { std::cout << "In FunctionClass2::_register()" << std::endl; } }; class FunctionClass3 { public: static void _register() { std::cout << "In FunctionClass3::_register()" << std::endl; } }; template <typename T1, typename T2 = DefaultClass, typename T3 = DefaultClass> class Checker; template <> class Checker<DefaultClass> { public: static void _register() { std::cout << "In Checker<DefaultClass>::_register()" << std::endl; DefaultClass::_register(); } }; template <typename T1, typename T2, typename T3> class Checker : public T1, public Checker<T2, T3> { public: static void _register() { std::cout << "In Checker<T1, T2, T3>::_register()" << std::endl; T1::_register(); Checker<T2, T3>::_register(); } }; #endif
測試用例
/******************************** * * Author : szyu * * Date : 2016.12.27 * ********************************/ #include "register.h" void test1() { typedef Checker<DefaultClass> Checker1; Checker1::_register(); std::cout << "=====================" << std::endl; typedef Checker<FunctionClass1> Checker2; Checker2::_register(); std::cout << "=====================" << std::endl; typedef Checker<FunctionClass1, FunctionClass2> Checker3; Checker3::_register(); std::cout << "=====================" << std::endl; typedef Checker<FunctionClass1, FunctionClass2, FunctionClass3> Checker4; Checker4::_register(); std::cout << "=====================" << std::endl; } int main( int argc, char *argv[] ) { test1(); return 0; }
執行結果
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。