Ali Çehreli wrote:
> On 01/02/2015 10:10 PM, ted wrote:
>
> > I'm now taking the view that const is there for the compiler to
> > optimise code on the basis that nothing can alter it once set (and can
> > only be set on initialisation).
>
> Of course, that is true for const values, not for co
On Sat, 03 Jan 2015 01:00:58 -0800
Ali Çehreli via Digitalmars-d-learn
wrote:
> On 01/02/2015 09:07 PM, ketmar via Digitalmars-d-learn wrote:
>
> > structure instance with const fields can be initialized only once, upon
> > creation. so did `Test myTest1;` -- you initialized `myTest1` with
>
On 01/02/2015 10:10 PM, ted wrote:
> I'm now taking the view that const is there for the compiler to optimise
> code on the basis that nothing can alter it once set (and can only be set
> on initialisation).
Of course, that is true for const values, not for const references. In
the latter case
On 01/02/2015 09:07 PM, ketmar via Digitalmars-d-learn wrote:
> structure instance with const fields can be initialized only once, upon
> creation. so did `Test myTest1;` -- you initialized `myTest1` with
> default values. you can't reinitialize it later.
>
> in C++ constness on member doesn't im
On Sat, 03 Jan 2015 16:40:14 +1030
ted via Digitalmars-d-learn wrote:
> I'm now taking the view that const is there for the compiler to optimise
> code on the basis that nothing can alter it once set (and can only be set
> on initialisation). So I see your point that it would not be used very
ketmar via Digitalmars-d-learn wrote:
> On Sat, 03 Jan 2015 15:56:58 +1030
> ted via Digitalmars-d-learn wrote:
>
>> Ironically, I'm trying to use const in an effort to understand it...but
>> there seems to be an unusual amount of pain until I grok it.
> just remember that `const` "infects" ever
On Sat, 03 Jan 2015 15:56:58 +1030
ted via Digitalmars-d-learn wrote:
> Ironically, I'm trying to use const in an effort to understand it...but
> there seems to be an unusual amount of pain until I grok it.
just remember that `const` "infects" everything down to the bytes when
it's applied. and
ketmar via Digitalmars-d-learn wrote:
> On Sat, 03 Jan 2015 14:45:24 +1030
> ted via Digitalmars-d-learn wrote:
>
>> Well, I just cleared up some of my misunderstanding.
>>
>> I did not realise the mA (within struct Test) would be a _copy_ of arg,
>> not a reference (pointer) to arg.
>>
>> So
On Sat, 03 Jan 2015 14:45:24 +1030
ted via Digitalmars-d-learn wrote:
p.s. also please note that structs in D are always passed by value and
copied (until you not explicitly ask for something another). so:
MyStruct a;
MyStruct b;
b = a;
actually does `memcpy()` (with postblit if there is
On Sat, 03 Jan 2015 14:45:24 +1030
ted via Digitalmars-d-learn wrote:
> Well, I just cleared up some of my misunderstanding.
>
> I did not realise the mA (within struct Test) would be a _copy_ of arg, not
> a reference (pointer) to arg.
>
> So the more correct code snippet would be:
>
> stru
Well, I just cleared up some of my misunderstanding.
I did not realise the mA (within struct Test) would be a _copy_ of arg, not
a reference (pointer) to arg.
So the more correct code snippet would be:
struct A
{
int someInt;
}
struct Test
{
@property { const(A) getA() { return *mA;
Hi,
thanks for the reply...to answer your direct question, the original code
looked like:
struct A
{
int someInt;
}
struct Test
{
@property { const(A) getA() { return mA; } }
this( ref const(A) arg )
{
mA = arg;
}
private:
A mA;
}
void main()
{
Test myTest
On Sat, 03 Jan 2015 13:25:31 +1030
ted via Digitalmars-d-learn wrote:
>
> I get the following error from the code below: (dmd2.066.1, linux)
> test.d(26): Error: cannot modify struct myTest1 Test with immutable members
>
> Is this expected?
>
> If so, how can I achieve this result - being able
I get the following error from the code below: (dmd2.066.1, linux)
test.d(26): Error: cannot modify struct myTest1 Test with immutable members
Is this expected?
If so, how can I achieve this result - being able to set (a new) initial value
of myTest1 from within an nested function ?
thanks !
t
14 matches
Mail list logo