
Hi, I have a std::vector<boost::any> m_Processes containing several hydrological processes where a process is implemented like this: template<typename DerivedT> class Process { public: DerivedT& asDerived( void ) { return static_cast<DerivedT&>( *this ); } void Apply( Subbasin& subbasin ) { asDerived().Apply( subbasin ); } } Special Processes are derived from Process and pass their type as template argument ( Barton and Nackman Trick ). I am writing a simulation software for hydrological simulation and want to test if I can get a better performance when getting rid of the virtual function overhead since all types are know at compile time. I want to iterate over all elements of m_Processes in a function void AdvanceTyp( void ). The below implemention doens't work, but will show my intend: template<typename DerivedT> void Subbasin::AdvanceTime( void ) { // Call Process::Apply for each element and pass a *this for_each( m_Processes.begin(), m_Process.end(), bind2nd( mem_func_ref( Process<DerivedT>::Apply, *this ) } At the moment the compiler can't resolve the template argument. How do I have to implement the function, such that it can be resolved by the compiler? -Dirk

"Dirk Gregorius" <dirk@dirkgregorius.de> wrote in message news:000601c4c0dd$9f8cb280$0e2a9386@Erft... | Hi, | | I have a std::vector<boost::any> m_Processes containing several hydrological | processes where a process is implemented like this: | | template<typename DerivedT> | class Process | { | public: | DerivedT& asDerived( void ) | { | return static_cast<DerivedT&>( *this ); | } | void Apply( Subbasin& subbasin ) | { | asDerived().Apply( subbasin ); | } | } | | Special Processes are derived from Process and pass their type as template | argument ( Barton and Nackman Trick ). no, you mean "the curiously recurring template idiom" |I am writing a simulation software | for hydrological simulation and want to test if I can get a better | performance when getting rid of the virtual function overhead since all | types are know at compile time. have you measured that virtual functions are slowing the stuff down? Anyway, I would expect boost.any + static dispatch is slower than virtual dispatch in a class hierarchy. br Thorsten
participants (2)
-
Dirk Gregorius
-
Thorsten Ottosen