C++: Use of namespaces in program logic / conditional namespaces? -


this technical question (if it's technically feasible) style question. in code have series of functions load , manipulate file. different syntax these functions exist in separate namespaces, that:

namespace typea {   void load();   void manipulate(); };  namespace typeb {   void load();   void manipulate(); }; 

in minimal example, simple have clause checks file type , calls typea:load() , typeb:load() etc. required.

however, wondering if possible using namespace aliases? make code cleaner there several dozen calls functions in namespaces need separate if/else clause.

what i've tried:

namespace my_type = (ft == "type_a") ? typea : typeb; ... my_type::load(); 

which doesn't compile error in namespace alias assignment line.

is there way of doing / accepted clean way of handling situations this?

i suppose virtual class , inheritance each file type 1 option. there others?

there no way such namespace alias.

3.4.6 using-directives , namespace aliases [basic.lookup.udir] 1 in using-directive or namespace-alias-definition, during lookup namespace-name or name in nested-name-specifier namespace names considered.

you use partial template specialization solve that.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -