Ada 编程/属性/'Range
外观
属性 attribute 的含义取决于前缀 X 的含义。
如果 X 是一个标量子类型,则 X'Range 表示该子类型的有效值范围,即它与子类型本身相同。
如果 X 是一个受约束的数组子类型或数组对象,则 X'Range 表示 X 的索引范围。
在任何情况下,X'Range 等效于 X'First .. X'Last,但 X 只会被评估一次。
如果 X 是多维的,则属性需要一个静态参数 N 来标识第 N 个索引;'Range (1) 与 'Range 相同。
X'Range (N) 等效于 X'First(N) .. X'Last(N),但 X 只会被评估一次。
typeTisrange1..10; -- T'Range is equal to TtypeAisarray(T)ofS; -- these three A'Range is the same as TtypeAisarray(T'Range)ofS; -- declarationstypeAisarray(T'First .. T'Last )ofS; -- are equivalenttypeBisarray(Trange<>)ofS; -- B'Range is illegal (B is unconstrained)subtypeSBisB (2 .. 5); -- SB'Range is the same as 2 .. 5typeMisarray(Boolean, T)ofS; -- M'Range is equivalent to M'Range (1), which is Boolean -- M'Range (2) is the same as T
OA: A; -- OA'Range is the same as T OB: B (2 .. 5); -- OB'Range is equal to 2 .. 5
