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=-0.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fce663eaf40b52f6 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!newshub.sdsu.edu!ctu-peer!Spring.edu.tw!news.nctu.edu.tw!netnews.eranet.net!news.ttn.net!feeder.seed.net.tw!attdv1!ip.att.net!newsfeed1.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail From: "Xenos" Newsgroups: comp.lang.ada Subject: Re: Ranges in C++ Date: Mon, 10 May 2004 15:03:02 -0400 Organization: Hades Message-ID: References: <1327280.rH5RGlINvC@linux1.krischik.com> <1802641.IB4YAx8xDq@linux1.krischik.com> NNTP-Posting-Host: 158.187.64.144 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 Xref: controlnews3.google.com comp.lang.ada:426 Date: 2004-05-10T15:03:02-04:00 List-Id: "Martin Krischik" wrote in message news:1802641.IB4YAx8xDq@linux1.krischik.com... > I did an implementation on templates. i.E. > > typedef IntegerRange<1, 31> DayOfMonth; > typedef IntegerRange<1, 12> MonthOfYear; If you added a parameter for the integer type, it would be more generic, and allow for ranged char, short, enums, etc. > > Apart from Image and Value all functions are inlined and only the value but > not First and Last need to stored. This is closer to the Ada original and > should give better performace. > > Also a template implentation gives you real types while a class > implementation gives only subtypes. Think of: yes, it is a trade off. As I needed ranged floating points, I didn't have much choice. But also note with your example you only have unique types if the ranges are different (which may or may not be what you want). I compensated for the type/subtype problem by adding a "uniqueness" parameter to the template with a default. This allowed both types and subtypes. Something like: class unique_default {}; template class Ranged { ... }; template class Float_Ranged { ... }; Unique types can be created by instantiating the template with a different classes for U. > > Set (DayOfMonth Day); > Set (MonthOfYear Month); > > And yes: no "const&" the type can be used like an integer. > > With Regards > > Martin > > -- > mailto://krischik@users.sourceforge.net > http://www.ada.krischik.com >