c++ - Decisions using Template Tags -


i have templated class need instantiate depending on command line arguments.

there must better way can think of:

if (optiona == 1){     if (optionb == 2){         myclass <option1, option2, option3> object;     } } else if (optiona == 2){  // whole big if-else ladder } 

this doesn't allow me use templated object outside scope of if statement! way, options tags

your challenge want compile-time decision (option type selection) based on runtime data (args). imagine macro/template solution generated 'parse tree', mapping option codes tags. result in combinatorial explosion generate templated types, slow compilation (and runtime). alternative use factory methods each option, passing option objects myclass constructor. not efficient pure compile-time generation, don't see alternative.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -