comp.lang.ada
 help / color / mirror / Atom feed
From: Mark Lorenzen <mark.lorenzen@gmail.com>
Subject: Problems using Generic_Dispatching_Constructor
Date: Wed, 1 Jun 2022 04:36:02 -0700 (PDT)	[thread overview]
Message-ID: <9a5e9c8b-c263-4ac7-86f8-97a8ee1fdb99n@googlegroups.com> (raw)

The generic function Ada.Tags.Generic_Dispatching_Constructor is defined as:

generic
   type T (<>) is abstract tagged limited private;
   type Parameters (<>) is limited private;
   with function Constructor (Params : not null access Parameters) return T is abstract;

function Ada.Tags.Generic_Dispatching_Constructor (The_Tag : Tag; Params  : not null access Parameters) return T'Class;

This gives us some problems when calling an instance of Ada.Tags.Generic_Dispatching_Constructor when the Params parameter is an in-mode parameter of a function e.g.:

function Make (From_Params : in P) return T'Class
   is
      function Make_T_Class is new Ada.Tags.Ada.Tags.Generic_Dispatching_Constructor (T => T, Parameters => P, Constructor => ...);
   begin
   ...
   return Make_T_Class (Some_Tag, P'Access);
   end Make;

This results in a compile-time error:
error: access-to-variable designates constant

Why is function Ada.Tags.Generic_Dispatching_Constructor defined as:
function Ada.Tags.Generic_Dispatching_Constructor (The_Tag : Tag; Params  : not null access Parameters) return T'Class;

and not as e.g (note the access-to-constant type):
function Ada.Tags.Generic_Dispatching_Constructor (The_Tag : Tag; Params  : not null access constant Parameters) return T'Class;

I guess we could declare function Make as (note the in-out mode):
function Make (From_Params : in out P) return T'Class
But this is horrible as functions should never ever have in-out or out-mode parameters (or side effects in general).

Why are access types used at all?

Is there another workaround?

Regards,
Mark L

             reply	other threads:[~2022-06-01 11:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 11:36 Mark Lorenzen [this message]
2022-06-01 12:42 ` Problems using Generic_Dispatching_Constructor Dmitry A. Kazakov
2022-06-01 21:25   ` Randy Brukardt
replies disabled

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