Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
ketmar via Digitalmars-d-learn wrote: On Sat, 03 Jan 2015 14:45:24 +1030 ted via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 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

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
via Digitalmars-d-learn wrote: On Sat, 03 Jan 2015 13:25:31 +1030 ted via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 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

Re: cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
ketmar via Digitalmars-d-learn wrote: On Sat, 03 Jan 2015 15:56:58 +1030 ted via Digitalmars-d-learn digitalmars-d-learn@puremagic.com 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

Re: cannot modify struct with immutable members

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

cannot modify struct with immutable members

2015-01-02 Thread ted via Digitalmars-d-learn
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 !

Re: cannot modify struct with immutable members

2015-01-03 Thread ted via Digitalmars-d-learn
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 const

Re: Weird UFC and opCall issues

2015-01-03 Thread ted via Digitalmars-d-learn
Darrell wrote: Seems when creating your own ranges they can't be a class. Must be a struct or Segmentation fault (core dumped) will follow. This works as long as Test is a struct. struct Test { @property int front() { return 2; } void popFront() { }

cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
Hi! I get the following compile error (linux, dmd2.066.1): test.d(13): Error: template test.testFunc cannot deduce function from argument types !()(double[], double), candidates are: test.d(3):test.testFunc(R)(R range, ElementType!R foo) For the following test file: import std.range:

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
Ali Çehreli wrote: On 02/10/2015 12:31 AM, ted wrote: ElementType!R testFunc(R)( R range, ElementType!R foo) // compiles with double foo If think it is a little too much to ask from the template system of D. A proper way of doing the same thing is to use a template constraint:

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
bearophile wrote: ted: Could someone enlighten me ? This works: import std.range: ElementType, isInputRange; ElementType!R testFunc(R, T)(R range, T foo) if (is(ElementType!R == T)) { static assert(isInputRange!R); typeof(return) retVal = foo ^^ 2; // More DRY.

Re: cannot deduce function from argument types issue.

2015-02-10 Thread ted via Digitalmars-d-learn
bearophile wrote: ted: ... where you say 'More DRY' above, are you referring to I was referring to both, but mostly to the typeof. It's more DRY (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself ). You are stating only once the type of the return variable. This is less bug-prone.

SList container problem

2015-08-13 Thread ted via Digitalmars-d-learn
have upgraded from 2.066.1 to 2.068.0, and have a change in behaviour: import std.container: SList; void main() { SList!int tmp; tmp.insertAfter( tmp[], 3 ); } used to work happily with dmd2.066.1, causes assert (core.exception.AssertError@std/container/slist.d(57): Assertion

Re: Templates and writing variable number of arguments

2015-08-23 Thread ted via Digitalmars-d-learn
try replacing: final void output(T)(string text, T params...) const { with final void output(T...)(string text, T params) const { Andre Polykanine via Digitalmars-d-learn wrote: Hi everyone, It's me again. Now I'm struggling with the `output` member function which should

Re: A better way than foreach with this?

2015-08-24 Thread ted via Digitalmars-d-learn
try: auto names1 = names.map!( a = replace(a, _, )); ...not sure how to do it in-place though. Joel wrote: auto names = Alef Bet Gimel Dalet He Vav Zayen Het Tet Yod Final_Kaf Kaf Lamed Final_Mem Mem Final_Nun Nun Samekh Ayin Final_Pe Pe Final_Tsadi Tsadi Qof Resh Shin Tav.split;

Re: SList container problem

2015-08-14 Thread ted via Digitalmars-d-learn
thanks for the reply... the method you described is suitable for appending to an array, but I'm using the singly-linked-list container. I've extended the test, and I'm pretty sure it's a bug... --ted Nicholas Wilson wrote: On Thursday, 13 August 2015 at 08:40:13 UTC, ted wrote: have