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];