我想遍歷數組並檢查當前數組索引是否爲枚舉值。該陣列以及枚舉被定義如下:比較枚舉值
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