class Object{
public:
Handle handle;
};
template <class T, Handle T::*handleptr>
class Con{
public:
...
};
class User{
public:
Con<Object,&Object::handle> objects; //Valid
Con<User,&User::handle> subusers; //invalid because of class scope
Handle handle;
};
Template specialization and hidden handles
I am trying to find a convenient way to handle element handles without explicitly needing to use them, the problem at the moment is that it's not possible to specialize the templates in the same class scope.
For instance, we have two classes, and one container class of arbitrary elements with a handle pointer requirement:
What I am looking for is a similar way to handle elements as the first Container in user, not needing to "care" about their respective handles when dealing with classes able to contain lists of the same type as themselves.
One option is ofc. to inherit and use it as an extension, however it fails if several handles are needed. Also another option of declaring a subclass with the handle is quite crude.
Any input is welcome, thank you.
So far the most elegant solution I have found is:
Passing the type with which to use the container externally. An acceptable solution, however far from elegant.
Any suggestions on improvements?
template <class T, Handle T::*handleptr, class Convert = T>class Con{public: Convert * Retrieve(int i){ return (Convert*) buffer; } ...};class _User{public: Handle handle;};class User : public _User{public: Con<_User,&_User::handle,User> subusers; //valid, however still quite crude};
Passing the type with which to use the container externally. An acceptable solution, however far from elegant.
Any suggestions on improvements?
I'm not exactly sure what you want to do, but doesn't this work for you?
class Object {public: Handle handle;};template < typename T >class Con { Handle T::*hptr;public: Con() : hptr( &T::handle ) { }};class User {public: Con< Object > objects; Con< User > subusers; Handle handle;};
Thanks for the reply.
Well, since it assumes every class to have the "handle" with that specific name, and this is not the case.
It is quite exactly the same solution as to inherit the handle and using the type directly in the container as the handle.
Any class may have a handle or several with any names, it would work if it was divided into two distinct container classes, one assumes the one handle, and one that expects the template parameter. A possible solution, however leaves alot to be desired since it does not allow for the multiple or arbitrary named handle cases.
Passing a variable name would be nice as a template parameter, but thats just dreaming of the impossible ^^
Any further input is greatly appreciated.
Well, since it assumes every class to have the "handle" with that specific name, and this is not the case.
It is quite exactly the same solution as to inherit the handle and using the type directly in the container as the handle.
Any class may have a handle or several with any names, it would work if it was divided into two distinct container classes, one assumes the one handle, and one that expects the template parameter. A possible solution, however leaves alot to be desired since it does not allow for the multiple or arbitrary named handle cases.
Passing a variable name would be nice as a template parameter, but thats just dreaming of the impossible ^^
Any further input is greatly appreciated.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement