google / google/xls

[enhancement] variant_count!<> builtin

Open
#1,714 2 comments 0 reactions 0 assignees View on GitHub
dslx enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### What's hard to do? (limit 100 words)

Similar to `u32::MAX`, it would be nice to have a way to get the number of elements in an enum. Similar to rust's [std::mem::variant_count](https://doc.rust-lang.org/std/mem/fn.variant_count.html).

### Current best alternative workaround (limit 100 words)

Make a const yourself and hope you keep it up to date.

### Your view of the "best case XLS enhancement" (limit 100 words)

A builtin `std::variant_count!<>` or a colon-ref (like `u32::MAX`), e.g. EnumType::NUM_VARIANTS.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.