c++ - Handle templates with unknown until runtime type -


i tried sleeping on this, still lost. i'm not sure search terms should using. can point me in right direction.

i want this:

template < typename interim > class phase_one {     interim do_something () ; } template < typename output, typename interim > class phase_two {     output do_something_more ( interim ) ; } template < output > class main_class {     phase_one m_first;     phase_two m_second;      output do_main ( )     {         return m_second.dosomething_more( m_first.do_something() );     } } 

hoping can see pseudocode need store , call on both template classes. interim type not known until runtime. thing know before hand output type , fact both phases have type in common.

how can store these objects , how can make them work together? instance type erasure required?

edit: phase_one std::codecvt , phase_two codecvt of creation. need select phase_two based on phase_one. , done @ runtime, after reading file's bom.

i'd prefer without boost or c++11. if there boost method of doing this, interested in seeing it, must implementable without boost libraries, if have create similar method/template myself.

i modified main_class template. made aware of interim type

template < typename interim > class phase_one {     interim do_something () ; }  template < typename output, typename interim > class phase_two {     output do_something_more ( interim ) ; }  template < typename output, typename interim > class main_class {     phase_one<interim> m_first;     phase_two<output, interim> m_second;      output do_main ( )     {         return m_second.dosomething_more( m_first.do_something() );     } } 

you instantiate main_class like

int main () {      if (some condition) {          main_class<char, unsigned long> m;          m.do_main();     } else {          main_class<char, unsigned short> m;          m.do_main();     }  } 

does work you?


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -