[Issue 18631] std.random.choice does not work with const arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Feb 23 21:11:18 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=18631

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |snarwin+bugzilla at gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #3 from Paul Backus <snarwin+bugzilla at gmail.com> ---
This is a special case of a general problem with ranges and const. A const
object cannot implement popFront (which mutates its receiver), and therefore
cannot be a range.

In this case, the problem can be worked around by using the [] operator to
obtain a mutable slice over the const array:

---
const x = [1, 2];
auto y = choice(x[]);
---

*** This issue has been marked as a duplicate of issue 17771 ***

--


More information about the Digitalmars-d-bugs mailing list