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,cea03ed275aa3d28 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.190.247.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.com!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Question about generics. From: "Peter C. Chapin" References: <7Q2qg.812592$084.507058@attbi_s22> Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: 03 Jul 2006 10:33:52 GMT NNTP-Posting-Host: 0ef2a89c.news.sover.net X-Trace: DXC=OdoPTVBoeF "Jeffrey R. Carter" wrote in news:7Q2qg.812592$084.507058@attbi_s22: > Peter C. Chapin wrote: >> >> generic >> Size : in Integer; >> package Xyzzy is >> type Index is mod Size; >> -- etc. >> end Xyzzy; > > What does a Size of -7 mean? Why not a compile time error when the instantiation is attempted? > As you've discovered, generic formal parameters are not static in Ada, > and so cannot be used in a type declaration. > > You can do > > generic > type Index is mod <>; > package P is > Size : constant Positive := Index'Modulus; > end P; Yes. However, this means at the point of instantiation I have to do something like type Dummy_Type is mod 8; package Fizzle is new Xyzzy(Index => Dummy_Type); The Dummy_Type will never be used in the context of the instantiation; it only exists to pass size information into the generic package. That seems pretty counter-intuitive and awkward. I guess I was hoping Ada would have a nicer solution... generic parameters that are named numbers or something. >> template< int size > >> class Xyzzy { >> char array[size]; // size is a compile time constant. >> }; > > This is a different kettle of fish. You can't declare new integer > types in C++, so you can't compare what you're trying to do with C++. > Array subtype constraints don't have to be static, or even constant: Don't be distracted by the fact that I used an array declaration above to demonstrate the "static-ness" of size. I realize that array bounds don't have to be static in Ada. However, my point was that C++ templates do allow non-type parameters to be used in contexts where compile time constants are required. For my particular situation I believe I could declare a subtype inside the generic package instead of a modular type. Alas, that means I'll have to manually wrap around values of my type. It's not the end of the world but, as I said, I was hoping for a nicer solution. Peter