comp.lang.ada
 help / color / mirror / Atom feed
* How do you specialize a generic function from a nested function?
@ 2015-07-26  8:29 EGarrulo
  2015-07-26  9:09 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 2+ messages in thread
From: EGarrulo @ 2015-07-26  8:29 UTC (permalink / raw)


I am trying to write a generic predicate that negates a supplied predicate.  The generic predicate compiles, but the compilation of client code fails with "generic subprogram cannot be called" (because the client code supplies a nested predicate, I suppose).  Here is the code (see the comment in the last file).

------------- negate.ads ------------------

generic
   type Value_Type is private;
   with function Predicate (Value : Value_Type) return Boolean;
   -- I have also tried with:
   -- Predicate : access function (Value : Value_Type) return Boolean;
function Negate (Value : Value_Type) return Boolean;

------------- negate.adb ------------------

function Negate (Value : Value_Type) return Boolean is
begin
   return not Predicate (Value);
end Negate;

------------- test.adb ------------------

with Negate;

procedure test is
   function Is_Zero (Value: Integer) return Boolean is (Value = 0);

   Is_Not_Zero : access function (Value: Integer) return Boolean 
   := Negate(Integer, Is_Zero'Access); -- <<== ##### ERROR HERE #####
begin
   null;
end test;

--------------------------------------


What is wrong?  And -- in any case -- could the code be simplified?  Thank you.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-26  9:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-26  8:29 How do you specialize a generic function from a nested function? EGarrulo
2015-07-26  9:09 ` Dmitry A. Kazakov

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