comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Creating a generic package with and setting its type to that of a record
Date: Wed, 28 Sep 2016 07:15:30 +0100
Date: 2016-09-28T07:15:30+01:00	[thread overview]
Message-ID: <ly60pg5z3x.fsf@pushface.org> (raw)
In-Reply-To: c941ba8e-f28c-4bcf-9e8a-13fa93031bda@googlegroups.com

Andrew Shvets <andrew.shvets@gmail.com> writes:

> generic
>   type Custom_Record_Type is <>; 
> package Gener is
>   ...
>
> What I'd like to do is set the type to that of a record (which has
> some overloaded operators, such as >, < and =.)  Can this be done?  If
> so, how?

I think you are looking for generic formal subprograms[1]. Something
like

generic
   type Custom_Record_Type is private;
   with function ">" (L, R; Custom_Record_Type) return Boolean is <>;
   with function "<" (L, R; Custom_Record_Type) return Boolean is <>;
   with function "=" (L, R; Custom_Record_Type) return Boolean is <>;
package Gener is

The 'is <>' notation means you don't need to supply an actual for this
parameter if a matching one is visible at the point of instantiation.

You could instantiate it for Integer, but I'm not sure what operation
would be used if you tried "<=", for instance; the composition of your
generic actuals, or the emergent "<=" of Integer.

[1] https://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_formal_subprograms


  parent reply	other threads:[~2016-09-28  6:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-28  1:02 Creating a generic package with and setting its type to that of a record Andrew Shvets
2016-09-28  2:08 ` Jeffrey R. Carter
2016-09-28  2:15   ` Andrew Shvets
2016-09-28  6:15 ` Simon Wright [this message]
2016-09-28 21:38   ` Randy Brukardt
2016-09-29  7:57     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox