UFCS and "with" statement

2013-06-11 Thread Rob T
struct S { } void f(S) { } void main() { S s; with (s) { f(); // compiler error } } Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? --rt

Re: Variable shadowing bug?

2013-06-11 Thread denizzz
On Tuesday, 11 June 2013 at 16:37:18 UTC, denizzz wrote: On Tuesday, 11 June 2013 at 11:22:15 UTC, bearophile wrote: denizzz: This message looks weird. I am spent hour to find this bug. :-( Why aren't you just using code like this? sfTime r = sfClock_getElapsedTime(sfPtr); return Time(r);

Redirecting C++ ostreams

2013-06-11 Thread Jeremy DeHaan
Hey guys, I have something I am curious about, but haven't had much luck with when doing research and experimenting. Basically, I am working with a library that uses ostreams internally and I want to somehow redirect that to what ever stderr is pointing to. The reason I am trying to do thi

what keeps a COM object alive?

2013-06-11 Thread finalpatch
A typical COM server would create a new object (derived from IUnknown), return it to the caller (potentially written in other languages). Because the object pointer now resides outside of D's managed heap, does that mean the object will be destroyed when the GC runs? A normal COM object written

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 20:58:17 -0400, Ali Çehreli wrote: On 06/11/2013 05:48 PM, captaindet wrote: > i think part of the problem is that '1' is an int. so the calculation > must be promoted to integer. No, the compiler knows that 1 could fit in a ubyte. It has value-range-propagation. Ch

Re: Variable shadowing bug?

2013-06-11 Thread denizzz
On Wednesday, 12 June 2013 at 02:01:27 UTC, denizzz wrote: On Wednesday, 12 June 2013 at 01:17:50 UTC, Mike Parker wrote: On Tuesday, 11 June 2013 at 16:37:18 UTC, denizzz wrote: Ok, but why compiler says that types of these types is equal? ...that typeids of these types are equal?

Re: Variable shadowing bug?

2013-06-11 Thread denizzz
On Wednesday, 12 June 2013 at 01:17:50 UTC, Mike Parker wrote: On Tuesday, 11 June 2013 at 16:37:18 UTC, denizzz wrote: sfTime* r = sfClock_getElapsedTime(sfPtr); says what sfTime can not be implictly converted to sfTime sfClock_getElapsedTime does not return a pointer. You're going to con

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Adam D. Ruppe
On Wednesday, 12 June 2013 at 01:35:47 UTC, Adam D. Ruppe wrote: // byte multiplication, answer goes into a 16 bit register, but we could truncate it too BTW just as a personal note you might be amused by, this multiply instruction beat the crap out of me when I was learning x86 assembly ba

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Adam D. Ruppe
On Wednesday, 12 June 2013 at 00:58:17 UTC, Ali Çehreli wrote: The CPU would have to have special registers to do those operations in. (I am under the impression that x86 does not have any arithmetic registers for types narrower than int.) It does, for 8, 16, 32, and 64 bits. Here's how 8 and

Re: Variable shadowing bug?

2013-06-11 Thread Mike Parker
On Tuesday, 11 June 2013 at 16:37:18 UTC, denizzz wrote: sfTime* r = sfClock_getElapsedTime(sfPtr); says what sfTime can not be implictly converted to sfTime sfClock_getElapsedTime does not return a pointer. You're going to continue to have type mismatches because you are trying to use two

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Ali Çehreli
On 06/11/2013 05:48 PM, captaindet wrote: > i think part of the problem is that '1' is an int. so the calculation > must be promoted to integer. According to "Integer Promotions" and "Usual Arithmetic Conversions" there is no arithmetic operation that is executed in any type narrower than int:

Re: Why there is too many uneccessary casts?

2013-06-11 Thread captaindet
On 2013-06-11 07:35, Adam D. Ruppe wrote: On Tuesday, 11 June 2013 at 10:12:27 UTC, Temtaime wrote: ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte The reason is arithmetic operations trans

Re: Passing arguments a template parameters vs. function parameters

2013-06-11 Thread John Colvin
On Tuesday, 11 June 2013 at 22:13:18 UTC, bearophile wrote: If you want to do benchmarks don't forget to do them with a better compiler, like LDC2, that is able to use that compile-time information to optimize better. When I have written that code I was using only DMD. I have just started t

Re: Passing arguments a template parameters vs. function parameters

2013-06-11 Thread bearophile
Craig Dillabaugh: If I had been coding this I would almost certainly have passed the splitting dimensions as a function parameter, since the compiler has to generate separate makeTree/findMedian functions for each dimension that i/idx takes in the program. So my question is, does anyone have an

Re: Passing arguments a template parameters vs. function parameters

2013-06-11 Thread Craig Dillabaugh
On Tuesday, 11 June 2013 at 21:26:35 UTC, John Colvin wrote: On Tuesday, 11 June 2013 at 20:46:32 UTC, Craig Dillabaugh wrote: I was looking at D code for constructing kd-trees, the full code listing for which can be found here: clip So my question is, does anyone have any idea why the aut

Re: Passing arguments a template parameters vs. function parameters

2013-06-11 Thread John Colvin
On Tuesday, 11 June 2013 at 20:46:32 UTC, Craig Dillabaugh wrote: I was looking at D code for constructing kd-trees, the full code listing for which can be found here: http://rosettacode.org/wiki/K-d_tree#Faster_Alternative_Version Of particular interest were the following functions: KdNode* m

Passing arguments a template parameters vs. function parameters

2013-06-11 Thread Craig Dillabaugh
I was looking at D code for constructing kd-trees, the full code listing for which can be found here: http://rosettacode.org/wiki/K-d_tree#Faster_Alternative_Version Of particular interest were the following functions: KdNode* makeTree(size_t dim, size_t i)(KdNode[] nodes) pure nothrow { i

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread ixid
On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write); I previously suggested to add the syntax 'arg1.(std.file.write)(arg2)' (see 'support UFCS with fully qualified function n

Fibers vs Async/await

2013-06-11 Thread Jonathan Dunlap
I was listening to one of the DConf sessions and where was some talk about implementing async from C# into D someday in the far future. Recently I learned about D's fibers... and it looks like the same thing to me. What are the major differences in principle? -Jonathan @jonathanAdunlap

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread John Colvin
On Tuesday, 11 June 2013 at 18:47:08 UTC, timotheecour wrote: On Monday, 10 June 2013 at 08:13:42 UTC, John Colvin wrote: On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write)

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Adam D. Ruppe
On Tuesday, 11 June 2013 at 19:09:11 UTC, Timothee Cour wrote: wouldn't it be a better and more consistent idea to implement bearophile's 'Compiler support to implement efficient safe integrals' http://d.puremagic.com/issues/show_bug.cgi?id=9850 so uint/int etc would require no cast This isn'

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread Jakob Ovrum
I think selective, renamed imports are much better. On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: * library solution, already works, no need to add new syntax * avoids the renamed local imports, which I argue is a bad idea (makes it harder to search for usages of a function, ie

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Timothee Cour
On Tue, Jun 11, 2013 at 11:26 AM, H. S. Teoh wrote: > On Tue, Jun 11, 2013 at 01:25:24PM -0400, Steven Schveighoffer wrote: > > On Tue, 11 Jun 2013 12:18:52 -0400, Adam D. Ruppe > > wrote: > > > > >On Tuesday, 11 June 2013 at 16:05:30 UTC, Steven Schveighoffer wrote: > > >>CPU performs math at i

Re: best way to handle UFCS with ambiguous names: using std.typetuple.Alias!

2013-06-11 Thread timotheecour
On Monday, 10 June 2013 at 08:13:42 UTC, John Colvin wrote: On Monday, 10 June 2013 at 02:02:09 UTC, Timothee Cour wrote: UFCS chains are problematic when a symbol is ambiguous (eg after import std.stdio:write;import std.file:write); I previously suggested to add the syntax 'arg1.(std.file.wri

Re: Why there is too many uneccessary casts?

2013-06-11 Thread H. S. Teoh
On Tue, Jun 11, 2013 at 01:25:24PM -0400, Steven Schveighoffer wrote: > On Tue, 11 Jun 2013 12:18:52 -0400, Adam D. Ruppe > wrote: > > >On Tuesday, 11 June 2013 at 16:05:30 UTC, Steven Schveighoffer wrote: > >>CPU performs math at int level. > > > >eh, I wouldn't blame the hardware. You can do >

Re: GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-11 Thread Alex Horvat
On Tuesday, 11 June 2013 at 17:41:59 UTC, Mike Wey wrote: On 06/11/2013 05:56 PM, Alex Horvat wrote: TreeStore store = cast(TreeStore)tvTreeView.getModel(); In this case store == null I think that one should work, how are you setting/creating the TreeStore? tvTreeView.setModel(CreateModel()

Re: GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-11 Thread Mike Wey
On 06/11/2013 05:56 PM, Alex Horvat wrote: TreeStore store = cast(TreeStore)tvTreeView.getModel(); In this case store == null I think that one should work, how are you setting/creating the TreeStore? -- Mike Wey

Re: GtkD not working

2013-06-11 Thread Daemon
I don't know your setup but you should usually get some linker error when not linking against the gtkd libraries. Also your first post whould suggest you are using Windows while -L-ldl would link in the Linux dynamic linker. I am using Windows, but adding those thingamajigs still solves the

Re: GtkD not working

2013-06-11 Thread Mike Wey
On 06/11/2013 03:33 PM, Daemon wrote: I've been checking stack overflow and some blogs and kept trying various things. I finally managed to launch it normally. For anyone who might have had the same problem, the solution is to pass "-L-lgtkd -L-ldl" to the command line. Project -> Properties ->

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 12:18:52 -0400, Adam D. Ruppe wrote: On Tuesday, 11 June 2013 at 16:05:30 UTC, Steven Schveighoffer wrote: CPU performs math at int level. eh, I wouldn't blame the hardware. You can do asm { mov AL, 10; add AL, 5; } and it is allowed, it also don't spill into AH

Re: Why there is too many uneccessary casts?

2013-06-11 Thread QAston
On Tuesday, 11 June 2013 at 16:18:54 UTC, Adam D. Ruppe wrote: I'd be extremely annoyed if that required a cast. It's bleeding obvious that you want it to assign back there To me u = u + k is as obvious as u += k, but that's probably not a thing anyone would be much concerned about :)

Re: static class instances not allowed?

2013-06-11 Thread bearophile
C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs, like CS1525: http://msdn.microsoft.com/en-gb/library/3hdyz4dw%28v=vs.80%29.aspx In such pages you can explain w

Re: Variable shadowing bug?

2013-06-11 Thread denizzz
On Tuesday, 11 June 2013 at 11:22:15 UTC, bearophile wrote: denizzz: This message looks weird. I am spent hour to find this bug. :-( Why aren't you just using code like this? sfTime r = sfClock_getElapsedTime(sfPtr); return Time(r); sfTime* r = sfClock_getElapsedTime(sfPtr); says what s

Re: static class instances not allowed?

2013-06-11 Thread Eric
On Tuesday, 11 June 2013 at 16:09:39 UTC, Steven Schveighoffer wrote: On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Adam D. Ruppe
On Tuesday, 11 June 2013 at 16:05:30 UTC, Steven Schveighoffer wrote: CPU performs math at int level. eh, I wouldn't blame the hardware. You can do asm { mov AL, 10; add AL, 5; } and it is allowed, it also don't spill into AH if you overflow it (it just sets the carry flag). I'm sure it

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 07:46:11 -0400, Temtaime wrote: No. I means, that uint a = uint.max; uint b = a + 1; writeln(b); Works OK. Why? Compiler doesn't know if a + b fits in uint, right? Then why overflow with ints are accepted? CPU performs math at int level. So even if you add two ubytes, t

Re: static class instances not allowed?

2013-06-11 Thread Steven Schveighoffer
On Tue, 11 Jun 2013 10:04:21 -0400, Eric wrote: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error These can be solved with a static ctor. Essentially, any static initializers mu

Re: How to implement this?

2013-06-11 Thread H. S. Teoh
On Tue, Jun 11, 2013 at 02:34:37PM +0200, Elvis wrote: > On Monday, 10 June 2013 at 14:40:05 UTC, Kenji Hara wrote: > >On Monday, 10 June 2013 at 09:42:56 UTC, Elvis wrote: > >>class A > >>{ > >> enum TypeID = 1; > >>} > >>class B : A > >>{ > >> enum TypeID = 2; > >>} > >> > >>class C : A > >>{

GtkD: Best way to get TreeStore out of TreeView.Model

2013-06-11 Thread Alex Horvat
I'm trying to get a TreeStore object back out of a TreeView in GtkD. The reason for this is so that I can change the value of a cell in the TreeView - in this case changing one image for another. I can't use a TreeModel for this as it does not have a setValue function. I've got this workin

Re: static class instances not allowed?

2013-06-11 Thread Eric
Why aren't static class instances allowed? Is there a work-around, or alternative approach to this? C# compilers present bugs with a standard number, like: myprog.cs(7,60): error CS1525: ... This is useful because you can then write an explanation page for each of those bugs, like CS1

Re: static class instances not allowed?

2013-06-11 Thread bearophile
Eric: The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error void main() {} (dmd7) desk3:~/tp/d_test2/dlib>dmd T.d T.d(4): Error: variable T.Bar.f is mutable. Only const or immutable clas

static class instances not allowed?

2013-06-11 Thread Eric
The following code does not compile: class Foo { int x; } class Bar { static Foo f = new Foo(); } // compiler error static Foo g = new Foo(); // compiler error void main() {} (dmd7) desk3:~/tp/d_test2/dlib>dmd T.d T.d(4): Error: variable T.Bar.f is mutable. Only const or immutable class threa

Re: Variable shadowing bug?

2013-06-11 Thread Mike Parker
On Tuesday, 11 June 2013 at 08:08:03 UTC, denizzz wrote: sfClock_getElapsedTime return type actually defined in the another file, typeid = _D45TypeInfo_S8derelict5sfml211systemtypes6sfTime6__initZ compilation causes: dsfml/system.d(54): Error: static assert (is(sfTime == sfTime)) is fals

Re: GtkD not working

2013-06-11 Thread Daemon
I've been checking stack overflow and some blogs and kept trying various things. I finally managed to launch it normally. For anyone who might have had the same problem, the solution is to pass "-L-lgtkd -L-ldl" to the command line. Project -> Properties -> Command Line -> Additional Options.

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Adam D. Ruppe
On Tuesday, 11 June 2013 at 10:12:27 UTC, Temtaime wrote: ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte The reason is arithmetic operations transform the operands into ints, that's why t

Re: How to implement this?

2013-06-11 Thread Elvis
On Monday, 10 June 2013 at 14:40:05 UTC, Kenji Hara wrote: On Monday, 10 June 2013 at 09:42:56 UTC, Elvis wrote: class A { enum TypeID = 1; } class B : A { enum TypeID = 2; } class C : A { enum TypeID = 3; } class D : B { enum TypeID = 4; } ... Could anybody shed some light on h

Re: Why there is too many uneccessary casts?

2013-06-11 Thread bearophile
Temtaime: Why? Compiler doesn't know if a + b fits in uint, right? Then why overflow with ints are accepted? It's an inconstancy based on practical considerations. Walter decided that applying the same rule to uint/int/long causes too many casts in normal problems. And the range of a 32 bi

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 13:46:11 +0200, Temtaime wrote: No. I means, that uint a = uint.max; uint b = a + 1; writeln(b); Works OK. Why? Compiler doesn't know if a + b fits in uint, right? Then why overflow with ints are accepted? Because there's a limit to how far this goes without introducing

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Temtaime
No. I means, that uint a = uint.max; uint b = a + 1; writeln(b); Works OK. Why? Compiler doesn't know if a + b fits in uint, right? Then why overflow with ints are accepted? So your example is meaningless.

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 13:15:11 +0200, Simen Kjaeraas wrote: On Tue, 11 Jun 2013 12:39:47 +0200, Temtaime wrote: There is overflow and it can be with int too. It's standard behavior. Indeed. And a class is a void* is an int is a char is a double? That's perfectly possible - it's all just me

Re: Variable shadowing bug?

2013-06-11 Thread bearophile
denizzz: This message looks weird. I am spent hour to find this bug. :-( Why aren't you just using code like this? sfTime r = sfClock_getElapsedTime(sfPtr); return Time(r); I don't fully understand, it seems a diagnostic problem. Please create a minimal test case that shows the problem. May

Re: Why there is too many uneccessary casts?

2013-06-11 Thread bearophile
Temtaime: ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte Why? It's pain in the ass, i think. My code contains only casts then. I agree that sometimes that's a pain. Currently D perform

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 12:39:47 +0200, Temtaime wrote: There is overflow and it can be with int too. It's standard behavior. Indeed. And a class is a void* is an int is a char is a double? That's perfectly possible - it's all just memory anyway. D has chosen to do it like this to prevent common

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Temtaime
There is overflow and it can be with int too. It's standard behavior.

Re: Why there is too many uneccessary casts?

2013-06-11 Thread Simen Kjaeraas
On Tue, 11 Jun 2013 12:12:25 +0200, Temtaime wrote: ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte Why? It's pain in the ass, i think. My code contains only casts then. Because it's u

Why there is too many uneccessary casts?

2013-06-11 Thread Temtaime
ubyte k = 10; ubyte c = k + 1; This code fails to compile because of: Error: cannot implicitly convert expression (cast(int)k + 1) of type int to ubyte Why? It's pain in the ass, i think. My code contains only casts then.

Re: std.traits functions causing the compiler to crash

2013-06-11 Thread Regan Heath
On Sat, 08 Jun 2013 05:52:49 +0100, Eric wrote: On Saturday, 8 June 2013 at 02:32:57 UTC, bearophile wrote: Eric: Yes, the template constraint is much better. However, the compiler still crashes, even with the new code: Because there's a type definition loop, regardless. Using a constrai

Re: Segfault on simple program?

2013-06-11 Thread nazriel
On Friday, 31 May 2013 at 17:14:46 UTC, Shriramana Sharma wrote: import std.stdio ; void foo ( int[] array ) { foreach ( i ; array ) { writeln ( i ) ; } } void main () { foo ( [ 1, 2, 3 ] ) ; } On both DMD 2.062 and 2.063 this compiles OK but causes a segfault. I'm running Ku

Variable shadowing bug?

2013-06-11 Thread denizzz
Piece of code: https://github.com/denizzzka/DSFML/blob/237a752988c76e3c2f63ed03ae12558823ce43ec/dsfml/system.d#L53 Time getElapsedTime() const { auto r = sfClock_getElapsedTime(sfPtr); static assert( is (typeof(r) == sfT