refRange with non copyable struct
Jerry via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 17 10:23:32 PDT 2017
Hello guys, so I wanted to have a noncopyable range on the stack.
So my thoughts was to make it non copyable and use refRange
whenever I want to use it with map and others.
But I got a compiler warning when doing so like this:
import std.range;
void main() {
NonCopyable v;
refRange(&v);
}
struct NonCopyable
{
@disable this(this);
int data;
enum empty = false;
void popFront() {}
int front() { return data; }
}
With the error message:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(8941):
Error: struct reproduction.NonCopyable is not copyable because it
is annotated with @disable
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(8982):
Error: mutable method reproduction.NonCopyable.front is not
callable using a const object
C:\D\dmd2\windows\bin\..\..\src\phobos\std\range\package.d(9649):
Error: template instance std.range.RefRange!(NonCopyable) error
instantiating
reproduction.d(6): instantiated from here:
refRange!(NonCopyable)
Is there any workaround?
Is this a bug?
More information about the Digitalmars-d-learn
mailing list