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.0 required=5.0 tests=BAYES_20,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1514d4f994aed7aa,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!t8g2000prg.googlegroups.com!not-for-mail From: eliben Newsgroups: comp.lang.ada Subject: generic function and overloading Date: 18 Oct 2007 00:28:38 -0700 Organization: http://groups.google.com Message-ID: <1192688972.967825.31130@t8g2000prg.googlegroups.com> NNTP-Posting-Host: 194.90.39.105 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-8-i" X-Trace: posting.google.com 1192692544 22004 127.0.0.1 (18 Oct 2007 07:29:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 18 Oct 2007 07:29:04 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.0 RFINTISAPROXY01 Complaints-To: groups-abuse@google.com Injection-Info: t8g2000prg.googlegroups.com; posting-host=194.90.39.105; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:2476 Date: 2007-10-18T00:28:38-07:00 List-Id: Hello, I have a few "hardware" types, for example uint16 and uint32. And I want to write a functions that will set or clear bits of such types. For example: function Bit_Set(word: uint16; bitn: natural) return uint16; function Bit_Set(word: uint16; bitn: natural) return uint16 is mask: uint16 := 2**bitn; begin return word or mask; end Bit_Set; However, I realize that such a function would be almost completely duplicated for the uint32 type. In C++ I would probably define it as a template on the type of the word, and the compiler would do the job for me. In Ada, however, when using generics it doesn't seem I can leave the same function name for all types (as I would do in overloading). I can define a generic Bit_Set, but then I have to specialize it for uin16 and uint32 with different function names. Is there any way I could combine the effects of generics and overloading and get a single Bit_Set for all my types without writing the code N times ? P.S. Ada95 Thanks, Eli