Bug 20166 – among should have an overload for fixed-length arrays

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-24T23:46:21Z
Last change time
2023-11-06T12:25:17Z
Assigned to
No Owner
Creator
Simen Kjaeraas

Comments

Comment #0 by simen.kjaras — 2019-08-24T23:46:21Z
Currently, one needs to use aliasSeq or aliasSeqOf to define the list of values for among to look through. When defining a list of elements that will be used elsewhere, a fixed-length array is often more useful, and this dance to convert between the two is not helping anyone. IOW, this should compile: enum brackets = ['(', '[', '{', '}', ']', ')']; assert('('.among(brackets));
Comment #1 by nick — 2023-03-11T11:55:38Z
Presumably you mean a dynamic array. The docs for among say see also canFind. That does what you want: import std.algorithm.searching; enum brackets = ['(', '[', '{', '}', ']', ')']; static assert(brackets.canFind('('));
Comment #2 by nick — 2023-11-06T12:25:17Z
Marking as WONTFIX because `among` says use `canFind` to search a range.