From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
ip-172-31-65-14.ec2.internal
X-Spam-Level:
X-Spam-Status: No, score=-3.2 required=3.0 tests=BAYES_00,FREEMAIL_FROM,
NICE_REPLY_A,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no
version=3.4.6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Blady
Newsgroups: comp.lang.ada
Subject: Re: Aggregate with derived types.
Date: Fri, 15 Sep 2023 09:27:57 +0200
Organization: A noiseless patient Spider
Message-ID:
References:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 15 Sep 2023 07:27:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cc85bafdc724e3723e7182e61de4ce8a";
logging-data="3307217"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vaZn4pmXfdWVb5e58KqQy"
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Cancel-Lock: sha1:ry0oKkdyI37Zpa8pIm1/xKCnPGA=
Content-Language: fr, en-US
In-Reply-To:
Xref: news.eternal-september.org comp.lang.ada:65654
List-Id:
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];