Semicolon can be left out after do-while

2011-04-12 Thread Timon Gehr
I just noticed a little oddity. Why does this code compile? The equivalent C code is rejected: import std.stdio; //#include int main(){ int a,b; do{ scanf("%d %d",&a,&b); }while(ahttp://www.digitalmars.com/d/2.0/statement.html#DoStatement)

Questions to template overload resolution

2011-04-12 Thread Timon Gehr
1) T foo(T:SomeClass)(T arg){..} It is specified on the main page that this template will match against instantiations with a subclass of SomeClass. Will this also duplicate the code? Or will the template work similar to the function T foo(SomeClass arg){..}? If yes, why should normal functions and

Re: So why doesn't popFront return an element?

2011-04-14 Thread Timon Gehr
> I'm trying to understand the design of ranges. Why does popFront only set the front() property to return the next element in the range? Why not return the element in the call to popFront right away? > > For example code like this (which doesn't work since popFront doesn't return): > void main() >

Re: So why doesn't popFront return an element?

2011-04-14 Thread Timon Gehr
Andrei Mitrovic: > Can the compiler optimize the second case and convert b.front to just do one field access? In simple cases, obviously yes: import std.range; import std.stdio; void main(){ int[] a=new int[1000]; auto b=retro(retro(a)); writeln(b.front); } Produces: .text:08094B64

Re: So why doesn't popFront return an element?

2011-04-14 Thread Timon Gehr
> Nah, it's simpler than that: > > assert(is(typeof(b) == int[])); > > which is done by retro (it detects if you're retro-ing a retro range, and > just returns the original). > > -Steve Makes sense. But still, I think inlining is responsible for the following code generating identical machine code

Re: un-requested compiler optimisations

2011-04-14 Thread Timon Gehr
> Should the compiler optimise by computing n only once? (even possibly at compile-time) > Then, what if I'm doing that in purpose? (be it stupid or not) > > Denis What is the difference? The only thing that is affected by this optimization is execution speed. Optimizing is about implementing the

Re: object.function()

2011-05-13 Thread Timon Gehr
> I have a question, > can I write all functions like this object.function() instead of > functin(object) ? > or that form for some function or cases. This currently only works for D arrays. (I think Walter&Andrei wanted it for other types too originally, I do not know if it will be implemented.

Re: correct way to create boiler plate code

2011-05-16 Thread Timon Gehr
> I am parsing some formulas from a spreadsheet file. To duplicate > the behavior of the spreadsheet functions, I am having to create a > lot of boiler plate code that maps from the spreadsheet functions > to the built-in functions. Mixin would seem to allow me to > automate the boiler-plate creati

Re: Interface/abstract constructors

2011-05-16 Thread Timon Gehr
> Hey guys, > > is there any chance to create an abstract constructor like: > > abstract class ABC { > >abstract this(); > > } > > DMD always says "...this non-virtual functions cannot be abstract" - > when I use an interface like: > > interface ABC { > >this(); > > } > > I get a similar er

Re: What is this strange alias syntax?

2011-05-22 Thread Timon Gehr
Andrej Mitrovic wrote: > Should I file a bug report to kill this syntax? No. It is perfectly valid, see grammar: http://www.digitalmars.com/d/2.0/declaration.html What is strange about this syntax in particular? int i; //declares i of type "int" alias int i; //defines i as type "int" int func(i

Re: What is this strange alias syntax?

2011-05-22 Thread Timon Gehr
> On 22/05/2011 16:20, Timon Gehr wrote: >> Andrej Mitrovic wrote: >>> Should I file a bug report to kill this syntax? >> >> No. It is perfectly valid, see grammar: >> http://www.digitalmars.com/d/2.0/declaration.html > > Grammar states only that it'

Re: How to break module into multiple file.

2011-05-23 Thread Timon Gehr
On 2011-05-23 00:09, Matthew Ong wrote: > On 5/21/2011 7:16 PM, Russel Winder wrote: > > On Sat, 2011-05-21 at 04:35 -0400, Nick Sabalausky wrote: > > [ . . . ] > > > >> Subversion handles multiple people editing the same file perfectly fine. > >> But Hg probably is better than SVN, overall. I've b

Re: What is this strange alias syntax?

2011-05-23 Thread Timon Gehr
ou need it. There is currently no alternative for the alias. > > I'll throw it back at you, do you see a good use case for it? And no, > porting C code isn't a good use case. > > -Steve There are no alias in C code. I actually gave one: Timon Gehr wrote: > al

Re: What is this strange alias syntax?

2011-05-23 Thread Timon Gehr
Steven Schveighoffer wrote: > On Mon, 23 May 2011 10:50:11 -0400, Andrej Mitrovic > wrote: > >> Since &main can't be a template value argument, maybe he meant this use >> case: >> >> alias int func(); >> >> void foo(alias T)() >> { > static assert(is(typeof(&T) == int function())); // fixed

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Timon Gehr
Jonathan M Davis wrote: > On 2011-05-30 12:49, simendsjo wrote: >> I'm having some problems trying to get the best of both worlds here. >> >> void f(Class c) { >>assert(c != null); >>// use c >> } >> >> In this example, we tell the compiler that c is never able to be null. >> The compiler c

Re: Helping the compiler with assumptions while using exceptions

2011-05-30 Thread Timon Gehr
> Timon Gehr: > >> The answer is yes, theoretically it could. (It would either have to have >> some very >> advanced code analysis caps, or would just have to treat enforce specially.) > > Id's not so advanced stuff. > > Bye, > bearophile You are

Re: nested comments

2011-05-30 Thread Timon Gehr
> commenting out code?? example please /+ /* this is code: */ int more_code; // more code code(more_code+even_more_code(1321)); +/

Re: How to do "cast(ubyte[4])some_uint" in D1?

2011-06-02 Thread Timon Gehr
> Nick Sabalausky: > >> In D2, I can treat a uint as an array of ubytes by doing this: >> >> uint num = /+...whatever...+/; >> ubyte[] = cast(ubyte[4])num; >> >> How do I do that in D1? > > Using a union is probably the safest way: > > union Uint2Ubyte { > uint u; > ubyte[4] b; > } > > By t

Re: Template error and parallel foreach bug?

2011-06-04 Thread Timon Gehr
I just found Project Euler, and tried to solve the first problem. https://gist.github.com/1007840 simendsjo wrote: > I did four implementations: template, ctfe, parallel foreach and > parallel map. > > The template implementation works on low numbers, but not on 1000 > (haven't checked when it fail

Re: So how exactly does one make a persistent range object?

2011-06-06 Thread Timon Gehr
Andrej Mitrovic wrote: >> On 6/6/11, Jonathan M Davis wrote: >> So, anything you do on your own could be polymorphic, but as soon as you >> get ranges from Phobos, you lose the polymorphism. > > Yeah, I've noticed that. I wouldn't want to loose the ability to call > into std.algorithm/std.range or

Re: Is it reasonable to learn D

2011-06-07 Thread Timon Gehr
Fabian wrote: > Dear D Community, > is it reasonable to learn D? > I've found a lot of good points for D but I've found a lot of negative > points too. I believe that I needn't to list all the point for D but I > want to give a few examples against learning D I've read in some German > and English

Re: Is it reasonable to learn D

2011-06-07 Thread Timon Gehr
Fabian wrote: > > The community does not grow if people stay away because it is small. > > Thank you for your answer. - You've got a big point! > > > I don't know about this but I think QtD and DWT are still being > > maintained? > > I can't see any changes on this web page: > http://www.dsource.or

Re: char[] to string

2011-06-11 Thread Timon Gehr
On 2011-06-10 19:56, Jonathan Sternberg wrote: > Why doesn't this work? > > import std.stdio; > > string copy_string(char [] input) > { > return input.dup; > } > > int main() > { > char [] buf = ['h', 'e', 'l', 'l', 'o']; > writeln( copy_string(buf) ); > } > > I want to do something mor

Re: + operators

2011-06-11 Thread Timon Gehr
Renoir wrote: > Sorry for the question but i'm an absolutely noob > I have: > > byte x = 10; > byte y = 3; > x = x + y; > > why compilers complains? > > Error: cannot implicitly convert expression (cast(int)x + cast(int) > y > ) of type int to byte > > Have i to make another cast to sum byte + byte

Re: enum sstring problem

2011-06-12 Thread Timon Gehr
Lloyd Dupont wrote: > I'm using 2.053 > this compile fine: > > enum : string > { > A = "hello", > B = "betty", > } > > > this doesn't! > > enum AA : string > { > A = "hello", > B = "betty", > } > > > Am I missing something? Named enum can't be typed? known bug?

Re: Strange behavior when concatenating array

2011-06-17 Thread Timon Gehr
Steven Schveighoffer wrote: > https://github.com/D-Programming-Language/druntime/pull/29 > > See if that helps. On my system, your code now results in your expected > output. > > -Steve If the compiler optimizes well enough the output given could be valid (it might construct the struct directly w

Re: Implicit conversion of unique objects to mutable and immutable

2011-06-22 Thread Timon Gehr
On Wed, 22 Jun 2011 00:02:55 +, Ali Çehreli wrote: > I wonder whether a UniqueRef object could be returned, which could allow > a single casting of its data to mutable or immutable at the call site. > Further casts could throw, but that would be a runtime solution. :-/ Further casts should re

Re: Operator Overloading and boilerplate code

2011-07-02 Thread Timon Gehr
Your example with reduced boilerplate code: struct DVECTOR2 { template Accepts(T){enum Accepts=is(T==DVECTOR2) || is(T==float) || is(T==D3DXVECTOR2) || is(T==POINT);} template isScalar(T){enum isScalar=is(T==float);} float x = 0f, y=0f; this()(float x, float y) { this.x = x; this.y = y;

Re: Minimum value in a range

2011-08-04 Thread Timon Gehr
Andrei Mitrovic wrote: > 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 c

Re: Multi-file byte comparison tool. What would you have done differently?

2011-08-04 Thread Timon Gehr
Kai Meyer wrote: > So the question is, how would you make it more D-ish? (Do we have a term > analogous to "pythonic" for D? :)) An easy first step to improve the D-Factor would be to replace all these for loops with foreach loops and ref foreach loops. -Timon

Re: const main args?

2011-08-12 Thread Timon Gehr
On 08/13/2011 01:04 AM, Adam Ruppe wrote: Jonathan M Davis wrote: const(T)[] maybe, but as soon as you use in, you can't use any range functions. That is, to me, the biggest problem with range functions and something that should be fixed. There's no defense for it aside from being the status

Re: Heap question

2011-08-13 Thread Timon Gehr
On 08/13/2011 03:44 PM, bearophile wrote: I'd like to create an empty heap, and then add to it an arbitrary (and statically unknown) number of items, keeping the heap invariant valid all the time (this means the heap invariant is valid after each item is added to the heap, so I am free to pop

Re: const main args?

2011-08-15 Thread Timon Gehr
On 08/15/2011 03:47 PM, Steven Schveighoffer wrote: On Fri, 12 Aug 2011 17:51:50 -0400, bearophile wrote: Steven Schveighoffer: > int main(in string[] args); What would be the purpose of this? Why do you use "in" in function arguments? To make sure you will not modify the given array. I t

Re: const main args?

2011-08-15 Thread Timon Gehr
On 08/15/2011 11:53 PM, Brad Roberts wrote: On Mon, 15 Aug 2011, Timon Gehr wrote: On 08/15/2011 03:47 PM, Steven Schveighoffer wrote: On Fri, 12 Aug 2011 17:51:50 -0400, bearophile wrote: Steven Schveighoffer: int main(in string[] args); What would be the purpose of this? Why do

Re: how to enable core dumps for assert() triggering?

2011-08-16 Thread Timon Gehr
On 08/16/2011 02:48 AM, mimocrocodil wrote: subj try compiling to 32 bit with the -m32 flag in non-release mode. afaik the 64 bit compiler does not yet support core dumps. (if you are actually compiling to 32 bit then I don't know why you don't get a core dump and you'd have to provide more

Re: Throwing exception in constructor

2011-08-16 Thread Timon Gehr
On 08/16/2011 07:08 PM, Stijn Herreman wrote: Why is the return statement required, while nothing after the Exception is executed? Error: one path skips constructor public this(string p1, string p2, string p3) { string json = download_string(...); if (json is null) { throw new Exception("404");

Re: COFF support for windows compiler

2011-08-16 Thread Timon Gehr
On 08/16/2011 07:53 PM, Klimov Max wrote: Do�developers�plan�to�realize�compilation�to�coff�format�on�windows? There�are�the�cases�when�i�have�to�use�visual�studio�compiler�that generates�coff�object�files.�For�example,�CUDA�compiler�now�support only�vc�cl�compiler.�That's�why�i�have�to�refuse�D,

Re: Removing entries from AAs

2011-08-19 Thread Timon Gehr
On 08/19/2011 02:01 PM, useo6 wrote: Hi, I've create a little example of my problem: module example; class ExampleClass { public { int mi; this(int i) { mi = i; } } } int main(string[] args) {

Re: help understanding import libraries

2011-08-20 Thread Timon Gehr
On 08/20/2011 04:35 PM, Andrej Mitrovic wrote: On 8/20/11, maarten van damme wrote: Now only how come that "dmd hello.d" results in a 1.70 mb application whereas "dmd -c hello.d"&& "dmd hello.obj phobos.lib" results in a 144 kb app In both cases on my system it produces a 464Kb app. You must

Re: How do "pure" member functions work?

2011-08-20 Thread Timon Gehr
On 08/20/2011 06:24 PM, Sean Eskapp wrote: == Quote from David Nadlinger (s...@klickverbot.at)'s article On 8/20/11 5:13 PM, Sean Eskapp wrote: Does marking a member function as pure mean that it will return the same result given the same parameters, or that it will give the same result, given

Re: help understanding import libraries

2011-08-20 Thread Timon Gehr
On 08/20/2011 06:27 PM, Timon Gehr wrote: On 08/20/2011 04:35 PM, Andrej Mitrovic wrote: On 8/20/11, maarten van damme wrote: Now only how come that "dmd hello.d" results in a 1.70 mb application whereas "dmd -c hello.d"&& "dmd hello.obj phobos.lib" resu

Re: Why aren't function attributes inferred?

2011-08-20 Thread Timon Gehr
On 08/20/2011 06:50 PM, Sean Eskapp wrote: Since the compiler can clearly tell when a function is not const, safe, pure, or nothrow, why can't they just be assumed, unless proven otherwise? This sort of inference is already done for function/delegate literals and template functions. It is no

Re: Regarding nothrow and @safe

2011-08-20 Thread Timon Gehr
On 08/20/2011 08:18 PM, Sean Eskapp wrote: bearophile: As far as I know they have decided to make memory overflow errors, so they are not exceptions, you can't catch them. Other people will confirm this or not. In this case, how would you go about handling out-of-memory situations? A systems

Re: Regarding nothrow and @safe

2011-08-20 Thread Timon Gehr
On 08/20/2011 08:25 PM, Sean Eskapp wrote: == Quote from Timon Gehr (timon.g...@gmx.ch)'s article On 08/20/2011 08:18 PM, Sean Eskapp wrote: bearophile: As far as I know they have decided to make memory overflow errors, so they are not exceptions, you can't catch them. Other p

Re: How do "pure" member functions work?

2011-08-21 Thread Timon Gehr
On 08/21/2011 09:10 PM, Don wrote: bearophile wrote: Sean Eskapp: Oh, I see, thanks! This isn't documented in the function documentation! D purity implementation looks like a simple thing, but it's not simple, it has several parts that in the last months have be added to the language and com

Re: An issue with templates with non-existant symbols

2011-08-22 Thread Timon Gehr
On 08/22/2011 04:16 AM, Andrej Mitrovic wrote: void foo(T)(T t) if(is(X == struct)) { } void main() { foo(4); } This prints out: test.d(9): Error: template test.foo(T) if (is(X == struct)) does not match any function template declaration test.d(9): Error: template test.foo(T) if (is(X ==

Re: How do "pure" member functions work?

2011-08-22 Thread Timon Gehr
On 08/22/2011 10:19 PM, Don wrote: Timon Gehr wrote: On 08/21/2011 09:10 PM, Don wrote: bearophile wrote: Sean Eskapp: Oh, I see, thanks! This isn't documented in the function documentation! D purity implementation looks like a simple thing, but it's not simple, it has several

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Timon Gehr
On 08/24/2011 07:40 PM, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...) { foreach (val; vals) { } } Very sim

Re: How do I simulate variadic parameters for template (range) functions?

2011-08-24 Thread Timon Gehr
On 08/24/2011 07:54 PM, Steven Schveighoffer wrote: On Wed, 24 Aug 2011 13:40:38 -0400, Andrej Mitrovic wrote: Here's what I can do with a variadic function: void main() { int[] a = [ 1, 2, 4, 7, 7, 2, 4, 7, 3, 5]; process(a[a.countUntil(7) .. $]); process(1); } void process(int[] vals...)

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio; class Foo { Foo parent; int state; this (int state) { this.state = state; } } v

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 09:21 PM, Andrej Mitrovic wrote: On 8/24/11, Timon Gehr wrote: it is usually faster in debug mode Huh.. How come? Well, not notably faster, but many compilers will emit something in the lines of mov eax, 1 test eax jnz beginning_of_loop if no optimizer is run, whereas

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/24/2011 09:36 PM, Jonathan M Davis wrote: On Wednesday, August 24, 2011 21:29:23 Timon Gehr wrote: On 08/24/2011 09:21 PM, Andrej Mitrovic wrote: On 8/24/11, Timon Gehr wrote: it is usually faster in debug mode Huh.. How come? Well, not notably faster, but many compilers will emit

Re: Why no (auto foo = bar) in while loops?

2011-08-24 Thread Timon Gehr
On 08/25/2011 12:47 AM, Mafi wrote: Am 24.08.2011 21:04, schrieb Timon Gehr: On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parents" of some class object until it finds an object with no parent (where parent is null): import std.stdio;

Re: Why no (auto foo = bar) in while loops?

2011-08-25 Thread Timon Gehr
On 08/25/2011 01:11 PM, Steven Schveighoffer wrote: On Wed, 24 Aug 2011 19:01:31 -0400, Timon Gehr wrote: On 08/25/2011 12:47 AM, Mafi wrote: Am 24.08.2011 21:04, schrieb Timon Gehr: On 08/24/2011 08:04 PM, Andrej Mitrovic wrote: Here's some code that iterates through "parent

Re: Why no (auto foo = bar) in while loops?

2011-08-25 Thread Timon Gehr
On 08/25/2011 05:31 PM, Steven Schveighoffer wrote: > On Thu, 25 Aug 2011 11:15:44 -0400, Jonathan M Davis > wrote: > >> On Thursday, August 25, 2011 07:11:31 Steven Schveighoffer wrote: >>> > On 08/25/2011 12:47 AM, Mafi wrote: > >>> >> I'm not really sure if it's good for 'while'. >>> >> I'm un

Re: Why no (auto foo = bar) in while loops?

2011-08-25 Thread Timon Gehr
On 08/25/2011 10:51 PM, Steven Schveighoffer wrote: > On Thu, 25 Aug 2011 12:21:19 -0400, Timon Gehr wrote: > > >> >> I usually replace code like this: >> >> x++; >> if(x < 100) >> { >> // use x >> } >> >> with this: >

Re: Reading by character and by line from stdin

2011-08-25 Thread Timon Gehr
On 08/25/2011 11:34 PM, bellinom wrote: > Thanks for that, I didn't realize they were that far out of date. I use the latest > version of the compiler on my home PC, so I'd like to know the most current ways > of reading from stdin. > > Thanks Currently what you get is readf and readln with st

Re: Reading by character and by line from stdin

2011-08-25 Thread Timon Gehr
On 08/26/2011 12:19 AM, Timon Gehr wrote: On 08/25/2011 11:34 PM, bellinom wrote: > Thanks for that, I didn't realize they were that far out of date. I use the latest > version of the compiler on my home PC, so I'd like to know the most current ways > of reading from

Re: Why no (auto foo = bar) in while loops?

2011-08-25 Thread Timon Gehr
On 08/26/2011 12:38 AM, Steven Schveighoffer wrote: On Thu, 25 Aug 2011 17:31:26 -0400, Timon Gehr wrote: On 08/25/2011 10:51 PM, Steven Schveighoffer wrote: > On Thu, 25 Aug 2011 12:21:19 -0400, Timon Gehr wrote: > > >> >> I usually replace code like this: >

Re: Why no (auto foo = bar) in while loops?

2011-08-25 Thread Timon Gehr
On 08/26/2011 02:00 AM, Ali Çehreli wrote: On Thu, 25 Aug 2011 23:31:26 +0200, Timon Gehr wrote: for(init; condition; statement){} while(condition ){} That's a very interesting way of looking at the question. I bet that explains the other way around: there can't be

Re: Reading by character and by line from stdin

2011-08-25 Thread Timon Gehr
On 08/26/2011 06:12 AM, Joel Christensen wrote: On 26-Aug-11 10:20 AM, Timon Gehr wrote: On 08/26/2011 12:19 AM, Timon Gehr wrote: On 08/25/2011 11:34 PM, bellinom wrote: whoops, this is better: auto arr=to!(int[])(split(strip!(readln(; Or, auto arr2=to!(int[])( readln.strip.split

Re: Multiple subtyping

2011-08-25 Thread Timon Gehr
On 08/26/2011 05:45 AM, Joel Christensen wrote: Hi, Has anyone had much experience with multiple subtyping. //Org: based on page 232 (6.13.1) in The D Programming Language book //#save(); without storeShape does not work import std.stdio; class Shape { void shape() { writeln( "Shape" ); } } c

Re: How do I pass multidimensional static arrays to functions expecting dynamic arrays?

2011-08-29 Thread Timon Gehr
On 08/30/2011 01:29 AM, Andrej Mitrovic wrote: Take a look: void main() { int[2] single; // foo(single); // no foo(single[]); // int[2][] slice, ok int[2][2] multi; // bar(multi); // int[2][2] no // bar(multi[]); // int[2][] slice, no // bar(multi[][]

Re: How do I pass multidimensional static arrays to functions expecting

2011-08-30 Thread Timon Gehr
On 08/30/2011 03:20 AM, bearophile wrote: Timon Gehr: bar(array(map!((int[] a){return a;})(multi[]))); Simpler: bar( array(map!q{ a[] }(multi[])) ); And buggy. It returns slices of a local stack frame, because static arrays are value types. Simpler still when we'll get amap: bar(

Re: How do I pass multidimensional static arrays to functions expecting

2011-08-30 Thread Timon Gehr
On 08/30/2011 01:06 PM, bearophile wrote: Timon Gehr Wrote: On 08/30/2011 03:20 AM, bearophile wrote: Timon Gehr: bar(array(map!((int[] a){return a;})(multi[]))); Simpler: bar( array(map!q{ a[] }(multi[])) ); And buggy. It returns slices of a local stack frame, because static arrays are

Re: Const struct syntax

2011-08-30 Thread Timon Gehr
On 08/30/2011 01:19 PM, Jonathan M Davis wrote: On Tuesday, August 30, 2011 07:08:32 bearophile wrote: DMD 2.055head gives no compile-time errors on this, is this expected and good/acceptable? struct Foo { int x; this(int x_) { this.x = x_; } } void main() { auto f1 = new const(

Re: opDispatch shadowing toString - feature or bug?

2011-09-01 Thread Timon Gehr
On 09/01/2011 09:34 AM, Damian Ziemba wrote: Greetings. I've been playing around with opDispatch and toString methods and I found strange behavior. Example: import std.stdio; struct Test { string opDispatch( string key )() {

Re: Why does std.range.zip use emplace instead of simple assignments?

2011-09-01 Thread Timon Gehr
On 09/01/2011 10:23 AM, David Nadlinger wrote: It might well be that I'm missing something obvious in the emplace() overload jungle, but what is the reason for std.range.zip to use std.conv.emplace for assigning the range elements to the »output« elements instead of just using the assignment oper

Re: Is integer overflow defined?

2011-09-01 Thread Timon Gehr
On 09/01/2011 06:20 PM, Sean Eskapp wrote: Is integer overflow defined (for instance, as being mod 2^size)? I am quite sure that all operations are defined as operations on two's complement integers, which would mean overflow is defined, but I cannot find the respective part of the specificat

Re: opDispatch shadowing toString - feature or bug?

2011-09-01 Thread Timon Gehr
On 09/02/2011 12:09 AM, Damian Ziemba wrote: On Thu, 01 Sep 2011 13:59:29 +0200, Timon Gehr wrote: static assert(isInputRange!Test); static assert(isInputRange!Test2); toString is not shadowed, but the implementation of writeln assumes that your types are an InputRange (they provide, by the

Re: Is integer overflow defined?

2011-09-02 Thread Timon Gehr
On 09/02/2011 02:45 AM, bearophile wrote: Timon Gehr: according to TDPL p53., that fact is defined. (unary minus: -x == ~x+1) Uh. Bye, bearophile For unsigned integers it is clearly defined: 1000... => 0111... => 1000... And according to TDPL p53: "This manipulation doe

Re: Reduce help..

2011-09-02 Thread Timon Gehr
On 09/02/2011 07:11 PM, Andrej Mitrovic wrote: string[2][] results; results ~= ["foo", ""]; results ~= ["foobar", ""]; size_t len; foreach (res; results) { len = max(len, res[0].length); } That gives me '6'. I want to convert this to functional-style code with reduce. I've tried: len = re

Re: Copying a variable state in a delegate literal definition

2011-09-02 Thread Timon Gehr
On 09/02/2011 08:46 PM, Andrej Mitrovic wrote: Damn it looks like I've ran into some template bug as well. With this: @property void connect(Signal signal = Signal.MouseClick)(void delegate() dg) { clickHandlers ~= dg; } and a call like this: item.connect = { this.showMe

Re: Copying a variable state in a delegate literal definition

2011-09-02 Thread Timon Gehr
On 09/03/2011 01:13 AM, Andrej Mitrovic wrote: On 9/3/11, Timon Gehr wrote: What happens if you declare the function final? Doesn't help. But it has to be virtual as every object needs to have it's own set of delegates. So if I get you right, you made the templated version fina

Re: integer cast in object_.d

2011-09-04 Thread Timon Gehr
On 09/05/2011 04:57 AM, Andrej Mitrovic wrote: I'm looking at compare() in class TypeInfo_Array and it's defined as: override int compare(in void* p1, in void* p2) { void[] a1 = *cast(void[]*)p1; void[] a2 = *cast(void[]*)p2; size_t sz = value.tsize(); size_t len = a1.length;

Re: Default argument for template tuple function parameter

2011-09-06 Thread Timon Gehr
On 09/06/2011 01:01 PM, Vladimir Panteleev wrote: AddressInfo[] getAddressInfo(T...)(string node, string service = null, T options) TypeTuple!() emptyTuple; AddressInfo[] getAddressInfo(T...)(string node, string service = null, T options=emptyTuple) {} Error: cannot implicitly convert expre

Re: Forward a single field to a subfield, "alias this"-style?

2011-09-06 Thread Timon Gehr
On 09/06/2011 11:03 PM, Vladimir Panteleev wrote: What I'm trying to do: struct S1 { int f; } struct S2 { S1 s1; alias s1.f g; } This doesn't work. The declaration compiles, but attempts to access g result in: Error: struct test.S2 'f' is not a member Error: struct test.S2 member f is not acce

Re: What does ref means

2011-09-07 Thread Timon Gehr
On 09/07/2011 08:50 PM, Johannes Totz wrote: On 06/09/2011 12:00, bearophile wrote: malio: Okay, thanks bearophile. But I currently doesn't exactly understand what's the difference between "ref" and "const ref"/"immutable ref". If "ref" is syntactic sugar for pointers only (like your first exa

Re: How would I retrieve the stdout error message of a system/shell command?

2011-09-08 Thread Timon Gehr
On 09/08/2011 07:26 PM, Justin Whear wrote: The Posix solution is to use pipes. Basically, you'll want the parent process to set up a pipe for stderr, fork, then the child process uses the write end of the stderr while the parent reads from the other end. Not sure what the Windoze solution is. Al

Re: How would I retrieve the stdout error message of a system/shell command?

2011-09-08 Thread Timon Gehr
irect then. Christophe wrote: Justin Whear , dans le message (digitalmars.D.learn:29380), a écrit : That'll work if you don't mind normal output being mixed with error messages. Timon Gehr wrote: On 09/08/2011 07:26 PM, Justin Whear wrote: The Posix solution is to use pipes. Basical

Re: How can I map bytes to a matrix of structures?

2011-09-09 Thread Timon Gehr
On 09/09/2011 05:19 PM, teo wrote: Here is an example of what I am after: struct DATA { ubyte D1; ubyte D2; ubyte D3; ubyte D4; } void main() { ubyte[16] a = [ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 ]; auto b = (cast(DATA

Re: How can I map bytes to a matrix of structures?

2011-09-09 Thread Timon Gehr
On 09/09/2011 10:25 PM, teo wrote: On Fri, 09 Sep 2011 17:43:04 +0200, Timon Gehr wrote: On 09/09/2011 05:19 PM, teo wrote: Here is an example of what I am after: struct DATA { ubyte D1; ubyte D2; ubyte D3; ubyte D4; } void main() { ubyte[16] a = [ 0x01, 0x02, 0x03, 0x04

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Timon Gehr
On 09/09/2011 11:36 PM, Andrej Mitrovic wrote: Ok it seems using const works, so I can use that instead. Still I'm wondering why I can't initialize foo inside a module ctor. It works for const because mutable is implicitly convertible to const, but not to immutable. You have to allocate an imm

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Timon Gehr
On 09/09/2011 11:42 PM, Jonathan M Davis wrote: On Friday, September 09, 2011 17:37:26 bearophile wrote: Andrej Mitrovic: I need to have an object which is initialized only once, so I thought I could use immutable for that. But I can't do this: private class Foo {} immutable Foo foo; static t

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Timon Gehr
On 09/09/2011 11:45 PM, Andrej Mitrovic wrote: class Foo { this() { value = true; } @property bool value() { return true; } @property void value(bool value) { } } class Foo { this() { value = true; } @property bool value() const { ret

Re: defining "in" What is the proper way in D2?

2011-09-11 Thread Timon Gehr
On 09/11/2011 11:12 PM, Jonathan M Davis wrote: On Sunday, September 11, 2011 14:00:55 Charles Hixson wrote: On 09/11/2011 01:25 PM, Vladimir Panteleev wrote: On Sun, 11 Sep 2011 23:02:37 +0300, Charles Hixson wrote: I can't figure it out from http://www.digitalmars.com/d/2.0/operatoroverlo

Re: defining "in" What is the proper way in D2?

2011-09-11 Thread Timon Gehr
On 09/12/2011 12:21 AM, Jonathan M Davis wrote: On Monday, September 12, 2011 00:11:11 Timon Gehr wrote: On 09/11/2011 11:12 PM, Jonathan M Davis wrote: On Sunday, September 11, 2011 14:00:55 Charles Hixson wrote: On 09/11/2011 01:25 PM, Vladimir Panteleev wrote: On Sun, 11 Sep 2011 23:02:37

Re: defining "in" What is the proper way in D2?

2011-09-11 Thread Timon Gehr
On 09/12/2011 12:28 AM, Charles Hixson wrote: On 09/11/2011 02:12 PM, Jonathan M Davis wrote: On Sunday, September 11, 2011 14:00:55 Charles Hixson wrote: On 09/11/2011 01:25 PM, Vladimir Panteleev wrote: On Sun, 11 Sep 2011 23:02:37 +0300, Charles Hixson wrote: I can't figure it out from h

Re: defining "in" What is the proper way in D2?

2011-09-11 Thread Timon Gehr
On 09/12/2011 02:53 AM, Charles Hixson wrote: On 09/11/2011 04:07 PM, Timon Gehr wrote: How do you mean, instantiate it? container.binaryOp("in")!(something I haven't figured out yet. Template syntax doesn't make any sense to me yet. I'm just copying examples and ada

Re: inout and methods which return "this"

2011-09-11 Thread Timon Gehr
On 09/12/2011 03:48 AM, Vladimir Panteleev wrote: What's the simplest const-correct way to write a method which returns "this"? I tried the following to no avail: class Test { inout(Test) f() inout { return this; } } Result: test.d(3): Error: inout on return means inout must be on a parameter

Re: defining "in" What is the proper way in D2?

2011-09-12 Thread Timon Gehr
On 09/12/2011 04:10 PM, Simen Kjaeraas wrote: On Mon, 12 Sep 2011 00:11:11 +0200, Timon Gehr wrote: I think the fact that "in" for AAs returns a pointer is a mistake and ugly in the first place and any generic code that relies on any container to return a raw internal pointer is

Re: defining "in" What is the proper way in D2?

2011-09-12 Thread Timon Gehr
On 09/12/2011 04:17 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 10:10:35 -0400, Simen Kjaeraas wrote: On Mon, 12 Sep 2011 00:11:11 +0200, Timon Gehr wrote: I think the fact that "in" for AAs returns a pointer is a mistake and ugly in the first place and any generic code t

Re: defining "in" What is the proper way in D2?

2011-09-12 Thread Timon Gehr
On 09/12/2011 04:34 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 10:24:52 -0400, Timon Gehr wrote: On 09/12/2011 04:17 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 10:10:35 -0400, Simen Kjaeraas wrote: On Mon, 12 Sep 2011 00:11:11 +0200, Timon Gehr wrote: I think the fact

Re: defining "in" What is the proper way in D2?

2011-09-12 Thread Timon Gehr
On 09/12/2011 05:16 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 11:02:20 -0400, Timon Gehr wrote: On 09/12/2011 04:34 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 10:24:52 -0400, Timon Gehr wrote: On 09/12/2011 04:17 PM, Steven Schveighoffer wrote: On Mon, 12 Sep 2011 10

Re: quickSort

2011-09-13 Thread Timon Gehr
On 09/14/2011 03:34 AM, hdsh wrote: this my try int[] quickSort(int[] arr) { int[] result = quickSort(filter!(arr< arr[0])(arr)) ~ arr[0] ~ quickSort(filter!(arr> arr[0])(arr)); } but it fail to compile Note that this approach is an inefficient way of implementing a sorting routine.

Re: quickSort

2011-09-13 Thread Timon Gehr
On 09/14/2011 04:12 AM, Timon Gehr wrote: On 09/14/2011 03:34 AM, hdsh wrote: this my try int[] quickSort(int[] arr) { int[] result = quickSort(filter!(arr< arr[0])(arr)) ~ arr[0] ~ quickSort(filter!(arr> arr[0])(arr)); } but it fail to compile Note that this approach is an inefficie

Re: Should the 2.054 feature about warning on implicit fallthrough include labels?

2011-09-14 Thread Timon Gehr
On 09/14/2011 08:52 PM, simendsjo wrote: Not sure if this is a bug or as intended. import std.stdio; void main() { int i = 1; switch(i) { case 0: writeln("case 0"); goto default; // needed here default: writeln("default"); // But always falls through here aLabel: writeln("a label"); } } This i

Re: Should the 2.054 feature about warning on implicit fallthrough include

2011-09-14 Thread Timon Gehr
On 09/14/2011 09:11 PM, bearophile wrote: simendsjo Wrote: Not sure if this is a bug or as intended. The semantics of switch is a mess (example: see http://d.puremagic.com/issues/show_bug.cgi?id=3820 ). Mixing labels and switch cases seems a good way to create a bigger mess. I think it is

Re: Should the 2.054 feature about warning on implicit fallthrough

2011-09-14 Thread Timon Gehr
On 09/14/2011 10:51 PM, bearophile wrote: Timon Gehr: I think it is a bit mean to say the whole semantics is a mess, The original C design is a mess with several traps, and successive things added in D to the switch have increased the mess, they were designed from very narrow points of

Re: Should the 2.054 feature about warning on implicit fallthrough

2011-09-14 Thread Timon Gehr
On 09/15/2011 12:43 AM, bearophile wrote: Timon Gehr: What would you suggest? At the moment I suggest nothing, because the situation is set. Case syntax was discussed a lot, by me too. I suggested to differentiate the syntax, not using ".." because in D they denote an interval o

  1   2   3   4   5   6   7   8   9   10   >