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=BAYES_00,FORGED_MUA_MOZILLA autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,70414f56d810c10c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.68.8.229 with SMTP id u5mr6276509pba.0.1316775662212; Fri, 23 Sep 2011 04:01:02 -0700 (PDT) Path: lh7ni3183pbb.0!nntp.google.com!news1.google.com!goblin3!goblin.stu.neva.ru!news.tu-darmstadt.de!news.belwue.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 23 Sep 2011 12:57:40 +0200 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: discriminant questions References: <9f37b726-d80b-4d24-bf3f-28a14255f7fd@s20g2000yql.googlegroups.com> <01a1374f-59ab-40be-9e39-0640cb2a513d@n35g2000yqf.googlegroups.com> <1fp2o673mu9az$.d9loz1zbcl0d.dlg@40tude.net> <14tiipigyejtc$.hyp7e82egqwq$.dlg@40tude.net> <34d856bd-19a3-4bbf-b9d8-c0f100000ef4@k7g2000vbd.googlegroups.com> <1tpl2pc36ptr4$.txv4v3wmkjlm.dlg@40tude.net> <1malv6h6q31j3.uz9ws5j0glnm.dlg@40tude.net> In-Reply-To: Message-ID: <4e7c6625$0$6556$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 23 Sep 2011 12:57:41 CEST NNTP-Posting-Host: d51d5fe6.newsspool4.arcor-online.net X-Trace: DXC=_NSbiJ]n`_@74okIm;?DS@4IUKJLh>_cHTX3jMT5P53Ei3ofG X-Complaints-To: usenet-abuse@arcor.de Xref: news1.google.com comp.lang.ada:18104 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Date: 2011-09-23T12:57:41+02:00 List-Id: On 23.09.11 09:59, Dmitry A. Kazakov wrote: > Can I declare an iterator object constant? What is the meaning of its > "constantness" when the container gets manipulated? See a huge language > problem here? An iterator can be immutable only if the container is. How do > I express such stuff in the language? Well, have one more level of indirection, and one aspect (i.e., only two more kludges ;-) Not sure whether the aspect can be checked at compile time, though, or to what extent. Compiling: const.adb (source file time stamp: 2011-09-23 10:27:42) 1. with Ada.Containers.Vectors; 2. 3. procedure Const is 4. 5. type E is (Mon, Bin, Ter); 6. subtype P is Positive range 1 .. 100; 7. 8. package Vec is new Ada.Containers.Vectors 9. (Element_Type => E, 10. Index_Type => P); 11. 12. type Const_Vector is access constant Vec.Vector; 13. type Const_Cursor is new Vec.Cursor 14. with Invariant => Has_Element (Const_Cursor); 15. 16. procedure Change (Element : in out E) is 17. begin 18. if Element = E'Last then 19. Element := E'First; 20. else 21. Element := E'Succ (Element); 22. end if; 23. end Change; 24. 25. function Frozen (V : Vec.Vector) return Const_Vector is 26. begin 27. return V'Unchecked_Access; 28. end Frozen; 29. 30. Container : Vec.Vector; 31. Position : Vec.Cursor; 32. Const_Container : Const_Vector; 33. begin 34. Container.Append(Mon); 35. Container.Append(Ter); 36. Position := Container.First; 37. Vec.Update_Element (Container, 38. Position, 39. Process => Change'Access); 40. Const_Container := Frozen (Container); 41. Vec.Update_Element (Const_Container.all, | >>> actual for "Container" must be a variable 42. Position, 43. Process => Change'Access); 44. 45. end Const; 46. 47. 48. 48 lines: 1 error gnatmake: "const.adb" compilation error Compilation exited abnormally with code 4 at Fri Sep 23 10:27:53