Re: cannot implicitly convert char[] to string

2015-08-15 Thread Ali Çehreli via Digitalmars-d-learn
On 08/15/2015 04:45 AM, cym13 wrote: On Saturday, 15 August 2015 at 11:34:01 UTC, cym13 wrote: On Saturday, 15 August 2015 at 11:25:20 UTC, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto

Re: Template Collections of Different Types

2015-08-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 16 August 2015 at 02:42:18 UTC, BBasile wrote: --- enum Ti {tibyte, tiubyte, ...} Ti getTypeInfo(T)(T t){statif is(t == ubyte) return Ti.tibyte; else...} You could also just use D's own run time typeinfo with the typeid() thing. It returns an instance of class TypeInfo. (This is

Re: Use members of a Named Enum without using Enum name?

2015-08-15 Thread Ali Çehreli via Digitalmars-d-learn
On 08/15/2015 09:22 AM, QuizzicalFella wrote: On Saturday, 15 August 2015 at 15:53:23 UTC, Adam D. Ruppe wrote: On Saturday, 15 August 2015 at 15:37:42 UTC, QuizzicalFella wrote: I'd like to be able to call someFunc(TRIANGLE) rather than someFunc(PolygonT.TRIANGLE). Two options come to mind:

Re: Template Collections of Different Types

2015-08-15 Thread BBasile via Digitalmars-d-learn
On Sunday, 16 August 2015 at 01:39:54 UTC, DarthCthulhu wrote: Say I want to do something like: Propertery!int pi = 42; PropertyCollection pc; pc.attach(Life_and_Everything, pi); assert(pc.Life_and_Everything == 42); Property!string ps = Hello World; pc.attach(text, ps); assert(pc.text ==

Re: Attributes not propagating to objects via typeinfo?

2015-08-15 Thread rsw0x via Digitalmars-d-learn
On Friday, 14 August 2015 at 15:39:39 UTC, Timon Gehr wrote: I don't understand. It is evidently fixable. E.g. if TypeInfo was just a template without the mostly redundant additional compiler support, this would be a trivial fix. It appears that this was suggested already after a bit of

Re: Template Collections of Different Types

2015-08-15 Thread DarthCthulhu via Digitalmars-d-learn
On Sunday, 16 August 2015 at 01:51:36 UTC, Adam D. Ruppe wrote: On Sunday, 16 August 2015 at 01:39:54 UTC, DarthCthulhu wrote: How would one store the Property objects in the PropertyCollection? You don't, not like that anyway. The attach call is the ruin of it. If it was all one definition,

Re: using memset withing a pure function

2015-08-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 19:50:56 UTC, Temtaime wrote: There's a problem with « dst[0 .. n] = val; ». It should be « dst[0 .. n][] = val; » No, you don't need the `[]`.

Template Collections of Different Types

2015-08-15 Thread DarthCthulhu via Digitalmars-d-learn
Say I want to do something like: Propertery!int pi = 42; PropertyCollection pc; pc.attach(Life_and_Everything, pi); assert(pc.Life_and_Everything == 42); Property!string ps = Hello World; pc.attach(text, ps); assert(pc.text == Hello World); How would one store the Property objects in the

Re: Template Collections of Different Types

2015-08-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 16 August 2015 at 01:39:54 UTC, DarthCthulhu wrote: How would one store the Property objects in the PropertyCollection? You don't, not like that anyway. The attach call is the ruin of it. If it was all one definition, you could use something like std.typecons.Tuple, but multiple

Using replaceInPlace, string and char[]

2015-08-15 Thread TSalm via Digitalmars-d-learn
Hi, A newbie question : I wrote this simple code : import std.array; import std.stdio; void main() { char[] a = mon texte 1.dup; char[] b = abc.dup; size_t x = 4; size_t y = 9; replaceInPlace( a, x , y, b );

Re: Using replaceInPlace, string and char[]

2015-08-15 Thread TSalm via Digitalmars-d-learn
On Saturday, 15 August 2015 at 08:07:43 UTC, Ali Çehreli wrote: This looks like a bug to me. The template constraints of the two overloads are pretty complicated. This case should match only one of them. Yes I understand. I've used ldc2. With DMD (v0.067.1) the error is more clear :

Re: Using replaceInPlace, string and char[]

2015-08-15 Thread Ali Çehreli via Digitalmars-d-learn
This looks like a bug to me. The template constraints of the two overloads are pretty complicated. This case should match only one of them. On 08/15/2015 12:43 AM, TSalm wrote: Don't understand why this doesn't work: it compiles fine and runs perfectly if I change char[] by string You mean,

Re: using memset withing a pure function

2015-08-15 Thread D_Learner via Digitalmars-d-learn
On Saturday, 15 August 2015 at 01:13:02 UTC, Adam D. Ruppe wrote: On Saturday, 15 August 2015 at 01:09:15 UTC, D_Learner wrote: When writting a pure fucntion involving C non pure functions like memcpy() and memset() Those functions are pure already, and marked so in the newest dmd (and I

Re: using memset withing a pure function

2015-08-15 Thread anonymous via Digitalmars-d-learn
On Saturday, 15 August 2015 at 18:04:30 UTC, D_Learner wrote: memcpy(skip[0], skip[0]+shift, (m-shift)*(int.sizeof)); memset(skip[0]+(m-shift),0, shift*(int.sizeof)) I was thinking conversion would be :- skip[0 .. size-1] = skip[shift .. size-1 ]; //For the memcpy(); Those

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
On Saturday, 15 August 2015 at 11:25:20 UTC, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot implicitly convert

Re: cannot implicitly convert char[] to string

2015-08-15 Thread cym13 via Digitalmars-d-learn
On Saturday, 15 August 2015 at 11:34:01 UTC, cym13 wrote: On Saturday, 15 August 2015 at 11:25:20 UTC, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message:

Re: cannot implicitly convert char[] to string

2015-08-15 Thread Timon Gehr via Digitalmars-d-learn
On 08/15/2015 01:54 PM, Timon Gehr wrote: On 08/15/2015 01:25 PM, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot

Re: Using replaceInPlace, string and char[]

2015-08-15 Thread Ali Çehreli via Digitalmars-d-learn
On 08/15/2015 01:47 AM, TSalm wrote: Must create a ticket for it ? I think so. Unless others object in 10 minutes... :) In the other hand using string is not efficient since this certainly make a copy of the original string. Right ? This is better to use replaceInPlace with char[], but

Re: cannot implicitly convert char[] to string

2015-08-15 Thread Timon Gehr via Digitalmars-d-learn
On 08/15/2015 01:25 PM, vladde wrote: I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot implicitly convert expression (format(s =

cannot implicitly convert char[] to string

2015-08-15 Thread vladde via Digitalmars-d-learn
I made a PR to phobos where I modified `std.format.format`. https://github.com/D-Programming-Language/phobos/pull/3528 However the auto builder fails, with the error message: runnable/test23.d(1219): Error: cannot implicitly convert expression (format(s = %s, s)) of type char[] to string The

Use members of a Named Enum without using Enum name?

2015-08-15 Thread QuizzicalFella via Digitalmars-d-learn
I have a named enum that I'd like to keep named, that I'd like to use as a type, but every time I use a member I'd rather not write out the enum name. I have a situation like the following: enum PolygonT : byte { TRIANGLE, RECTANGLE, STAR } void someFunc(PolygonT shape) { //some stuff } I'd

Re: Use members of a Named Enum without using Enum name?

2015-08-15 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 15 August 2015 at 15:37:42 UTC, QuizzicalFella wrote: I'd like to be able to call someFunc(TRIANGLE) rather than someFunc(PolygonT.TRIANGLE). Two options come to mind: alias TRIANGLE = PolygonT.TRIANGLE; // etc Or at the usage site: with(PolygonT) { someFunc(TRIANGLE); } I

Re: Use members of a Named Enum without using Enum name?

2015-08-15 Thread QuizzicalFella via Digitalmars-d-learn
On Saturday, 15 August 2015 at 15:53:23 UTC, Adam D. Ruppe wrote: On Saturday, 15 August 2015 at 15:37:42 UTC, QuizzicalFella wrote: I'd like to be able to call someFunc(TRIANGLE) rather than someFunc(PolygonT.TRIANGLE). Two options come to mind: alias TRIANGLE = PolygonT.TRIANGLE; // etc

Re: using memset withing a pure function

2015-08-15 Thread Temtaime via Digitalmars-d-learn
There's a problem with « dst[0 .. n] = val; ». It should be « dst[0 .. n][] = val; »

Re: using memset withing a pure function

2015-08-15 Thread D_Learner via Digitalmars-d-learn
On Saturday, 15 August 2015 at 18:49:15 UTC, anonymous wrote: On Saturday, 15 August 2015 at 18:04:30 UTC, D_Learner wrote: [...] Those two slices have different lengths (when shift != 0). They must have equal lengths, and they must not overlap. [...] Am now sorted. Thanks, your workout