🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Determining between classes and built-in t

#2282
From: Alex Martelli
Date: Sun, 22 Oct 1995 23:28
40 lines
2225 bytes
howlett@netcom.com (Scott Howlett) writes:
	...
>> template <class T> inline bool can_memmove(const T&) { return false; }
>> inline bool can_memmove(const int&) { return true; } // etc

>Perhaps this would be better as something like the following:

>template<class T> class type_traits {
>    enum { can_memmove = true };
>};

>class type_traits<foo> {
>    enum { can_memmove = false };
>};

>That way you get the answer to can_memmove at compile time. Not only
>does this save you code (both time and space) but it allows you to

I would be surprised to find myself using a compiler unable to
optimize away an inline function call returning a manifest constant...
it is however true that the idiom you propose seems to have no
offseting defect.

>do things which require compile-time constants, such as using
>type_traits<T>::can_memmove as a parameter to some other template.

Conceded, and this makes the idiom you suggest appear to be quite
preferable, thanks.


Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it                            Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia   Fax: +39 (51) 597120
---
[ 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: <martelli.814348376@cadlab>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <martelli.813831475@cadlab> <VANDEVOD.95Oct16193053@avs.cs.rpi.edu> <martelli.813918684@cadlab> <howlett-1710952158260001@192.0.2.1>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 22 Oct 95 23:28:00 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
From: martelli@cadlab.cadlab.it (Alex Martelli)
Subject: Re: Determining between classes and built-in t
Message-ID: <martelli.814348376@cadlab>
X-Newsreader: NN version 6.5.0 #11
Organization: Cad.Lab Spa, Bologna, Italia
References: <martelli.813831475@cadlab> <VANDEVOD.95Oct16193053@avs.cs.rpi.edu> <martelli.813918684@cadlab> <howlett-1710952158260001@192.0.2.1>
X-Original-Date: Sun, 22 Oct 1995 07:52:56 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMIrTpOEDnX0m9pzZAQFm3QF/RGyh7rOi2Dwpk/QWrKiXH0CHgfdKRM+7
 S/4qYZ8tUFaixIst8abncE/yfNmlUeaG
 =7/Yg