Bug 12680 – isIterable fails for types with disabled postblit

Status
REOPENED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-04-29T19:35:19Z
Last change time
2024-12-01T16:21:00Z
Assigned to
No Owner
Creator
monarchdodra
Moved to GitHub: phobos#10051 →

Comments

Comment #0 by monarchdodra — 2014-04-29T19:35:19Z
//---- import std.traits; struct S { this(this) @disable; } static assert(isIterable!(S[])); //---- Fails. Shouldn't.
Comment #1 by post — 2016-02-10T20:33:58Z
The example code you posted most definitely should not compile because S is not iterable. I guess you forgot the opApply() or range primitives. The following code *does* compile successfully: import std.traits; struct OpApply { @disable this(this); int opApply(int delegate(ref uint) dg) { assert(0); } } struct Range { @disable this(this); @property uint front() { assert(0); } void popFront() { assert(0); } enum bool empty = false; } static assert (isIterable!OpApply); static assert (isIterable!Range);
Comment #2 by petar.p.kirov — 2016-02-11T08:07:25Z
@Lars T. Kyllingstad The OP is not trying to iterate over the struct, but over an array of structs with @disabled this(this).
Comment #3 by post — 2016-02-11T22:47:56Z
Ah, sorry, I didn't notice the brackets. Well, then I guess it's more a question of how you define "a foreach loop with a single loop variable of automatically inferred type", as it is specified in the documentation. This does not work: S[10] arr; foreach (s; arr[]) { } This does work, however: foreach (ref s; arr[]) { } Since the documentation doesn't say anything explicitly about ref, I'm inclined to think that isIterable works as intended. Maybe we need an isRefIterable template too.
Comment #4 by robert.schadek — 2024-12-01T16:21:00Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10051 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB