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,6cdf06eb7605332d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: Smarter Generics Date: Sun, 15 Aug 2004 01:14:03 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <%6uTc.592$de4.1@trndny07> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1092532443 28915 134.91.1.34 (15 Aug 2004 01:14:03 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Sun, 15 Aug 2004 01:14:03 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:2735 Date: 2004-08-15T01:14:03+00:00 List-Id: Frank J. Lhota wrote: : What would be great is if there were some way to write Limited_Stacks so : that the implementation strategy could be chosen based on the generic : parameters, so that we could do something like this: The following can be compiled, don't know if it is sufficiently general, though. generic type Stack_Element is private; Max_Length : in Positive; package Dyn_Stacks is type Stack_Type is limited private; Stack_Overflow, Stack_Underflow : exception; procedure Push ( Item : in Stack_Element; Onto : in out Stack_Type ); procedure Pop ( Item : out Stack_Element; Onto : in out Stack_Type ); private Some_Threshold: constant := 1_000; subtype Stack_Array_Index is Natural range 0 .. Some_Threshold; type Stack_Array is array(Stack_Array_Index) of Stack_Element; type Implementation is tagged null record; -- not yet decided what strategy to use, maybe abstract? type Array_Implementation is new Implementation with record items: Stack_Array; end record; type List_Implementation is new Implementation with record null; -- replace with a list type end record; type Strategy(which: Boolean) is limited record case which is when False => a_items: Array_Implementation; when true => l_item: List_Implementation; end case; end record; type Stack_Type is new Strategy(Max_Length > Some_Threshold); -- there we are ;-) end Dyn_Stacks; -- Georg