我正在学习Ada(通过尝试https://adventofcode.com/2018/问题).
我有一个向量ActivityVector的ActivityRecord记录:
type ActivityRecord is
record
dt: Ada.Calendar.Time;
str: UStr.Unbounded_String;
end record;
package ActivityVector is new Ada.Containers.Vectors
(Element_Type => ActivityRecord,
Index_Type => Natural);
Run Code Online (Sandbox Code Playgroud)
我想把它们放在键盘的地图上Integer.我有以下内容:
function IntegerHash(i: Integer) return Ada.Containers.Hash_Type;
package ActivityMap is new Ada.Containers.Indefinite_Hashed_Maps(
Key_Type => Integer,
Element_Type => Activity.ActivityVector.Vector,
Hash => IntegerHash,
Equivalent_Keys => "="
);
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我得到:
act_map.ads:9:04: instantiation error at a-cihama.ads:46
act_map.ads:9:04: no visible subprogram matches the specification for "="
act_map.ads:9:04: instantiation error at a-cihama.ads:46
act_map.ads:9:04: default "=" on "Vector" is not directly visible
Run Code Online (Sandbox Code Playgroud)
看起来它期望为向量定义一个相等运算符?我可以定义一个,但首先我想检查一下:
看起来它期望为向量定义一个相等运算符
是.
我可以定义一个
不要这样做,只需使用实例化中定义的现有函数Ada.Containers.Vectors:
package ActivityMap is new Ada.Containers.Indefinite_Hashed_Maps(
Key_Type => Integer,
Element_Type => Activity.ActivityVector.Vector,
Hash => IntegerHash,
Equivalent_Keys => "=",
"=" => Activity.ActivityVector."="
);
Run Code Online (Sandbox Code Playgroud)
或者,Activity.ActivityVector."="通过执行直接使功能可见
use type Activity.ActivityVector.Vector;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
107 次 |
| 最近记录: |