"Dr. Adrian Wrigley" <
[email protected]> skrev i en
meddelelse
This can be implemented mostly with templates.
the evidence I find is that these Ada features meet programmers'
needs (because they are widely used), yet the nearest equivalent
with templates is almost never used (I have never seen examples).
I don't think new template classes match the utility of new
types and subranges in practical terms (but I'm prepared to
be shown wrong!).
How, for example, do you create a new 2-D array indexed by
enumeration sub-ranges?
For example, what is the templated, range-checked equivalent of:
------------------------------------------
generic
type Index_T is (<>);
type Intensity_T is digits <>;
package CrossBright_P is
type CrossIntensity_T is array (Index_T, Index_T) of Intensity_T;
-- more subprograms here
end CrossBright_P;
type EMSpectrum_T is (Gamma_Ray, X_Ray, Ultra_Violet, Visible, Infra_Red, Microwave, Radio_Wave);
type Intensity_T is digits 6 range 0.0 .. 10_000.0;
type CrossSpectrumIntensity_T is array (EMSpectrum_T, EMSpectrum_T) of Intensity_T;
package MyCrossBright is new CrossBright_P (EMSpectrum_T, Intensity_T);
CrossIntensity : MyCrossBright.CrossIntensity_T := (others => (others => Intensity_T'First));
--------------------------------------------------------------
How would you do that without "compiling on the fly"?
same way as in Ada!
This will be part of the next standard, I hope. Still i do not believe it to
be esential for use.
It is sometimes handy to use the C preprocessor for local functions
Why? What is the purpose - if not to restrict portability?
To get access to externally defined data storage!!
For example, hardware devices, network data representation,
interfacing to machine code etc.
....
I doubt that this should be part of the standard. What is needed is
specification of low-level features in e.g. multiprocessor environments.
I think portable concurrent or distributed programming is a paradigm
poorly (non) supported by C++. The current situation is a mess.
Most of these "implementation defined" parts are there for portability. To
many definitions will make it more difficult to port C++ to other platforms.
But at least any difficulty is addressed once per platform,
rather than once for each program!
I do not see the purpose of the out-parameter. Why not simply return the
value(s)?
How do you return multiple values?
As for named parameter associations, these can again be implemented in a
library.
Again, they are widely used in Ada code, but very rarely in C++.
I found the library implementation kludgey.
For C++ portability from C was (and is) an important issue. Thus there is no
question about remocing e.g. pointer-arithmetic and decaying of arrays to
pointers. This simply can not happen. Also some of these features are needed
for an efficient implementation of low-level classes (e.g. std::vector).
What you can do is not use these features. And it is just a matter of
education to routinely use e.g. std::vector< t > and std::string instead of
arrays and char pointers.
You can't routinely use only the new features, because library
code mainly uses the old features. (most libraries are supplied
via C-style header files)
There are some bad decisions in the type system - specifically i hate the
automatic conversions from double to integral value. But again - this is
something you have to live with.
(only if you have to use C++!)
Right. The template stuff could possibly have been more elegant.
I am not sure i follow you here. In what way do you want portability? Are
you thinking of e.g. portability between an X-windows system and Windows? Or
portability of lower-level constructs such as multithreading or networking?
I wonder how Ada does this stuff.
portability for different type sizes (eg pointer widths, char signedness,
basic type ranges, data alignment)
I thought Ada supported generic programming. Isn't it then just a question
of creating a library?
it's a nuisance to have to define a suitable hashing function for
each type, particularly one you are several levels into a generic nesting!
The hashing function might need to be passed in at the top and
built in stages at each level. Not nice. (is there an alternative?)