M
ma740988
Consider a number of instances of template class
vector<a>, vector<b> ..., vector<f>
The types are - of course different. Of interest is an efficient way
to access them at runtime.
One approach.
if ( condition A is satisfied )
use vector<a>
Presumably some 'relevant pattern' would be ideal compared to a chain
of if's in all related methods.
So in an email I received, I'm told - advisors are great creatures -
to create a heterogeneous container. I've included 'enough' of the
example for traceability.
The example
template<class T>
class Proxy0
{
public:
typedef T TYPE_R;
virtual T CallFunc()=0;
};
//////////////////////////////////////
// Create a Heterogeneous Container
template<typename I, typename T, typename F>
class HetContainer_CommonFunction0 : public I
{
public:
HetContainer_CommonFunction0(T *Src, F f) : TargetClass(Src),
m_f(f){}
I::TYPE_R CallFunc()
{
return ((*TargetClass).*m_f)();
}
~HetContainer_CommonFunction0() { delete TargetClass; }
T *TargetClass;
F m_f;
};
template<typename R, typename T, typename F>
Proxy0<R>* CreateHeterogeneousContainer(T* Src, F f)
{
return new HetContainer_CommonFunction0<Proxy0<R>,T, F>(Src, f);
}
// more
At issue is the call
return ((*TargetClass).*m_f)();
I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.
Thanks for your time
vector<a>, vector<b> ..., vector<f>
The types are - of course different. Of interest is an efficient way
to access them at runtime.
One approach.
if ( condition A is satisfied )
use vector<a>
Presumably some 'relevant pattern' would be ideal compared to a chain
of if's in all related methods.
So in an email I received, I'm told - advisors are great creatures -
to create a heterogeneous container. I've included 'enough' of the
example for traceability.
The example
template<class T>
class Proxy0
{
public:
typedef T TYPE_R;
virtual T CallFunc()=0;
};
//////////////////////////////////////
// Create a Heterogeneous Container
template<typename I, typename T, typename F>
class HetContainer_CommonFunction0 : public I
{
public:
HetContainer_CommonFunction0(T *Src, F f) : TargetClass(Src),
m_f(f){}
I::TYPE_R CallFunc()
{
return ((*TargetClass).*m_f)();
}
~HetContainer_CommonFunction0() { delete TargetClass; }
T *TargetClass;
F m_f;
};
template<typename R, typename T, typename F>
Proxy0<R>* CreateHeterogeneousContainer(T* Src, F f)
{
return new HetContainer_CommonFunction0<Proxy0<R>,T, F>(Src, f);
}
// more
At issue is the call
return ((*TargetClass).*m_f)();
I realize it's a function pointer call, however, the member access
specifier . coupled with the deference operator * for m_f makes the
syntax very confusing to me.
Thanks for your time