Re: various questions

2010-07-30 Thread Rory Mcguire
Jason Spencer wrote: Ok, I've gone over this, adapted it, and mostly understand it. I just have one question left: == Quote from bearophile (bearophileh...@lycos.com)'s article template Iota(int stop) { ... alias TypeTuple!(Iota!(stop-1), stop-1) Iota; } ... foreach (t;

Re: various questions

2010-07-30 Thread Jason Spencer
== Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article Jason Spencer wrote: I nievely went and replaced foreach (t; Iota!(str_types.length)) with foreach (t; str_types.length), since the length of that array is known at compile-time. your replacement tries to loop over an uint

Re: various questions

2010-07-30 Thread Rory Mcguire
Jason Spencer wrote: == Quote from Rory Mcguire (rjmcgu...@gm_no_ail.com)'s article Jason Spencer wrote: I nievely went and replaced foreach (t; Iota!(str_types.length)) with foreach (t; str_types.length), since the length of that array is known at compile-time. your replacement

Re: Wanting an immutable associative array in a class

2010-07-30 Thread Lars T. Kyllingstad
On Thu, 29 Jul 2010 22:55:35 -0400, bearophile wrote: RedZone: But it would be nice if I could have the array reference itself be immutable and not just the array's contents. Is there any way I could do this? Let's say your code is as your second example: class Foo { private:

Re: various questions

2010-07-30 Thread bearophile
Jason Spencer: I nievely went and replaced foreach (t; Iota!(str_types.length)) with foreach (t; str_types.length), since the length of that array is known at compile-time. That of course bombed, but I don't quite get why. Is the compiler actually evaluating the foreach loop at compile

Re: alias = compile-time variants?

2010-07-30 Thread Philippe Sigaud
On Thu, Jul 29, 2010 at 22:40, Jason Spencer spenc...@sbcglobal.net wrote: In writing templates that make heavy use of alias parameters, does anyone else feel uneasy about whether the caller will pass a type, a value, or a schmoo? I thought they could only be symbols. That is, an alias is a

string initialization question.

2010-07-30 Thread dcoder
Hello. Is there anyway in D to convenient fill a string variable with a char say X times? So, I'd like to do something like: string divider( size, '-');// C++ notation. $divider = '-' x $size;// perl notation. I thought I could do the following: const char divider[rowstr.length]

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 11:24:41 -0400, dcoder dco...@devnull.com wrote: Hello. Is there anyway in D to convenient fill a string variable with a char say X times? So, I'd like to do something like: string divider( size, '-');// C++ notation. $divider = '-' x $size;// perl

Re: string initialization question.

2010-07-30 Thread Justin Spahr-Summers
On Fri, 30 Jul 2010 11:35:15 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: On Fri, 30 Jul 2010 11:24:41 -0400, dcoder dco...@devnull.com wrote: Hello. Is there anyway in D to convenient fill a string variable with a char say X times? So, I'd like to do something like:

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 11:46:32 -0400, Justin Spahr-Summers justin.spahrsumm...@gmail.com wrote: On Fri, 30 Jul 2010 11:35:15 -0400, Steven Schveighoffer schvei...@yahoo.com wrote: If you want to allocate a new array on the heap with '-' in it, I think there is a way, but I'm not sure how to

Re: string initialization question.

2010-07-30 Thread bearophile
Steven Schveighoffer: char[] divider = new char[5]; divider[] = '-'; That assigns 0xff to all divider chars, and then assigns '-'. I think there's a way to do it without the initial assignment. In past there was some way to do that: typedef char mchar = '-'; mchar[] divider =

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 12:46:20 -0400, bearophile bearophileh...@lycos.com wrote: Steven Schveighoffer: char[] divider = new char[5]; divider[] = '-'; That assigns 0xff to all divider chars, and then assigns '-'. I think there's a way to do it without the initial assignment. I was

xfbuild, optlink and pragma(lib)

2010-07-30 Thread Mafi
Hi, I wanted to create an simple wrapper around SDL. After my simple first steps, I wanted to create a simple application using my wrapper. That's it: /// module test; import std.stdio; import mysdl.system; //pragma(lib,rPath\to\SDL\lib\libSDLmain.a);

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: I think a function to do it is fine, like makeArray('-', 5); Well, creating a function for producing an array literal and returning it using templates and string mixins wouldn't be all that hard, but if you want to create a dynamic

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 15:56:36 -0400, Jonathan M Davis jmdavisp...@gmail.com wrote: On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: I think a function to do it is fine, like makeArray('-', 5); Well, creating a function for producing an array literal and returning it using

Re: string initialization question.

2010-07-30 Thread bearophile
Jonathan M Davis: a makeArray() function would have exactly the same tools that you have to create an array of all the same value. So, it's not going to be any more efficient that what you can do. Doesn't the D2 GC give you a lower level function to GC-allocate uninitialized memory? The

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 17:24:41 dcoder dco...@devnull.com napisał(a): Is there anyway in D to convenient fill a string variable with a char say X times? If you need to only print, you can: import std.stdio; import std.range; void main() { foreach (c; take(repeat('-'), 5)) write(c);

Re: string initialization question.

2010-07-30 Thread Tomek Sowiński
Dnia 30-07-2010 o 22:15:50 Tomek Sowiński j...@ask.me napisał(a): writeln('-'.repeat.take(5)); Oh, and if repeat had slicing (as it should)... '-'.repeat[0..5] Still, it's far cry from Python's '-' * 5 Tomek

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 13:10:46 Steven Schveighoffer wrote: On Fri, 30 Jul 2010 15:56:36 -0400, Jonathan M Davis jmdavisp...@gmail.com wrote: On Friday, July 30, 2010 10:14:45 Steven Schveighoffer wrote: I think a function to do it is fine, like makeArray('-', 5); Well, creating a

Re: string initialization question.

2010-07-30 Thread Steven Schveighoffer
On Fri, 30 Jul 2010 16:31:49 -0400, Jonathan M Davis jmdavisp...@gmail.com wrote: On Friday, July 30, 2010 13:10:46 Steven Schveighoffer wrote: It's not. The only runtime functions available to the compiler look like this: _d_newarrayT(TypeInfo ti, size_t length); I guess that's one

Re: string initialization question.

2010-07-30 Thread dcoder
== Quote from Jonathan M Davis (jmdavisp...@gmail.com)'s article A makeArray() function wouldn't hurt any, but I don't think that it would really buy us much. Of course, truth be told, I've always thought that the ability to construct a string or vector in C++ all of a single value was pretty

Re: string initialization question.

2010-07-30 Thread Philippe Sigaud
I don't know where such a tool should finally be placed in D, but I having it available as a library or as part of the language would be great. It seems like a lot of other languages have it like python, perl, C++, and Java. So it can't be that useless. There is fill() in

Re: string initialization question.

2010-07-30 Thread Jonathan M Davis
On Friday, July 30, 2010 14:13:15 dcoder wrote: If I'm writing a program that pretty prints tree data, or output of sql, like Oracle's sqlplus, or postgres equivalent, I find having such a utility function/constructor a pretty handy feature. I don't know where such a tool should finally be