UFCS and with statement

2013-06-12 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

Why TypeTuple can be assigned to a variable

2013-06-12 Thread Zhenya
Hi! I was just surprised when realized, that this code compiles and runs: import std.typetuple; import std.stdio; void main() { auto foo = TypeTuple!(foo,bar); writeln(typeid(typeof(foo))); writeln(foo); } If I were compiler expert,I'd say that it's a bug.But I am not) So, can anybody

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Simen Kjaeraas
On Wed, 12 Jun 2013 10:01:59 +0200, Zhenya zh...@list.ru wrote: Hi! I was just surprised when realized, that this code compiles and runs: import std.typetuple; import std.stdio; void main() { auto foo = TypeTuple!(foo,bar); writeln(typeid(typeof(foo))); writeln(foo); } If I were

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Zhenya
On Wednesday, 12 June 2013 at 08:14:06 UTC, Simen Kjaeraas wrote: On Wed, 12 Jun 2013 10:01:59 +0200, Zhenya zh...@list.ru wrote: Hi! I was just surprised when realized, that this code compiles and runs: import std.typetuple; import std.stdio; void main() { auto foo =

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Simen Kjaeraas
On Wed, 12 Jun 2013 11:44:19 +0200, Zhenya zh...@list.ru wrote: OK,you say that TypeTuple!(foo,bar) is a cool value of type TypeTuple!(string,string),right? Well, yes and no, not really. It's a bit magical. In your case, it's assigned to an auto variable, and that variable gets that type.

Re: Why TypeTuple can be assigned to a variable

2013-06-12 Thread Zhenya
On Wednesday, 12 June 2013 at 10:09:07 UTC, Simen Kjaeraas wrote: On Wed, 12 Jun 2013 11:44:19 +0200, Zhenya zh...@list.ru wrote: OK,you say that TypeTuple!(foo,bar) is a cool value of type TypeTuple!(string,string),right? Well, yes and no, not really. It's a bit magical. In your case, it's

Getting object members

2013-06-12 Thread Szymon Gatner
Hi, I am trying to get members of a class via pointer to Object. I know how to iterate over members when type is known at compile time (with __traits) but I can't find a documentation of how to get them polymorphically, I mean: class Foo { int x, y; } Object o = new Foo(); auto ci =

Re: UFCS and with statement

2013-06-12 Thread bearophile
Rob T: Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? Probably no one thought on this case. Why do you think it's useful? Bye, bearophile

Re: Variable shadowing bug?

2013-06-12 Thread bearophile
denizzz: says what sfTime* can not be implictly converted to sfTime* Maybe it's a diagnostic bug. Please create a minimal example. Bye, bearophile

Strange error when importing std.regex

2013-06-12 Thread Temtaime
Hello guys! http://dpaste.1azy.net/9c4c3eb8 http://dpaste.1azy.net/afd8d20b How i can avoid this?

Clarification of @trusted attribute?

2013-06-12 Thread Gary Willoughby
I know the reason to mark a method as trusted from the docs: Trusted functions are guaranteed by the programmer to not exhibit any undefined behavior if called by a safe function. Generally, trusted functions should be kept small so that they are easier to manually verify. Undefined

Re: Strange error when importing std.regex

2013-06-12 Thread bearophile
Temtaime: How i can avoid this? You have to qualify where the function comes from. One way to do it is to use: std.algorithm.splitter(arr, 1); Bye, bearophile

Re: what keeps a COM object alive?

2013-06-12 Thread Sean Cavanaugh
On 6/11/2013 10:38 PM, finalpatch wrote: 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

Stack trace

2013-06-12 Thread New guy
Could someone please tell me how can I get the stack trace when an exception is thrown? My test code: Code: - void f1() { throw new Exception(in f1); } void f2() { f1(); } void f3() { f2(); } void main() { f3(); } Output:

Re: what keeps a COM object alive?

2013-06-12 Thread finalpatch
Hi Sean, Thanks for your reply. I have no problem with client side COM programming in D. What I'm asking is if I write a COM object in D (in this case the D code is a COM server), then it looks like I have to store a reference to that COM object in some globally reachable place (eg. add it to a

Re: Strange error when importing std.regex

2013-06-12 Thread Temtaime
Oh, thanks very much.

Re: Getting object members

2013-06-12 Thread Adam D. Ruppe
On Wednesday, 12 June 2013 at 10:59:42 UTC, Szymon Gatner wrote: I know how to iterate over members when type is known at compile time (with __traits) but I can't find a documentation of how to get them polymorphically, I mean: It hasn't been implemented in the runtime yet (though all the

Re: what keeps a COM object alive?

2013-06-12 Thread Richard Webb
On Wednesday, 12 June 2013 at 14:41:05 UTC, finalpatch wrote: This feels even more cumbersome than in C++ because in C++ we can simply delete this in the Release() method, there's no need to store a reference in a global place. Juno does this by allocating the object on the non-gc heap,

Re: what keeps a COM object alive?

2013-06-12 Thread finalpatch
Richard Webb we...@beardmouse.org.uk writes: On Wednesday, 12 June 2013 at 14:41:05 UTC, finalpatch wrote: This feels even more cumbersome than in C++ because in C++ we can simply delete this in the Release() method, there's no need to store a reference in a global place. Juno does

Re: Redirecting C++ ostreams

2013-06-12 Thread Craig Dillabaugh
On Wednesday, 12 June 2013 at 04:05:22 UTC, Jeremy DeHaan wrote: 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

Re: Why there is too many uneccessary casts?

2013-06-12 Thread captaindet
On 2013-06-11 19:48, captaindet wrote: 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

Re: Strange error when importing std.regex

2013-06-12 Thread Dmitry Olshansky
12-Jun-2013 17:28, bearophile пишет: Temtaime: How i can avoid this? You have to qualify where the function comes from. One way to do it is to use: There is no ambiguity, 1 is not a Regex object but it seems like template constraint in std.regex blows up. @Temtaime please file a bug on

Re: Strange error when importing std.regex

2013-06-12 Thread bearophile
Dmitry Olshansky: There is no ambiguity, 1 is not a Regex object but it seems like template constraint in std.regex blows up. @Temtaime please file a bug on this. http://d.puremagic.com/issues/ std.algorithm.splitter(arr, 1); I think this bug already surfaced some time ago... Maybe it's

Re: Friend class and methods

2013-06-12 Thread Adam D. Ruppe
On Wednesday, 12 June 2013 at 19:01:24 UTC, Maxime Chevalier-Boisvert wrote: Does D have something like the concept of friend classes and functions in C++? The closest is to put both classes and the function in the same module. Things all in the same module can see the private members of

Re: Friend class and methods

2013-06-12 Thread David Nadlinger
On Wednesday, 12 June 2013 at 19:01:24 UTC, Maxime Chevalier-Boisvert wrote: Does D have something like the concept of friend classes and functions in C++? I'd like to have a function that can access private members of two classes at the same time. No (t really), you have to stick the two

Friend class and methods

2013-06-12 Thread Maxime Chevalier-Boisvert
Does D have something like the concept of friend classes and functions in C++? I'd like to have a function that can access private members of two classes at the same time.

Re: Friend class and methods

2013-06-12 Thread Maxime Chevalier-Boisvert
The closest is to put both classes and the function in the same module. Things all in the same module can see the private members of each other. Good enough for my needs. Thanks.

Strange seg fault

2013-06-12 Thread gedaiu
Hi, Can anyone help me why this code goes wrong? I get exit code 139 with DMD 2.063 import std.stdio; struct Test { string val = ; string[] key; /** * operator = overload */ Test opAssign(string val){ this.val =

Associative multidimensional Arrays

2013-06-12 Thread MaB
Hi! I want to bulid up a IndexArray with a structure like this (PHP code): code $arrIndex = array( A = array( B = array() ), B = array( B = array(C = array()) ) ); /code The Keys are of Type string and the values can be arrays with the same structure.

Re: Associative multidimensional Arrays

2013-06-12 Thread gedaiu
Hi, Please look at this thread. You might find your answer there: http://forum.dlang.org/thread/vphniyxyvgsiazutt...@forum.dlang.org Bogdan On Wednesday, 12 June 2013 at 20:20:09 UTC, MaB wrote: Hi! I want to bulid up a IndexArray with a structure like this (PHP code): code $arrIndex =

Re: what keeps a COM object alive?

2013-06-12 Thread Richard Webb
I was referring to the COM server support stuff in the Juno library, which allocates COM objects outside the GC heap so the GC will never collect them. See https://github.com/JesseKPhillips/Juno-Windows-Class-Library/blob/master/juno/com/core.d#L3147 for an example.

Re: Associative multidimensional Arrays

2013-06-12 Thread Ali Çehreli
On 06/12/2013 01:20 PM, MaB wrote: Hi! I want to bulid up a IndexArray with a structure like this (PHP code): code $arrIndex = array( A = array( B = array() ), B = array( B = array(C = array()) ) ); /code The Keys are of Type string and the values

Re: Strange seg fault

2013-06-12 Thread Adam D. Ruppe
I think you've hit bug city in the associative array implementation. The this in there doesn't seem to point at anything meaningful. This is probably worthy of a bug report. A potential workaround is to store pointers to your structs in the associative array, that way you can set them up

Re: Strange seg fault

2013-06-12 Thread Ali Çehreli
On 06/12/2013 01:12 PM, gedaiu wrote: Hi, Can anyone help me why this code goes wrong? I get exit code 139 with DMD 2.063 import std.stdio; struct Test { string val = ; string[] key; /** * operator = overload */ Test opAssign(string val){

Re: Friend class and methods

2013-06-12 Thread Ali Çehreli
On 06/12/2013 12:12 PM, Maxime Chevalier-Boisvert wrote: The closest is to put both classes and the function in the same module. Things all in the same module can see the private members of each other. Good enough for my needs. Thanks. Sometimes 'package' is more suitable than 'private'.

Template Trick

2013-06-12 Thread matovitch
Hello, I got a simple vector template : struct Vector(T, uint N) { alias type T; T data[N]; } And I'd like to call a function like : void func(V, V.type default_value)(args...); But this (of course) doesn't work. Is there a simple and nice way to do this ? (I'm sure there is ;-))

Re: Template Trick

2013-06-12 Thread H. S. Teoh
On Wed, Jun 12, 2013 at 11:26:40PM +0200, matovitch wrote: Hello, I got a simple vector template : struct Vector(T, uint N) { alias type T; [...] This line should read: alias type = T; And it should work as you wanted. T -- If you look at a thing nine hundred and

Re: Template Trick

2013-06-12 Thread matovitch
On Wednesday, 12 June 2013 at 21:36:38 UTC, H. S. Teoh wrote: On Wed, Jun 12, 2013 at 11:26:40PM +0200, matovitch wrote: Hello, I got a simple vector template : struct Vector(T, uint N) { alias type T; [...] This line should read: alias type = T; And it should work as you

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

2013-06-12 Thread Mike Wey
On 06/11/2013 07:55 PM, Alex Horvat wrote: 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

Re: Template Trick

2013-06-12 Thread Ali Çehreli
On 06/12/2013 02:26 PM, matovitch wrote: Hello, I got a simple vector template : struct Vector(T, uint N) { alias type T; You later corrected that it should be alias T type; But still, prefer the new syntax over the backward C syntax: alias type = T; T data[N]; }

Re: Template Trick

2013-06-12 Thread matovitch
To be more precise the code below doesn't compile : struct Vector(T, uint N) { alias T type; enum dimension = N; T data[N]; } void func(V, V.type def_val) (uint i, V v) { if (i v.dimension) { v.data[i] = def_val; } } void main() {

Re: Template Trick

2013-06-12 Thread Ali Çehreli
On 06/12/2013 02:47 PM, matovitch wrote: To be more precise the code below doesn't compile : struct Vector(T, uint N) { alias T type; enum dimension = N; T data[N]; } void func(V, V.type def_val) (uint i, V v) { if (i v.dimension) { v.data[i] = def_val; } }

Re: Template Trick

2013-06-12 Thread matovitch
On Wednesday, 12 June 2013 at 21:52:46 UTC, Ali Çehreli wrote: Here is one way: void func(V, alias def_val) (uint i, V v) if (is (typeof(def_val == V.type))) { if (i v.dimension) { v.data[i] = def_val; } } Ali Thank you !

Re: Template Trick

2013-06-12 Thread bearophile
matovitch: void func(V, V.type def_val) (uint i, V v) { if (i v.dimension) { v.data[i] = def_val; } } I think something like that is not yet possible, but maybe it will be possible later. Your code has also allowed me to find a new small compiler bug that

Re: Template Trick

2013-06-12 Thread Ali Çehreli
On 06/12/2013 02:56 PM, matovitch wrote: On Wednesday, 12 June 2013 at 21:52:46 UTC, Ali Çehreli wrote: Here is one way: void func(V, alias def_val) (uint i, V v) if (is (typeof(def_val == V.type))) Oops. It should be: if (is (typeof(def_val) == V.type)) Hmmm. How come the other

Re: Compiler errors and recursive nested functions

2013-06-12 Thread Ali Çehreli
On 06/12/2013 03:45 PM, Dylan Knutson wrote: Hello! I'm trying to make a deepMap function which operates on the deepest non-range element of an array. I think that this function should theoretically work, however there are some compiler errors that I can't quite understand. Here's the code:

Compiler errors and recursive nested functions

2013-06-12 Thread Dylan Knutson
Hello! I'm trying to make a deepMap function which operates on the deepest non-range element of an array. I think that this function should theoretically work, however there are some compiler errors that I can't quite understand. Here's the code: http://dpaste.dzfl.pl/97918311 And the

Re: Compiler errors and recursive nested functions

2013-06-12 Thread Dylan Knutson
DPaste has stopped responding to requests at the time of writing, so here's the code in case its still down by the time someone reads this: import std.algorithm : map; import std.range : isInputRange, ElementType; // Doesn't work //template deepMap(alias pred, Range)

Re: Compiler errors and recursive nested functions

2013-06-12 Thread Ali Çehreli
On 06/12/2013 03:49 PM, Dylan Knutson wrote: DPaste has stopped responding to requests at the time of writing, Being an old ;) old-timer I never understood the need for those sites. import std.algorithm : map; import std.range : isInputRange, ElementType; As a workaround, make that

How to use Power on D

2013-06-12 Thread Carlos
So I have this code I'm working on but I get weird results. What am I doing wrong ? Code : import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 16){ write(Result : , (2)^(count), from : , count, \n); } } Prints: Result : 3 from : 1 Result : 0 from : 2

Re: How to use Power on D

2013-06-12 Thread Infiltrator
On Thursday, 13 June 2013 at 00:24:18 UTC, Carlos wrote: So I have this code I'm working on but I get weird results. What am I doing wrong ? Code : import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 16){ write(Result : , (2)^(count), from : , count, \n);

Re: How to use Power on D

2013-06-12 Thread bearophile
Carlos: Thank you for your time. That's one bitwise operator. You want ^^ Bye, bearophile

Re: How to use Power on D

2013-06-12 Thread Carlos
On Thursday, 13 June 2013 at 00:27:33 UTC, bearophile wrote: Carlos: Thank you for your time. That's one bitwise operator. You want ^^ Bye, bearophile I didn't understoof in the first try but Infiltrator told me on the #d irc chat and here is the new code. import std.stdio; import

So I found this using 2 to the power of = 31

2013-06-12 Thread Carlos
I have this code : import std.stdio; import std.c.stdlib; void main() { foreach (count; 1 .. 33){ write((2)^^(count), : , count, \n); } exit (0); } And here is the output : 2 : 1 4 : 2 8 : 3 16 : 4 32 : 5 64 : 6 128 : 7 256 : 8 512 : 9 1024 : 10 2048 : 11 4096 : 12 8192 : 13

Re: So I found this using 2 to the power of = 31

2013-06-12 Thread Carlos
import std.stdio; import std.math : pow; void main() { cast(ulong)count; foreach (count; 1 .. 33){ write((2)^^(count), : , count, \n); } } same output.

Re: So I found this using 2 to the power of = 31

2013-06-12 Thread Jonathan M Davis
On Thursday, June 13, 2013 03:46:59 Carlos wrote: import std.stdio; import std.math : pow; void main() { cast(ulong)count; That line won't compile. foreach (count; 1 .. 33){ write((2)^^(count), : , count, \n); } } same output. If you want to set the type of count, then give it a

Re: So I found this using 2 to the power of = 31

2013-06-12 Thread Carlos
On Thursday, 13 June 2013 at 02:03:35 UTC, Jonathan M Davis wrote: On Thursday, June 13, 2013 03:46:59 Carlos wrote: import std.stdio; import std.math : pow; void main() { cast(ulong)count; That line won't compile. foreach (count; 1 .. 33){ write((2)^^(count), : , count, \n); } } same

Re: So I found this using 2 to the power of = 31

2013-06-12 Thread bearophile
Carlos: What do I have to know about how D works with data ? If you want to avoid the overflow, then use a BigInt from std.bigint: import std.stdio, std.bigint; void main() { foreach (immutable i; 0 .. 100) writeln(i, , 2.BigInt ^^ i); } Bye, bearophile

Re: Redirecting C++ ostreams

2013-06-12 Thread Jeremy DeHaan
On Wednesday, 12 June 2013 at 16:15:08 UTC, Craig Dillabaugh wrote: Do you have access to the source code of the library? Or are you just linking to it? I do some-what. I don't want to change the source code of the library itself, but I can change the C/C++ code of the binding that is used

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

2013-06-12 Thread Alex Horvat
On Wednesday, 12 June 2013 at 21:44:55 UTC, Mike Wey wrote: On 06/11/2013 07:55 PM, Alex Horvat wrote: 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

Re: UFCS and with statement

2013-06-12 Thread Rob T
On Wednesday, 12 June 2013 at 11:05:22 UTC, bearophile wrote: Rob T: Rather disappointing that this fails. Anyone know if this is an expected limitation of UFCS or a bug? Probably no one thought on this case. Why do you think it's useful? Bye, bearophile If we're to use UFCS as a means