On Thursday, 4 February 2021 at 20:40:43 UTC, tsbockman wrote:
TLDR; Either make `c` mutable, or override/overload the `C`
associative array support methods `toHash` and `opEquals` to
support `const(C)` objects.
This solved my issue. I finally understood why this was happening
after digging
On Thursday, 4 February 2021 at 08:16:06 UTC, Saurabh Das wrote:
This code:
void main()
{
import std.typecons : rebindable, tuple;
const c = new C();
auto t = tuple(c.rebindable);
}
class C
{
}
When compiled with DMD 2.095.0 gives a warning:
Warning: struct Rebindable has method t
This code:
void main()
{
import std.typecons : rebindable, tuple;
const c = new C();
auto t = tuple(c.rebindable);
}
class C
{
}
When compiled with DMD 2.095.0 gives a warning:
Warning: struct Rebindable has method toHash, however it cannot
be called with const(Rebindable!(const(C
gin(ref Image image, const(InitParams)
initParams);
Which creates a const pointer to a const class signature. But
it should only be a const pointer. Any idea how to solve this?
The problem is that const in D is transitive. That means T *
const from C++ is not expressible in D. Any reference thr
Which creates a const pointer to a const class signature. But
it should only be a const pointer. Any idea how to solve this?
The problem is that const in D is transitive. That means T *
const from C++ is not expressible in D. Any reference through a
const becomes const. To use it, IMO your b
gin(class
b2d::Image & __ptr64,class b2d::Context2D::InitParams const * __ptr64)
__ptr64
So I somehow get some more const from D. This is the code I used:
final uint _begin(ref Image image, const(InitParams) initParams);
Which creates a const pointer to a const class signature. But it sh
On Tue, 20 Jan 2015 14:45:26 +
bearophile via Digitalmars-d-learn
wrote:
> ketmar:
>
> > Jonathan explains it very well. i can add the only thing: don't
> > use `const` until you forced to. ;-)
>
> In D use immutable (or const) everywhere you can. Possibly mark
> as immutable everything d
ketmar:
Jonathan explains it very well. i can add the only thing: don't
use `const` until you forced to. ;-)
In D use immutable (or const) everywhere you can. Possibly mark
as immutable everything doesn't need to mutate.
sure, you can cast `const` away in your code, but using `cast`
is a
```
>
> It failed to compile and complaint that `cannot modify const
> expression ret`。
>
> Since `ret` is just a binding to a const class object, why can't
> I rebind it to another const class variable?
>
> Must I use pointers to cope with this?
Jonathan explains it very
gt;
> @property
> const(Node) maximum() const {
> auto ret = this;
>
> while (ret.right_) {
> ret = ret.right_;
> }
>
> return ret;
> }
> }
> ```
>
> It failed to compile and complaint that `cannot modify const
> expression
const class object, why
can't I rebind it to another const class variable?
Must I use pointers to cope with this?
Thx
You are looking for
http://dlang.org/phobos/std_typecons.html#.Rebindable
;
while (ret.right_) {
ret = ret.right_;
}
return ret;
}
}
```
It failed to compile and complaint that `cannot modify const
expression ret`。
Since `ret` is just a binding to a const class object, why can't
I rebind it to another
Oleg:
how create variable that store const object and can be changed
to other const object?
Take a look at std.typecons.Rebindable/std.typecons.rebindable.
Read all Phobos documentation, it helps.
Bye,
bearophile
Hello. I can't find siple way to realization this behavior:
[code]
class A
{
A parent;
void someFunc() const { }
void parentCall() const
{
const(A) cur = this;
while( cur )
{
cur.someFunc();
cur = cur.parent;
}
}
}
[/code]
error: cannot modify const
14 matches
Mail list logo