Re: Integral and non-integral
From: Alf P. Steinbach (alfps_at_start.no)
Date: 03/09/04
- Next message: Jack Klein: "Re: The range of variables with GNU g++"
- Previous message: Claudio Puviani: "Re: How did C++ beat the competition?"
- In reply to: Alf P. Steinbach: "Re: Integral and non-integral"
- Next in thread: Rob Williscroft: "Re: Integral and non-integral"
- Reply: Rob Williscroft: "Re: Integral and non-integral"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Mar 2004 05:08:08 GMT
* alfps@start.no (Alf P. Steinbach) schriebt:
> * Rob Williscroft <rtw@freenet.REMOVE.co.uk> schriebt:
> >
> > #include <iostream>
> >
> > struct X
> > {
> > static int const value = 2;
> > };
An example of what the concept of general language rules (no special
cases), I think this is known as orthogonality, dictates is that one
should be allowed to write, in a header file,
struct X
{
static double const value = 2.0;
};
that is, one should be able to provide complete class definition in a
header file.
The question is why this is actively prohibited by the language.
Here is one in principle way the compiler could transform a fully inlined
class to something allowed by the current arbitrarily restricted language.
Except for the use of underscores this is also a transformation the
programmer can use, although a function for producing the constant
value would be much more practical for the programmer.
1) Moving definition out of class, solving syntactic problem, yielding
struct X
{
static double const value;
};
double const value = 2.0;
2) Templatization, solving multiple definition problem, yielding
struct __Concrete {}; // Underscores means defined by compiler.
template< class __Dummy >
struct __X
{
static double const value;
};
template< class __Dummy >
double const __X<__Dummy>::value = 2.0; // Multiple defs OK, §3.2/5.
typedef __X<__Concrete> X;
(Note: it's possible there are language details that prevent this exact
transformation for classes that are not fully inline, e.g. further rules
could have to be used for out-of-class member function definitions, but
that does not matter -- it's not as if the in-principle transformation
which demonstrates technical doability is the best practical way.)
Having performed these mechanical transformations, (1) and (2), class X is
ready for use, being defined in full in a header file, which shows that
* There seems to be no sound _technical_ reason why in-class definitions
of arbitrarily typed static constants couldn't be or can not be allowed.
* Also, there seems to be nothing that the current arbitrary rules _prevent_
regarding final functionality, they just make things very awkward.
And the effect could conceivably be defined by such a transformation.
-- A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?
- Next message: Jack Klein: "Re: The range of variables with GNU g++"
- Previous message: Claudio Puviani: "Re: How did C++ beat the competition?"
- In reply to: Alf P. Steinbach: "Re: Integral and non-integral"
- Next in thread: Rob Williscroft: "Re: Integral and non-integral"
- Reply: Rob Williscroft: "Re: Integral and non-integral"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|