您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。