Re: where exactly c++,c fail and Ada gets thru'
- From: Martin Krischik <krischik@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Apr 2006 19:32:50 +0200
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 ().
Martin
--
mailto://krischik@xxxxxxxxxxxxxxxxxxxxx
Ada programming at: http://ada.krischik.com
.
- Follow-Ups:
- Re: where exactly c++,c fail and Ada gets thru'
- From: REH
- Re: where exactly c++,c fail and Ada gets thru'
- From: Maciej Sobczak
- Re: where exactly c++,c fail and Ada gets thru'
- 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
- where exactly c++,c fail and Ada gets thru'
- Prev by Date: Re: where exactly c++,c fail and Ada gets thru'
- Next by Date: Re: procedural vs object oriented
- 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
|