comp.lang.ada
 help / color / mirror / Atom feed
From: Blady <p.p11@orange.fr>
Subject: Re: Aggregate with derived types.
Date: Fri, 15 Sep 2023 09:27:57 +0200	[thread overview]
Message-ID: <ue111u$34tmh$1@dont-email.me> (raw)
In-Reply-To: <udvufb$2opvr$1@dont-email.me>

Le 14/09/2023 à 23:37, Jeffrey R.Carter a écrit :
> On 2023-09-14 22:00, Blady wrote:
>>
>> I wonder why the float list aggregate isn't inferred by the compiler 
>> and need some help with a qualification.
> 
> I'm not sure. But can't you simply write
> 
> ML2 : My_Float_List2 := [-3.1, -6.7, 3.3, -3.14, 0.0];
> 
> ? I presume that My_Float_List2 inherits its aggregate definition from 
> My_Float_List1.

Unfortunately not directly:
     10.    ML2c : My_Float_List2 := [-3.1, -6.7, 3.3, -3.14, 0.0];
                                     |
         >>> error: type of aggregate has private ancestor "Vector"
         >>> error: must use extension aggregate

Shouldn't inherit them?

Indeed you have it if you defined a private extension with explicit aspects:
    package PA is
       type My_Float_List3 is new My_Float_Lists.Vector with private with
         Constant_Indexing => Constant_Reference,
         Variable_Indexing => Reference,
         Default_Iterator => Iterate,
         Iterator_Element  => Float,
         Aggregate         =>
          (Empty => Empty, Add_Unnamed => Append, New_Indexed => 
New_Vector, Assign_Indexed => Replace_Element);
       function Constant_Reference
         (Container : aliased My_Float_List3; Index : Positive) return 
My_Float_Lists.Constant_Reference_Type is
         (My_Float_Lists.Constant_Reference (My_Float_Lists.Vector 
(Container), Index));
       function Reference (Container : aliased in out My_Float_List3; 
Index : Positive) return My_Float_Lists.Reference_Type is
         (My_Float_Lists.Reference (My_Float_Lists.Vector (Container), 
Index));
    private
       type My_Float_List3 is new My_Float_Lists.Vector with null record;
    end PA;

    ML3 : PA.My_Float_List3 := [-3.1, -6.7, 3.3, -3.14, 0.0];

  reply	other threads:[~2023-09-15  7:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14 14:02 Aggregate with derived types Blady
2023-09-14 15:31 ` Jeffrey R.Carter
2023-09-14 20:00   ` Blady
2023-09-14 21:37     ` Jeffrey R.Carter
2023-09-15  7:27       ` Blady [this message]
2023-09-16  6:39     ` 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