From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,25b9eb5c3a89bced X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!g10g2000cwb.googlegroups.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: where exactly c++,c fail and Ada gets thru' Date: 27 Apr 2006 09:48:08 -0700 Organization: http://groups.google.com Message-ID: <1146156488.812085.225600@g10g2000cwb.googlegroups.com> References: <1145852356.559455.222600@i39g2000cwa.googlegroups.com> <1145855124.720029.35280@t31g2000cwb.googlegroups.com> <1235818.stAph9vF03@linux1.krischik.com> NNTP-Posting-Host: 192.35.35.34 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1146156495 14671 127.0.0.1 (27 Apr 2006 16:48:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 27 Apr 2006 16:48:15 +0000 (UTC) In-Reply-To: <1235818.stAph9vF03@linux1.krischik.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g10g2000cwb.googlegroups.com; posting-host=192.35.35.34; posting-account=lnUIyw0AAACoRB2fMF2SFTIilm8F10q2 Xref: g2news2.google.com comp.lang.ada:3964 Date: 2006-04-27T09:48:08-07:00 List-Id: 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 Y_Type; > typedef range 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 > range::operator = (Base_Type right) > > template > range::operator + (Base_Type right) > > template > 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.