D - Detecting Pointer Types
- resistor mac.com (5/5) Feb 26 2004 I'm writing the destruction for a templated class. It has a member vari...
- Sean Kelly (25/29) Feb 26 2004 template IsPointer( T )
- resistor mac.com (5/35) Feb 26 2004 That seems rather...hackish. I'm sure it would work, but it seems rathe...
- Sam McCall (3/6) Feb 26 2004 If it's for a destructor, would foo=T.init work?
- John Reimer (3/11) Feb 26 2004 I thought it to be rather novel and creative. It's an interesting exampl...
- resistor mac.com (7/18) Feb 27 2004 Sorry if that sounded insulting. I didn't mean to be. I just meant tha...
- John Reimer (7/13) Feb 27 2004 No, no, no. Don't worry about it. You were not insulting at all. You a...
- Matthias Becker (2/12) Mar 01 2004 This is very common technique in C++. Actualy this was the simplest kind...
- John Reimer (3/17) Mar 01 2004 Oh dear, I guess I better study up on my template-meta-programming then
- Sean Kelly (4/7) Mar 02 2004 If you're so inclined, there's a book called "Generative Programming"
- John Reimer (2/15) Mar 02 2004 Thanks for the tip, Sean. I'll look into it.
- Sean Kelly (4/7) Feb 27 2004 Not sure I understand. If your pointer is a class member then it will
I'm writing the destruction for a templated class. It has a member variable of type T (the template's type). I want to somehow detect if this is a pointer type, and set it to null if it is. Is there some way to detect if it's a point type, or will I have to make a specialized version of the class to handle it? Owen
Feb 26 2004
resistor mac.com wrote:I'm writing the destruction for a templated class. It has a member variable of type T (the template's type). I want to somehow detect if this is a pointer type, and set it to null if it is. Is there some way to detect if it's a point type, or will I have to make a specialized version of the class to handle it?template IsPointer( T ) { static const bit IsPointer = false; } tempalte IsPointer( T : T* ) { static const bit IsPointer = true; } if( IsPointer!( T ) ) t = NULL; You stull might get a compiler error trying to set T to NULL depending on what T is. You may want to do something like this instead: template SetNULL( T ) { void SetNULL( T val ) {} } template SetNULL( T : T* ) { void SetNULL( T val ) { val = NULL; } } SetNULL!(T)( t );
Feb 26 2004
That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class? Owen In article <c1m53v$2gf5$1 digitaldaemon.com>, Sean Kelly says...resistor mac.com wrote:I'm writing the destruction for a templated class. It has a member variable of type T (the template's type). I want to somehow detect if this is a pointer type, and set it to null if it is. Is there some way to detect if it's a point type, or will I have to make a specialized version of the class to handle it?template IsPointer( T ) { static const bit IsPointer = false; } tempalte IsPointer( T : T* ) { static const bit IsPointer = true; } if( IsPointer!( T ) ) t = NULL; You stull might get a compiler error trying to set T to NULL depending on what T is. You may want to do something like this instead: template SetNULL( T ) { void SetNULL( T val ) {} } template SetNULL( T : T* ) { void SetNULL( T val ) { val = NULL; } } SetNULL!(T)( t );
Feb 26 2004
resistor mac.com wrote:That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class?If it's for a destructor, would foo=T.init work? Sam
Feb 26 2004
On Fri, 27 Feb 2004 04:04:03 +0000, resisto wrote:That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class? Owen In article <c1m53v$2gf5$1 digitaldaemon.com>, Sean Kelly says...I thought it to be rather novel and creative. It's an interesting example of the flexibility of templates.
Feb 26 2004
Sorry if that sounded insulting. I didn't mean to be. I just meant that it seemed like something that shouldn't require such arcane antics to achieve. I certainly am impressed with his solution. It was more a comment on the need to do that at all than on his solution. Sorry if I offended anyone. Owen In article <pan.2004.02.27.06.39.55.658007 telus.net>, John Reimer says...On Fri, 27 Feb 2004 04:04:03 +0000, resisto wrote:That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class? Owen In article <c1m53v$2gf5$1 digitaldaemon.com>, Sean Kelly says...I thought it to be rather novel and creative. It's an interesting example of the flexibility of templates.
Feb 27 2004
In article <c1njd1$1r5t$1 digitaldaemon.com>, resistor mac.com says...Sorry if that sounded insulting. I didn't mean to be. I just meant that it seemed like something that shouldn't require such arcane antics to achieve. I certainly am impressed with his solution. It was more a comment on the need to do that at all than on his solution. Sorry if I offended anyone. OwenNo, no, no. Don't worry about it. You were not insulting at all. You are perfectly entitled to your opinion. For your purposes, the solution may have been more convoluted than desired. I was just balancing out the perspective: if not a practical solution, it certainly was original :-). Later, John
Feb 27 2004
This is very common technique in C++. Actualy this was the simplest kind of template-meta-programming.That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class? Owen In article <c1m53v$2gf5$1 digitaldaemon.com>, Sean Kelly says...I thought it to be rather novel and creative. It's an interesting example of the flexibility of templates.
Mar 01 2004
On Mon, 01 Mar 2004 14:48:22 +0000, Matthias Becker wrote:Oh dear, I guess I better study up on my template-meta-programming then :-).This is very common technique in C++. Actualy this was the simplest kind of template-meta-programming.That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class? Owen In article <c1m53v$2gf5$1 digitaldaemon.com>, Sean Kelly says...I thought it to be rather novel and creative. It's an interesting example of the flexibility of templates.
Mar 01 2004
John Reimer wrote:Oh dear, I guess I better study up on my template-meta-programming then :-).If you're so inclined, there's a book called "Generative Programming" that covers the topic pretty thoroughly without focusing too heavily on C++. Sean
Mar 02 2004
Sean Kelly wrote:John Reimer wrote:Thanks for the tip, Sean. I'll look into it.Oh dear, I guess I better study up on my template-meta-programming then :-).If you're so inclined, there's a book called "Generative Programming" that covers the topic pretty thoroughly without focusing too heavily on C++. Sean
Mar 02 2004
resistor mac.com wrote:That seems rather...hackish. I'm sure it would work, but it seems rather strange to have to do that. Has nobody else ever needed to write a ~this() for a templated class?Not sure I understand. If your pointer is a class member then it will disappear when the dtor exits and the gc will wipe out any orphaned data. Sean
Feb 27 2004