我想遍历数组并检查当前数组索引是否为枚举值。该阵列以及枚举被定义如下:比较枚举值
type Option is (None, A, B, C, D);
type Votes is array(Option) of Natural;
Zero_Option_Distribution: constant Votes := (others => 0);
Votes_Distribution: Votes := Zero_Option_Distribution;
的循环如下所示:
for I in Voting_System.Votes_Distribution'Range loop
-- this is where I would like to check whether I is a representation of either of the enum values
end loop;
我已经尝试过,来到了我心中的一切,就像
if I = Voting_System.Option(None) then -- ...
and
if I'Val("None") then -- ...
和一些更多的版本,他们每个人都没有工作。
我真的没有更多的想法来实现这一点。基于这条线在你的问题
那么'I'的类型是'Votes_Distribution'的索引类型,它是'Party'而不是'Option'。所以你在做什么似乎没有意义。如果'Party'在其他地方被声明为包含'None'的'Option'的子类型,那么'如果I = None'应该可以工作(假设您使相关声明可见)。 –
用Party的定义更新您的问题可能会让问题变得清晰一些。 – NWS