A
Axter
I'm fine tuning a scope_handle class that takes a policy class as the
second template.
http://code.axter.com/scope_handle.h
Please see above link for full understanding of the problem.
One thing I don't like about the way the current policy template is
setup is that for the ptr_policy class the first template type is
different from the template type given to the policy.
And on the other policy classes, the template type is the same. (Which
is what I prefer)
Example:
scope_handle<char*, implicit_conversion_policy<char*> >
scope_handle<FILE, implicit_conversion_policy<FILE> >
scope_handle<HANDLE, no_policy<HANDLE> >
and for ptr_policy
scope_handle<Mynode*, ptr_policy<Mynode> >
I would like to be able to setup the ptr_policy class so that it takes
the same type as the first template type.
scope_handle<Mynode*, ptr_policy<Mynode*> >
But then if I do that, I can't seem to figure out a way to get the
dereference type declaration on the T& operator*() function.
template<typename T>
class ptr_policy
{
protected:
typedef typename T* type_t;
ptr_policy(type_t type):m_handle(type){}
type_t m_handle;
public:
type_t operator->() const{return m_handle;}
T& operator*() const{return *m_handle;}
bool operator! () const{return m_handle == 0;}
};
If T is of type (foo*) instead of (foo), is there any way to get type
(foo&) out of type (foo*)?
FYI: ******* I'm not asking about dereferencing the variable. I'm
referring to how to dereference the TYPE *******
second template.
http://code.axter.com/scope_handle.h
Please see above link for full understanding of the problem.
One thing I don't like about the way the current policy template is
setup is that for the ptr_policy class the first template type is
different from the template type given to the policy.
And on the other policy classes, the template type is the same. (Which
is what I prefer)
Example:
scope_handle<char*, implicit_conversion_policy<char*> >
scope_handle<FILE, implicit_conversion_policy<FILE> >
scope_handle<HANDLE, no_policy<HANDLE> >
and for ptr_policy
scope_handle<Mynode*, ptr_policy<Mynode> >
I would like to be able to setup the ptr_policy class so that it takes
the same type as the first template type.
scope_handle<Mynode*, ptr_policy<Mynode*> >
But then if I do that, I can't seem to figure out a way to get the
dereference type declaration on the T& operator*() function.
template<typename T>
class ptr_policy
{
protected:
typedef typename T* type_t;
ptr_policy(type_t type):m_handle(type){}
type_t m_handle;
public:
type_t operator->() const{return m_handle;}
T& operator*() const{return *m_handle;}
bool operator! () const{return m_handle == 0;}
};
If T is of type (foo*) instead of (foo), is there any way to get type
(foo&) out of type (foo*)?
FYI: ******* I'm not asking about dereferencing the variable. I'm
referring to how to dereference the TYPE *******