0

As I understand from here anything that implements Ada.Iterator_Interfaces can use the Ada 2012 for loop syntax. "for ... [in|of] .. loop .. end loop;

How do I create a generic subprogram that I can instantiate with a type in a package that implements the Ada.Iterator_Interfaces? and so then be able to have that subprogram iterate over that type using an Ada 2012 for loop.

In Java this might look like:

public String join(Iterable<String> collection) {
   for (item : collection){
     //do stuff
   } 
}

For example (although not the only case) a classic join function that can take any iterable container containing strings and return all the strings joined together in a string list. eg.

my_container = ["a","b","c"]
join(my_container) = "abc"

Thanks

Matt

Matt
  • 134
  • 15
  • so... what's your question? – egilhh Jan 27 '15 at 14:22
  • 2
    Are you looking for [generic formal derived types](http://www.ada-auth.org/standards/12rm/html/RM-12-5-1.html)? They work with interfaces too. `generic type T is new Ada.Iterator_Interfaces with private;...` and now your instantiation requires a type that implements `Iterator_Interfaces`. – ajb Jan 28 '15 at 05:57
  • thanks , yes close to that - I've added a java example to be more clear. – Matt Jan 29 '15 at 09:59

0 Answers0