🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Can I declare private constants?

#2333
From: David Vandevoorde
Date: Fri, 27 Oct 1995 23:09
39 lines
2033 bytes
> clamage@Eng.Sun.COM (Steve Clamage) wrote:
[...]
> So it seems to me that being able to write
> struct T { static const double e = 2.7182818285; };
> doesn't give you any added capability or convenience compared to
> struct T { static const double e; };
> because you must still provide a definition someplace.

Doesn't this also largely apply to integral and enumeration types?
My primary interest in member declarator const-initializers is the
added opportunities for inlining;

e.g.:	struct SomeModel {
	    static const double a = 1.76;
	    static const double b = 0.76;
	    // ...
	};

	template<class M> inline
	double derived_quantity(double x) {
	    return (1.0-M::a*M::a)/M::b*x*x; // purely hypothetical
	}

Obviously, I would rather see constant propagation work in such case.
Especially since this kind of code easily creeps into innermost loops.

> We might someday revisit the restrictions on floating-point constants,
> but it seems to me the rules are at least consistent.

I agree with the consistency... and I hope revisitation will come soon...

Thanks,

	Daveed


[ 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: <VANDEVOD.95Oct27190550@avs.cs.rpi.edu>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu> <46ovik$s80@engnews2.Eng.Sun.COM> <46pp4p$74i@ixnews3.ix.netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: vandevod@cs.rpi.edu (David Vandevoorde)
Newsgroups: comp.std.c++
Subject: Re: Can I declare private constants?
Date: 27 Oct 1995 23:09:32 GMT
Organization: RPI Computer Science
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <VANDEVOD.95Oct27190550@avs.cs.rpi.edu>
References: <VANDEVOD.95Oct26140846@avs.cs.rpi.edu> <46ovik$s80@engnews2.Eng.Sun.COM>
 <46pp4p$74i@ixnews3.ix.netcom.com>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: avs.cs.rpi.edu
In-Reply-To: miker3@ix.netcom.com's message of 27 Oct 1995 14:55:15 GMT
Content-Length: 1088
X-Lines: 35
Originator: clamage@taumet