Reputation: 7913
I've been using Ada.Containers.Indefinite_Hased_Maps to create my own custom hashed maps, and it worked quite well until I tried to use a vector as the element type. Here is an example of the problematic code:
package String_Vectors is new Ada.Containers.Vectors(Element_Type => Unbounded_String, Index_Type => Natural);
subtype String_Vector is String_Vectors.Vector;
package Positive2StringVector_HashMaps is new Ada.Containers.Indefinite_Hashed_Maps --Compiler fails here
(Element_Type => String_Vector,
Key_Type => Positive,
Hash => Positive_Hash,
Equivalent_Keys => Positive_Equal);
Basically, I cannot Positive2StringVector_HashMaps
package, because the compiler comes up with:
no visible subprogram matches the specification for "="
From what I understand, it isn't finding the equality operator for the String_Vector
, am I correct? If I am, what is the proper way of implementing it? And if I'm not, what am I doing wrong??
Upvotes: 1
Views: 1665
Reputation: 25501
You don’t need to implement
function “=“ (L, R : String_Vectors.Vector) return Boolean
yourself, because there already is one in String_Vectors
; see ALRM A.18.2(12). So you write
package Positive2StringVector_HashMaps is new Ada.Containers.Indefinite_Hashed_Maps
(Element_Type => String_Vector,
Key_Type => Positive,
Hash => Positive_Hash,
Equivalent_Keys => Positive_Equal,
“=“ => String_Vectors.”=");
By the way, is there some reason you used Ada.Containers.Vectors
on Unbounded_String
rather than Indefinite_Vectors
on String
? (wanting to change the length of a contained string would count as a Good Reason!)
Upvotes: 4