Re: where exactly c++,c fail and Ada gets thru'
- From: "Martin Krischik" <krischik@xxxxxxxxxxxxxxxxxxxxx>
- Date: 28 Apr 2006 00:49:13 -0700
REH wrote:
Martin Krischik wrote:
Maciej Sobczak wrote:
Yes, classes are used to define new types. Is there any problem with
this? It is also necessary in Ada if we want to do just a bit more of
what is provided by type and subtype constructs.
Say:
type Y_Type is range 1 .. 10;
subtype X_Type is new x range 1 .. 5;
function F (X: X_Type) return Y_Type is
begin
return X + 3;
end F
Now I would expect that an Ada compiler will not insert any runtime checks
as X + 3 is allways in the range of Y_Type. However:
function G (X: X_Type) return Y_Type is
begin
return X + 7;
end G;
may well be outside the range of Y_Type and if so CONSTRAINT_ERROR will be
raised.
Now say we have a suitable C++ range template:
typedef range<int, 1, 10> Y_Type;
typedef range<Y_Type, 1, 5> X_Type;
Y_Type F (X_Type X)
{
return X + 3;
}
Y_Type G (X_Type X)
{
return X + 7;
}
Now anyone up to the challenge to define:
template <typename Base_Type, Base_Type First, Base_Type Last>
range::operator = (Base_Type right)
template <typename Base_Type, Base_Type First, Base_Type Last>
range::operator + (Base_Type right)
template <typename Base_Type, Base_Type First, Base_Type Last>
range::range (Base_Type right)
in such a way that it works like Ada - inclusive the *realistic* change that
the compiler will optimize away the range check in F ().
I have done this.
I had a look. Looks impressive with all those includes. Looks like one
of thoses templates I never want to debug thrue.
But don't expect me to have found that magic static analysis something
trick. So:
How exactly did you do it?
Martin
.
- Follow-Ups:
- References:
- where exactly c++,c fail and Ada gets thru'
- From: Ananth the Boss
- Re: where exactly c++,c fail and Ada gets thru'
- From: jimmaureenrogers@xxxxxxxxxxxxxxxx
- Re: where exactly c++,c fail and Ada gets thru'
- From: Maciej Sobczak
- Re: where exactly c++,c fail and Ada gets thru'
- From: Martin Krischik
- Re: where exactly c++,c fail and Ada gets thru'
- From: REH
- where exactly c++,c fail and Ada gets thru'
- Prev by Date: Re: procedural vs object oriented
- Next by Date: gps vs gnat pro
- Previous by thread: Re: where exactly c++,c fail and Ada gets thru'
- Next by thread: Re: where exactly c++,c fail and Ada gets thru'
- Index(es):
Relevant Pages
|