Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Iterator Interface
--GNAT 4.9.3 with Ada.Text_IO; with Ada.Iterator_Interfaces; with system; with System.Address_To_Access_Conversions; procedure Hello is type Integer_Array is array (Positive range <>) of aliased Integer; type list(cnt : positive) is record data : Integer_Array(1..cnt); end record; package Address_Conversions is new System.Address_To_Access_Conversions (list); type cursor is record container : system.address; index : integer; end record; function has_element(position : cursor) return boolean is l : list renames Address_Conversions.To_Pointer(position.container).all; begin return position.index <= l.data'length; end has_element; package Iterators is new Ada.Iterator_Interfaces (Cursor, Has_Element); type iterator is new iterators.forward_iterator with record container : system.address; end record; function First (iter : Iterator) return Cursor; function Next (iter : Iterator; Pos : Cursor) return Cursor; function Iterate (container : list) return Iterators.Forward_Iterator'Class is begin return iter : iterator do iter.container := container'address; end return; end iterate; function First (iter : Iterator) return Cursor is begin return C : Cursor do C.container := iter.container; C.index := 1; end return; end First; function Next (iter : Iterator; Pos : Cursor) return Cursor is begin return C : Cursor do C.container := Pos.container; C.index := Pos.index + 1; end return; end Next; type reference_type(element : not null access integer) is limited null record with Implicit_Dereference => element; function get (C : Cursor) return reference_type is S : list renames Address_Conversions.To_Pointer (C.container).all; begin return reference_type'(element=>s.data(c.index)'access); end get; l : list :=(data=>(1,2,3,4,5,6,7,8,9,10), cnt=>10); begin for c in iterate(l) loop ada.text_io.put_line(integer'image(get(c))); end loop; end Hello;
run
|
edit
|
history
|
help
1
Please
log in
to post a comment.
Dynamic Dispatching
Stack (Using Tasking)
division_emtera_p.adb
susuma_dos_enteros.adb
Ada.adb
Ada Dimentional System
plop
Dynamic Dispatching with no dynamic allocation
Ada Dimentional System
1d array as 4d with easy reshaping
Please log in to post a comment.