Ada Programming/Attributes/'Enum Val
Appearance
This language feature has been introduced in Ada 2022.
Description
[edit | edit source]Return the enumeration literal represented by a given number.
For every enumeration subtype S, S'Enum_Val denotes a function with the following spec:
function S'Enum_Val (Arg : <Universal_Integer>) return S'Base;
The function returns the enumeration value whose representation matches the argument, or raises Constraint_Error if no enumeration literal of the type has the matching value. This will be equal to the value of the Val attribute in the absence of an enumeration representation clause. This is a static attribute (i.e., the result is static if the argument is static).
Example
[edit | edit source]typeEnum_Typeis(Enum1, Enum2, Enum3);
pragma Assert (Enum_Type'Enum_Val(0) = Enum1); -- OK
See also
[edit | edit source]Wikibook
[edit | edit source]Ada Reference Manual
[edit | edit source]- 13.4: Enumeration Representation Clauses [Annotated]
- Annex K: Language-Defined Attributes [Annotated]
Ada 2022 Overview
[edit | edit source]External links
[edit | edit source]GNAT Reference Manual > Implementation Defined Attributes > Enum_Val