Re: Convert string to wchar.

2011-08-02 Thread Jonathan M Davis
On Wednesday 03 August 2011 08:29:09 Jacob Carlborg wrote: > On 2011-08-02 19:51, Jonathan M Davis wrote: > >> I tried to convert a string into a wchar, but that didn't compile > >> because of this template constraint: > >> > >> https://github.com/D-Programming-Language/phobos/blob/master/std/conv

Re: Convert string to wchar.

2011-08-02 Thread Jacob Carlborg
On 2011-08-02 19:51, Jonathan M Davis wrote: I tried to convert a string into a wchar, but that didn't compile because of this template constraint: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L17 70 Is there a way to convert a string into a wchar? Does that even ma

Re: Hexadecimal string to integer

2011-08-02 Thread Johann MacDonagh
On 8/2/2011 8:17 PM, Stijn Herreman wrote: std.conv does not support conversion from a hexadecimal string to an integer. Is there a technical reason for this limitation? This is the best I could do, can it be improved still? int i = to!int(parse!float("0x1ap0")); parse!int("1a", 16);

Hexadecimal string to integer

2011-08-02 Thread Stijn Herreman
std.conv does not support conversion from a hexadecimal string to an integer. Is there a technical reason for this limitation? This is the best I could do, can it be improved still? int i = to!int(parse!float("0x1ap0"));

Re: Template specification conflict

2011-08-02 Thread Jonathan M Davis
> On 02.08.2011 16:18, simendsjo wrote: > > On 02.08.2011 14:13, Dmitry Olshansky wrote: > >> On 02.08.2011 16:06, simendsjo wrote: > >>> On 02.08.2011 13:55, Dmitry Olshansky wrote: > On 02.08.2011 15:06, simendsjo wrote: > > The following program gives me > > "Error: template t.S.__c

Re: Convert string to wchar.

2011-08-02 Thread Jonathan M Davis
> I tried to convert a string into a wchar, but that didn't compile > because of this template constraint: > > https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L17 > 70 > > Is there a way to convert a string into a wchar? Does that even make sense? What do you want it to d

Convert string to wchar.

2011-08-02 Thread Jacob Carlborg
I tried to convert a string into a wchar, but that didn't compile because of this template constraint: https://github.com/D-Programming-Language/phobos/blob/master/std/conv.d#L1770 Is there a way to convert a string into a wchar? -- /Jacob Carlborg

Re: String conversion functions in Phobos

2011-08-02 Thread Jonathan M Davis
On Tuesday 02 August 2011 13:46:54 simendsjo wrote: > On 02.08.2011 12:27, Jonathan M Davis wrote: > > On Tuesday 02 August 2011 12:15:00 simendsjo wrote: > >> On 02.08.2011 12:07, Jonathan M Davis wrote: > >>> The github version has std.utf.toUTFz > >> > >> Thanks, I'll try that. > >> What about

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 14:22, Dmitry Olshansky wrote: On 02.08.2011 16:18, simendsjo wrote: On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: temp

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 15:25, Dmitry Olshansky wrote: On 02.08.2011 16:30, simendsjo wrote: On 02.08.2011 14:22, Dmitry Olshansky wrote: On 02.08.2011 16:18, simendsjo wrote: On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 15:25, Dmitry Olshansky wrote: Most definitely a bug, you seem to hit a lot of 'em recently :) Yeah :( The biggest reason I left D back in the days. Compiler bugs whenever I did anything more than simple tests, and breaking changes with each release so I had to change a lot of

Re: Generate array of random values

2011-08-02 Thread David Nadlinger
On 8/2/11 6:42 AM, Jesse Phillips wrote: auto arr = new int[1024]; fill(arr, randomCover(iota(0,1024), rndGen)); Note that this produces a random permutation of the numbers 0 to 1023, which may or may not be what you want. David

Re: Template specification conflict

2011-08-02 Thread Dmitry Olshansky
On 02.08.2011 16:30, simendsjo wrote: On 02.08.2011 14:22, Dmitry Olshansky wrote: On 02.08.2011 16:18, simendsjo wrote: On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The

Re: Generate array of random values

2011-08-02 Thread bearophile
Andrej Mitrovic: > Maybe.. > > auto max = 1024; > auto len = 1024; > > arr = rndRange(max)[0..len]; In my opinion that's not general enough for Phobos, see the N dimensional table() I have explained here: auto arr = table!q{ uniform(0, 1024) }(1024); http://www.digitalmars.com/webnews/newsgro

Re: Minimum value in a range

2011-08-02 Thread bearophile
Andrej Mitrovic: > import std.algorithm; > > void main() > { > auto x = min([1, 2, 3]); // x would be 1 > } > > min() isn't equipped to do this on a single range. What can I use > instead? I haven't had my coffee yet. :) See: http://d.puremagic.com/issues/show_bug.cgi?id=4705 Bye, bearoph

Re: Minimum value in a range

2011-08-02 Thread simendsjo
On 02.08.2011 14:42, Andrej Mitrovic wrote: Oh just realized I can use the much simpler: auto x = reduce!(min)([1, 2, 3]); Coffee is starting to kick in! Of course. I even had a lot of coffee running through my veins, so shame on me!

Re: Minimum value in a range

2011-08-02 Thread Andrej Mitrovic
Oh just realized I can use the much simpler: auto x = reduce!(min)([1, 2, 3]); Coffee is starting to kick in!

Re: Minimum value in a range

2011-08-02 Thread Andrej Mitrovic
Does anyone know why putting this alias in module scope errors out?: import std.algorithm; alias reduce!((a, b){ return 1; }) foo; void main() { foo([1, 2, 3]); } Error: delegate test.__dgliteral1!(int,int).__dgliteral1 is a nested function and cannot be accessed from reduce But this will

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 14:22, Dmitry Olshansky wrote: On 02.08.2011 16:18, simendsjo wrote: On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: temp

Re: Minimum value in a range

2011-08-02 Thread Andrej Mitrovic
On 8/2/11, simendsjo wrote: > assert(reduce!"min(a,b)"([1,2,3]) == 1); Thanks!

Re: Template specification conflict

2011-08-02 Thread Dmitry Olshansky
On 02.08.2011 16:18, simendsjo wrote: On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflict

Re: Generate array of random values

2011-08-02 Thread Andrej Mitrovic
Woops you're right about the range type being returned. I guess this is the next best thing: arr = array(rndRange(max, len));

Re: Generate array of random values

2011-08-02 Thread Dmitry Olshansky
On 02.08.2011 16:08, Andrej Mitrovic wrote: On 8/2/11, Pelle wrote: Without UFCS, well, how would you want it to look? Maybe.. auto max = 1024; auto len = 1024; arr = rndRange(max)[0..len]; IOW, using the slice operator instead of a call to array(). It could be done , but IMO a lot of gener

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 14:13, Dmitry Olshansky wrote: On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflicts with constructor t.S.this at t.d(4)"

Re: Template specification conflict

2011-08-02 Thread Dmitry Olshansky
On 02.08.2011 16:06, simendsjo wrote: On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflicts with constructor t.S.this at t.d(4)" Is this because char etc can be converted to

Re: Minimum value in a range

2011-08-02 Thread simendsjo
On 02.08.2011 14:03, Andrej Mitrovic wrote: import std.algorithm; void main() { auto x = min([1, 2, 3]); // x would be 1 } min() isn't equipped to do this on a single range. What can I use instead? I haven't had my coffee yet. :) import std.algorithm; void main() { assert(min(1, 2,

Re: Template specification conflict

2011-08-02 Thread simendsjo
On 02.08.2011 13:55, Dmitry Olshansky wrote: On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflicts with constructor t.S.this at t.d(4)" Is this because char etc can be converted to uint? Shouldn't the template specificat

Re: Generate array of random values

2011-08-02 Thread Andrej Mitrovic
On 8/2/11, Pelle wrote: > Without UFCS, well, how would you want it to look? Maybe.. auto max = 1024; auto len = 1024; arr = rndRange(max)[0..len]; IOW, using the slice operator instead of a call to array().

Minimum value in a range

2011-08-02 Thread Andrej Mitrovic
import std.algorithm; void main() { auto x = min([1, 2, 3]); // x would be 1 } min() isn't equipped to do this on a single range. What can I use instead? I haven't had my coffee yet. :)

Re: Template specification conflict

2011-08-02 Thread Dmitry Olshansky
On 02.08.2011 15:06, simendsjo wrote: The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflicts with constructor t.S.this at t.d(4)" Is this because char etc can be converted to uint? Shouldn't the template specification make this unambiguous? import std.tra

Re: String conversion functions in Phobos

2011-08-02 Thread simendsjo
On 02.08.2011 12:27, Jonathan M Davis wrote: On Tuesday 02 August 2011 12:15:00 simendsjo wrote: On 02.08.2011 12:07, Jonathan M Davis wrote: The github version has std.utf.toUTFz Thanks, I'll try that. What about the other way around? * to []? I believe that it'll work with char* to string

Template specification conflict

2011-08-02 Thread simendsjo
The following program gives me "Error: template t.S.__ctor(C) if(isSomeChar!(C)) conflicts with constructor t.S.this at t.d(4)" Is this because char etc can be converted to uint? Shouldn't the template specification make this unambiguous? import std.traits; struct S { this(uint i) {}

Re: String conversion functions in Phobos

2011-08-02 Thread Jonathan M Davis
On Tuesday 02 August 2011 12:15:00 simendsjo wrote: > On 02.08.2011 12:07, Jonathan M Davis wrote: > > The github version has std.utf.toUTFz > > Thanks, I'll try that. > What about the other way around? * to []? I believe that it'll work with char* to string with std.conv.to, but I think that's

Re: String conversion functions in Phobos

2011-08-02 Thread simendsjo
On 02.08.2011 12:07, Jonathan M Davis wrote: The github version has std.utf.toUTFz Thanks, I'll try that. What about the other way around? * to []?

Re: NaCl stable ABI

2011-08-02 Thread Alex Rønne Petersen
On 02-08-2011 05:20, Andrej Mitrovic wrote: Maybe it's a framework for Farmville on Google Plus. :p Then we must support it! - Alex

Re: String conversion functions in Phobos

2011-08-02 Thread Jonathan M Davis
On Tuesday 02 August 2011 12:02:07 simendsjo wrote: > I want to convert SomeChar[] or SomeChar* into > PerhapsAnotherCharNullTerminated*, but std.conv doesn't work like this. > char[] a = "ao"; > to!(wchar*)(a); // fails > > toUTF16z converts char[] to wchar* > toStringz converts char[] to char* >

String conversion functions in Phobos

2011-08-02 Thread simendsjo
I want to convert SomeChar[] or SomeChar* into PerhapsAnotherCharNullTerminated*, but std.conv doesn't work like this. char[] a = "ao"; to!(wchar*)(a); // fails toUTF16z converts char[] to wchar* toStringz converts char[] to char* Am I missing function(s), or do I have to combine them myself?

Re: Generate array of random values

2011-08-02 Thread Pelle
On Mon, 01 Aug 2011 21:43:13 +0200, Andrej Mitrovic wrote: Actually I don't really need *uniform* distribution, it's just that when porting C code to D I didn't find any obvious random()/rnd() functions, and uniform seemed to be the closest thing without having to mess around with a bunch of