Re: std.typecons rebindable + tuple with const class gives warning

2021-02-17 Thread Saurabh Das via Digitalmars-d-learn
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

Re: std.typecons rebindable + tuple with const class gives warning

2021-02-04 Thread tsbockman via Digitalmars-d-learn
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

std.typecons rebindable + tuple with const class gives warning

2021-02-04 Thread Saurabh Das via Digitalmars-d-learn
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

Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-06 Thread Rubn via Digitalmars-d-learn
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

Re: C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Uknown via Digitalmars-d-learn
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

C++ / const class pointer signature / unable to find correct D syntax

2018-05-04 Thread Robert M. Münch via Digitalmars-d-learn
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

Re: rebind of const class variables

2015-01-20 Thread ketmar via Digitalmars-d-learn
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

Re: rebind of const class variables

2015-01-20 Thread bearophile via Digitalmars-d-learn
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

Re: rebind of const class variables

2015-01-20 Thread ketmar via Digitalmars-d-learn
``` > > 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

Re: rebind of const class variables

2015-01-20 Thread Jonathan M Davis via Digitalmars-d-learn
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

Re: rebind of const class variables

2015-01-20 Thread Mathias LANG via Digitalmars-d-learn
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

rebind of const class variables

2015-01-20 Thread qqiang via Digitalmars-d-learn
; 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

Re: const class

2014-11-26 Thread bearophile via Digitalmars-d-learn
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

const class

2014-11-26 Thread Oleg via Digitalmars-d-learn
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