On Wednesday, 3 February 2016 at 06:11:07 UTC, H. S. Teoh wrote:
I still can't come up with a compelling use case that would
justify using a const/immutable class member, that couldn't be
done by some other means, though. Especially since we're
talking about classes, we already have all the tra
On Tue, Feb 02, 2016 at 09:08:07PM -0800, Jonathan M Davis via
Digitalmars-d-learn wrote:
> On Tuesday, February 02, 2016 19:32:39 Ali Çehreli via Digitalmars-d-learn
> wrote:
> > On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > > I usually tell folks not to do it beca
On Tuesday, February 02, 2016 19:32:39 Ali Çehreli via Digitalmars-d-learn
wrote:
> On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> > I usually tell folks not to do it because of
> > all of the problems it causes.
>
> That's been my guideline: "const and immutable membe
On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote:
> Well, in principle, if you have a member that's going to be
initialized on
> construction and then never mutated, having it be const or immutable
would
> be desirable,
That's how I've seen it used in a friend's code. Ma
On Tuesday, February 02, 2016 18:14:50 H. S. Teoh via Digitalmars-d-learn wrote:
> On Tue, Feb 02, 2016 at 05:49:00PM -0800, Jonathan M Davis via
> Digitalmars-d-learn wrote:
> > On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn
> > wrote:
> > > const and immutable member
On Tue, Feb 02, 2016 at 05:49:00PM -0800, Jonathan M Davis via
Digitalmars-d-learn wrote:
> On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn
> wrote:
> > const and immutable members make structs non-assignable:
[...]
> > That's why I've been avoiding them altogether. How
On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn
wrote:
> const and immutable members make structs non-assignable:
>
> struct S {
> const int c;// Makes S non-assignable
> immutable int i;// Makes S non-assignable
> }
>
> void main() {
> auto a
On 02/02/2016 03:02 PM, anonymous wrote:
> I'm not sure what you mean by "default assignment".
I think I meant member-wise assignment. :)
> I'd say it works
> more simply with classes, because they're reference types. It's the same
> as using pointers to structs:
>
> auto a = new S();
> auto b
On 02.02.2016 23:48, Ali Çehreli wrote:
struct S {
const int c;// Makes S non-assignable
immutable int i;// Makes S non-assignable
}
void main() {
auto a = S();
auto b = S();
a = b; // Compilation ERROR
}
(That is the same issue in C++.)
That's