Article View: comp.std.c++
Article #1972Re: Do we need a standard isPointer() function?
From: Fergus Henderson
Date: Thu, 14 Sep 1995 22:26
Date: Thu, 14 Sep 1995 22:26
48 lines
2069 bytes
2069 bytes
phalpern@truffle.ultranet.com (Pablo Halpern) writes:
>What I would like is some
>operation which tells me whether a type is a built-in type and/or a
>pointer type.
Try the following:
template <class T>
struct ext_type_info {
enum { is_pointer = false }; // assume T is not a pointer...
}
// define a partial specialization
template <class U>
struct ext_type_info<U *> { // ... unless it matches this
enum { is_pointer = true }; // partial specialization
}
#include <assert.h>
main() {
assert(ext_type_info<int>::is_pointer == false);
assert(ext_type_info<int*>::is_pointer == true);
}
[This is now legal C++, but I don't know of any compilers that
support partial specialization yet.]
Also check out the numeric_limits class in the draft standard.
You can use `numeric_limits<T>::is_specialised' to determine
whether a type T is one of the fundamental numeric types.
[Similarly, numeric_limits<T> is not yet supported by most implementations.]
> 1) Is the format of the returned value of type_info::name() standard
> enough for me to depend on it for this purpose?
No.
--
Fergus Henderson | #define x t=a[i],a[i]=a[m],a[m]=t/* use -O */
| char a[]=" 12345678";main(m,i,j,t){for(i=m;i<
fjh@cs.mu.oz.au | 9;x,i++)for(x,j=m;--j?(t=a[m-j]-a[m])-j&&t+j:
http://www.cs.mu.oz.au/~fjh | main(m+1)*0;);m-9||puts(a+1);} /* 8 queens */
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<9525806.29066@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<439kkn$n81@caesar.ultra.net>Show Full Headers
Complete Article Headers
Approved: fjh@cs.mu.oz.au Date: 14 Sep 95 22:26:52 GMT From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Message-ID: <9525806.29066@mulga.cs.mu.OZ.AU> Newsgroups: comp.std.c++ Organization: Computer Science, University of Melbourne, Australia Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back References: <439kkn$n81@caesar.ultra.net> Subject: Re: Do we need a standard isPointer() function?