On Tue, Jun 21, 2016 at 01:48:27PM +, jmh530 via Digitalmars-d-learn wrote:
[...]
> Thanks to you and the others for the detailed clarifications. I think
> part of the difficulty is that there are basically three things being
> discussed that are all very similar: an alias to data, a pointer
On Tuesday, 21 June 2016 at 15:21:01 UTC, Ali Çehreli wrote:
[snip]
Thanks.
On 06/21/2016 06:48 AM, jmh530 wrote:
> So an immutable pointer guarantees that whatever it is pointing to will
> never change,
Yes but saying "_requires_ that data never changes" is more correct.
When it comes to a pointer (i.e. the user of data), "guarantee" is
related to const.
> but a
On Tuesday, 21 June 2016 at 02:54:06 UTC, ketmar wrote:
Thanks to you and the others for the detailed clarifications. I
think part of the difficulty is that there are basically three
things being discussed that are all very similar: an alias to
data, a pointer to data, and a view of data.
behavior is identical. And really, if you never need to take
the address of the variable, then a manifest constant using
enum would be more appropriate.
Actually, I should say it *may* be more appropriate. Definitely
only when the initializer is known at compile time. There are
cases when
On Tue, Jun 21, 2016 at 02:24:03AM +, jmh530 via Digitalmars-d-learn wrote:
> I feel like I have a reasonable understanding of when to use const as
> a parameter in a function or for const member functions. However, I
> don't really understand why/when it should be used as a type modifier.
>
On Tuesday, 21 June 2016 at 02:24:03 UTC, jmh530 wrote:
So the line from the spec is
"Const types are like immutable types, except that const forms
a read-only view of data. Other aliases to that same data may
change it at any time."
I tried making an alias of a const variable and modifying
I feel like I have a reasonable understanding of when to use
const as a parameter in a function or for const member functions.
However, I don't really understand why/when it should be used as
a type modifier.
For instance, the Programming in D book basically just says
On Tue, Jan 24, 2012 at 08:01:41PM -0500, bearophile wrote:
Jonathan M Davis:
Now, the confusing part is the fact that unlike C++, D allows you to put
the
const for making the function on the _left-hand_ side of the function (C++
only lets you put it on the right). This is to
On Tuesday, January 24, 2012 16:24:27 Ali Çehreli wrote:
On 01/24/2012 04:06 PM, Jonathan M Davis wrote:
class A {
int x;
const int f1() { ... }
int f2() const { ... }
const(int) f3() { ... }
}
[...]
int f2() const
becomes
int f2(const A this)
On 01/25/2012 02:29 AM, H. S. Teoh wrote:
On Tue, Jan 24, 2012 at 08:01:41PM -0500, bearophile wrote:
Jonathan M Davis:
Now, the confusing part is the fact that unlike C++, D allows you to put the
const for making the function on the _left-hand_ side of the function (C++
only lets you put it
On Wed, Jan 25, 2012 at 11:50:57PM +0100, Timon Gehr wrote:
On 01/25/2012 02:29 AM, H. S. Teoh wrote:
[...]
But since Walter doesn't like the idea of restricting the syntax to 'int
y() const', then what about making it mandatory to write:
const(int) x;
instead of:
const int
On 01/26/2012 12:35 AM, H. S. Teoh wrote:
On Wed, Jan 25, 2012 at 11:50:57PM +0100, Timon Gehr wrote:
On 01/25/2012 02:29 AM, H. S. Teoh wrote:
[...]
But since Walter doesn't like the idea of restricting the syntax to 'int
y() const', then what about making it mandatory to write:
and f2? If not, which is the preferred
syntax? If yes, what is the meaning of 'const' in either case?
I tried various code inside f1 and f2, and it seems in both of them I
can't change x, which appears to mean that 'const' in this case refers
to immutability of the class object? Is this correct
On Tue, Jan 24, 2012 at 07:06:47PM -0500, Jonathan M Davis wrote:
[...]
So, while a C++ programmer expects that
int f2() const
means that f2 is const, they're likely to be surprised by the fact that in
const int f1()
it's the int that's const, not f1.
[...]
Wait, I thought 'const int
Jonathan M Davis:
Now, the confusing part is the fact that unlike C++, D allows you to put the
const for making the function on the _left-hand_ side of the function (C++
only lets you put it on the right). This is to increase consistency between
modifers (public, override, pure, etc.) -
16 matches
Mail list logo