|
Boost : |
From: Dirk Gregorius (dirk_at_[hidden])
Date: 2004-11-02 08:12:35
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk