# \[design\] indexing into enums / enum.indices

**URL:** <https://chapel.discourse.group/t/design-indexing-into-enums-enum-indices/8095>\
**Category:** Users\
**Created:** [November 8, 2021, 6:49pm UTC](https://chapel.discourse.group/t/design-indexing-into-enums-enum-indices/8095 "2021-11-08T18:49:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradcray](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/bradcray/32/72_2.png) [@bradcray](https://chapel.discourse.group/u/bradcray)\
**Post date:** [November 8, 2021, 6:49pm UTC](https://chapel.discourse.group/t/design-indexing-into-enums-enum-indices/8095/1 "2021-11-08T18:49:28Z")

</div>

Hi Chapel community —

I'm looking for feedback on a proposal to support two new features on `enum` types:

1. supporting `myEnum[i]` as a means of getting the 'i'th symbol in the enumeration
2. supporting `myEnum.indices` as a means of getting the range `0..<myEnum.size`

The first supplies a capability that is not available for end-users today; the second continues the recent trend of having indexable things support a query indicating what indices can be used with them.

If you have thoughts on this, or would like to upvote the proposal, please see:

> <https://github.com/chapel-lang/chapel/issues/15102>
>
> Internally, Chapel uses a dense indexing scheme for enum symbols that is used to… store and track them. Conversions between the indices and enum symbols and back again have been supported by undocumented routines and are useful when doing things like I/O or using implementing ranges of enums. This issue asks whether these indices should be exposed more directly to users as well. For example, imagine:
> 
> \* \`proc type enum.indices\`: would return the legal set of indices for accessing an enum (say 0..#enum.size)
> \* \`proc type enum.this(i: integral)\`: would return the i-th constant in the enumeration
> 
> Thus:
> 
> \`\`\`chapel
> enum color = {red, green, blue};
> writeln(color.indices); // would write out \`0..2\`
> writeln(color(1)); // would write out \`green\`
> \`\`\`

Thanks,  
-Brad
