template specialization for ENUM
https://stackoverflow.com/questions/47666913/template-specialization-for-enum-values
https://stackoverflow.com/questions/1619993/template-specialization-for-enum
https://gcc.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:30,endLineNumber:24,positionColumn:30,positionLineNumber:24,selectionStartColumn:30,selectionStartLineNumber:24,startColumn:30,startLineNumber:24),source:'//+%23include+%3Ciostream%3E%0A%23include+%3Ctype_traits%3E%0A%23include+%3Ccstdint%3E%0A%23include+%3Ccompare%3E%0A%0Aenum+A+%7BRED,+BLUE%7D%3B%0A%0A//+template+%3Ctypename+T%3E+void+func(%0A//+++++T%26+param,+%0A//+++++typename+std::enable_if%3Cfalse%3E::type+%3D+nullptr+)+%7B%7D%0A%0Atemplate+%3Ctypename+T%3E+void+func(%0A++++T%26+param,+%0A++++typename+std::enable_if%3C(param%3D%3D1)%3E::type+%3D+nullptr+)+%7B%7D%0A//+template+%3Ctypename+T%3E+void+inc_counter(%0A//+++++T%26+param,%0A//+++++typename+std::enable_if%3C%0A//+++++++++A::BLUE+%3D%3D+param%0A//+++++%3E::type*+%3D+nullptr+)+%7B%0A//+%0A//+++++%7D%0A%0Avoid+doSomething()+%7B%0A++++constexpr+A+var+%3D+A::RED%3B%0A++++int+b+%3D+1%3B%0A++++//+blah+blah+blah%0A++++//+inc_counter(cntObj)%3B%0A++++func(b)%3B%0A%7D%0A%0A%0Aint+main()%7B%0A++++doSomething()%3B%0A++++return+0%3B%0A%7D'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g122,deviceViewOpen:'1',filters:(b:'0',binary:'0',binaryObject:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B11',selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+gcc+12.2+(Editor+%231)',t:'0')),k:19.187757504414357,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+3.7',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+gcc+12.2+(Compiler+%231)',t:'0')),k:47.4789091622523,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
看起来个根据值来做spec是不可能实现的任务了
本文来自博客园,作者:ijpq,转载请注明原文链接:https://www.cnblogs.com/ijpq/p/17049109.html