473,395 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

knowing if a template parameter is a pointer

Hi,

I would like to port a .NET list into standard c++
and in particular is there a way of knowing if the object is a pointer
or not ?

Ex :

template<typename T>
class List : public std::list<T>
{
public:
~List() { Clear(); }

inline void Add(T object)
{
// IS IT POSSIBLE TO KNOW if object is a pointer ???????????
if ( ISAPONITER(object) )
bIsPtr = true;
else
bIsPtr = false;
push_back(object);
}

inline void Clear(bool bDeallocate = true)
{
if (bDeallocate && m_bIsPtr)
{
int count = this->size();
// ???? I SHOULD PARSE MY LIST AND DEALLOCATE
this->std::list<T>::clear();
}
}

inline int GetCount() { return size(); }

private:
bool m_bIsPtr;
};

Nov 8 '06 #1
2 1235
Vincent RICHOMME wrote:
I would like to port a .NET list into standard c++
and in particular is there a way of knowing if the object is a pointer
or not ?
What does it mean for it to be a pointer? Why do you have that
requirement? Try using -with it, and if it's a pointer (or a class
that pretends to be a pointer), the code will successfully compile.
If the operator-is not defined for that type, the compilation will
fail.

You can also specialise your template for all pointers.

So the solution depends on what you need to do.
>
Ex :
[..]
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 8 '06 #2

Vincent RICHOMME wrote:
Hi,

I would like to port a .NET list into standard c++
and in particular is there a way of knowing if the object is a pointer
or not ?
This already exists in boost::type_traits I am sure but...

template < typename T>
struct is_pointer
{
enum { value = false };
};

template < typename T >
struct is_pointer < T * >
{
enum { value = true };
}

then it becomes as simple as something like:

template < typename T >
class X
{
static bool const is_ptr = is_pointer<T>::value;
};

Nov 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brian Ross | last post by:
Hi, I am trying to do something similar to the following: int Func1(int x, int y); double Func2(double x, double y); template <typename FuncT> // <- What would go here class CObjectT {
9
by: tropostropos | last post by:
On Solaris, using the Sun compiler, I get annoying warnings from the following code. The problem is that I am passing a C++ member function pointer to the C library function qsort. Is there a...
4
by: Ondrej Spanel | last post by:
The code below does not compile with .NET 2003, I get folowing error: w:\c\Pokusy\delegTemplArg\delegTemplArg.cpp(11) : error C2993: 'float' : illegal type for non-type template parameter 'x' ...
5
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
4
by: David Sanders | last post by:
Hi, I have a class depending on a template parameter: template<int n> class MyClass { }; I want the template parameter to be chosen according to a variable, e.g.
4
by: abir | last post by:
I am matching a template, and specializing based of a template, rather than a single class. The codes are like, template<template<typename T,typename Alloc = std::allocator<T> class pix{ }; ...
7
by: Christof Warlich | last post by:
Hi, the subject says it all: I need to instantiate an array of objects where each object "knows" its arrary index. So far, this is easy as long as index is not a compile-time constant: class ...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
2
by: Clyde | last post by:
Hi, what i'm trying to do is: /////////////// Code Start template <class TType, int* p = 0> class Template { public:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.