From: Georg Bauhaus <rm.tsoh.plus-bug.bauhaus@maps.futureapps.de>
Subject: Re: Generics with concrete and class-wide types
Date: Tue, 01 Apr 2008 09:22:56 +0200
Date: 2008-04-01T09:22:56+02:00 [thread overview]
Message-ID: <47f1e2d0$0$4748$9b4e6d93@newsspool3.arcor-online.net> (raw)
In-Reply-To: <279b6f4f-36cf-446f-8b54-fd72b957b22f@i7g2000prf.googlegroups.com>
Maciej Sobczak wrote:
> Consider a generic subprogram that makes sense for arguments of both
> class-wide type and a concrete type.
> -- does not compile:
> procedure SP is new Some_Procedure
> (T => Integer, Iterator_Type => Iterator_Integer'Class); -- Bang!
FWIW, the following triggers everything from a running
program to an Ada 95 compiler internal assertion failure
(in case the iterator object is initialized in the main
procedure).
with Iterators, Some_Procedure;
procedure Test_Iterators is
package II is new Iterators(Integer);
procedure Context_Conc(it: II.Conc_Iter) is
procedure SP is new Some_Procedure
(Integer, II, Iterator_Type => II.Conc_Iter);
begin
SP(it);
end Context_Conc;
procedure Context_Disp(it: II.Iterator'Class) is
procedure SP is new Some_Procedure
(Integer, II, Iterator_Type => II.Iterator'Class);
begin
SP(it);
end Context_Disp;
c: II.Conc_Iter := II.Conc_Iter'(El => new Integer'(42));
begin
Context_Conc(c);
Context_Disp(c);
end Test_Iterators;
with Iterators;
generic
type T is private;
with package Integer_Iterators is new Iterators(T);
type Iterator_Type(<>) is new Integer_Iterators.Iterator with private;
procedure Some_Procedure (it: Iterator_Type);
generic
type T is private;
package Iterators is
type Iterator is abstract tagged null record;
function Get(It: Iterator) return T is abstract;
type T_Ptr is access constant T;
type Conc_Iter is new Iterator with
record
El: T_Ptr;
end record;
function Get(It: Conc_Iter) return T;
end Iterators;
procedure Some_Procedure (It: Iterator_Type) is
use type Integer_Iterators.Iterator;
Tmp: T;
begin
Tmp := Get(It);
end Some_Procedure;
package body Iterators is
function Get (It: Conc_Iter) return T is
begin
return It.El.all;
end Get;
end Iterators;
next prev parent reply other threads:[~2008-04-01 7:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-31 20:22 Generics with concrete and class-wide types Maciej Sobczak
2008-03-31 23:38 ` Adam Beneschan
2008-04-01 20:10 ` Randy Brukardt
2008-04-01 21:17 ` Adam Beneschan
2008-04-01 0:23 ` Randy Brukardt
2008-04-01 3:57 ` Eric Hughes
2008-04-01 6:58 ` christoph.grein
2008-04-01 7:22 ` Georg Bauhaus [this message]
2008-04-01 9:42 ` Dmitry A. Kazakov
2008-04-01 9:51 ` Maciej Sobczak
2008-04-01 10:53 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox