🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2124

Re: Determining between classes and built-in t

#2124
From: Steve Clamage
Date: Thu, 05 Oct 1995 18:05
40 lines
2246 bytes
In article 100000@gusak, "Brett W. Denner" <dennerbw@cliffy.lfwc.lockheed.com> writes:
>Is there a way to identify whether a data type in a template function is a
>class or a built-in type?  For example,
>
>template <class T> void
>func(T var)
>{
>    if ( /* test whether T is a built-in type */ )
> 	/* do something based on T being a built-in type */;
>    else
>        /* do something else based on T being a user-define type */;A
>}
>
>Will rtti allow me to test for this?  Is there another way of determing this?

What is the actual problem you are trying to solve? Is it really the case
that if T is a double or a char* or a FILE* you will do operation A, but if
it is a complex or a string or an fstream you will do operation B?

And what do you mean by a "user-defined type"? Consider the following:
	typedef int T1;
	typedef int (*T2)(int);
	struct T3 { double x, y; };
	typedef double T3::*T4;
I'm pretty sure you would consider T3 a user-defined type, and T1 not a
user-defined type, but T2 and T4 aren't so obvious to me.

I suspect you would be better off documenting the properties that T must
have, and write the template accordingly. If you really have two different
sets of criteria, write two templates. You can add tests to the template
that don't generate any code to verify the properties of type T. D&E has
examples of how to do that.
---
Steve Clamage, stephen.clamage@eng.sun.com



[ 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: <450v2o$f3g@engnews2.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
References: <Pine.SGI.3.91.951003143924.20596A-100000@gusak>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Determining between classes and built-in t
Date: 5 Oct 1995 18:05:35 GMT
Organization: Sun Microsystems Inc.
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <450v2o$f3g@engnews2.Eng.Sun.COM>
References: <Pine.SGI.3.91.951003143924.20596A-100000@gusak>
Reply-To: clamage@Eng
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
Content-Length: 1408
X-Lines: 36
Originator: clamage@taumet