Re: First project: questions on how-to, and on language features

2016-02-02 Thread Alex Vincent via Digitalmars-d-learn
On Sunday, 24 January 2016 at 18:52:41 UTC, Chris Wright wrote: There is no documentation, so I have no idea what you're trying to achieve here. So your questions about why this isn't in Phobos, whether there are any other libraries that do this, and whether there's a way to simplify your contr

Re: const and immutable member variables in classes

2016-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 02, 2016 at 09:08:07PM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, February 02, 2016 19:32:39 Ali Çehreli via Digitalmars-d-learn > wrote: > > On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > > I usually tell folks not to do it beca

Re: const and immutable member variables in classes

2016-02-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 02, 2016 19:32:39 Ali Çehreli via Digitalmars-d-learn wrote: > On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > > I usually tell folks not to do it because of > > all of the problems it causes. > > That's been my guideline: "const and immutable membe

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 00:37:25 UTC, Mike Parker wrote: The parameter to the C function should be declared as extern(C), and so should your function implementation. extern(C) alias FuncPtr = double function(uint, const(double)*, double*, void*); extern(C) void takeFuncPtr(FuncPtr)

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 00:28:24 UTC, biozic wrote: Is grad allocated in the D code? If so, it could have been collected because the GC lost track of its use when passing to and from the C code. Or is grad owned by the C code? If so, either there is a bug in the library or it's misus

Re: const and immutable member variables in classes

2016-02-02 Thread Ali Çehreli via Digitalmars-d-learn
On 02/02/2016 07:05 PM, Jonathan M Davis via Digitalmars-d-learn wrote: > Well, in principle, if you have a member that's going to be initialized on > construction and then never mutated, having it be const or immutable would > be desirable, That's how I've seen it used in a friend's code. Ma

Re: const and immutable member variables in classes

2016-02-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 02, 2016 18:14:50 H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, Feb 02, 2016 at 05:49:00PM -0800, Jonathan M Davis via > Digitalmars-d-learn wrote: > > On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn > > wrote: > > > const and immutable member

Re: const and immutable member variables in classes

2016-02-02 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Feb 02, 2016 at 05:49:00PM -0800, Jonathan M Davis via Digitalmars-d-learn wrote: > On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn > wrote: > > const and immutable members make structs non-assignable: [...] > > That's why I've been avoiding them altogether. How

Re: const and immutable member variables in classes

2016-02-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 02, 2016 14:48:03 Ali Çehreli via Digitalmars-d-learn wrote: > const and immutable members make structs non-assignable: > > struct S { > const int c;// Makes S non-assignable > immutable int i;// Makes S non-assignable > } > > void main() { > auto a

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 22:56:28 UTC, jmh530 wrote: My D code calls a C function. One of the parameters to the C function is a function pointer to a D function. This D function (below) is one that I copied from the C library's tutorial. I only slightly changed the signature. This fun

Re: Binding to C - Arrays and Access Violation

2016-02-02 Thread biozic via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 22:56:28 UTC, jmh530 wrote: I'm working on generating a binding to a C library. I've got the .h file converted and can call some parts of the library with no errors. However, I have reached a stumbling block in a critical part. The library requires passing funct

Re: const and immutable member variables in classes

2016-02-02 Thread Ali Çehreli via Digitalmars-d-learn
On 02/02/2016 03:02 PM, anonymous wrote: > I'm not sure what you mean by "default assignment". I think I meant member-wise assignment. :) > I'd say it works > more simply with classes, because they're reference types. It's the same > as using pointers to structs: > > auto a = new S(); > auto b

Re: const and immutable member variables in classes

2016-02-02 Thread anonymous via Digitalmars-d-learn
On 02.02.2016 23:48, Ali Çehreli wrote: struct S { const int c;// Makes S non-assignable immutable int i;// Makes S non-assignable } void main() { auto a = S(); auto b = S(); a = b; // Compilation ERROR } (That is the same issue in C++.) That's

Binding to C - Arrays and Access Violation

2016-02-02 Thread jmh530 via Digitalmars-d-learn
I'm working on generating a binding to a C library. I've got the .h file converted and can call some parts of the library with no errors. However, I have reached a stumbling block in a critical part. The library requires passing function pointers to various functions in the library. When I tr

const and immutable member variables in classes

2016-02-02 Thread Ali Çehreli via Digitalmars-d-learn
const and immutable members make structs non-assignable: struct S { const int c;// Makes S non-assignable immutable int i;// Makes S non-assignable } void main() { auto a = S(); auto b = S(); a = b; // Compilation ERROR } (That is the same issue in C

Re: Linking C libraries with DMD

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 20:06:05 UTC, jmh530 wrote: I suspect that if I re-compile the dll using Visual Studio, then it will work with D. Yeah, this is what finally allowed me to progress. Unfortunately, my sample example compiles, but throws an Access Violation error when I run it.

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 17:35:25 UTC, Chris Wright wrote: On Tue, 02 Feb 2016 15:59:06 +, Atila Neves wrote: [...] I've seen this sort of thing before. A blogger I used to follow, Jeremy Miller, implemented an event broker using this pattern. I don't like it. It requires a new typ

Re: Linking C libraries with DMD

2016-02-02 Thread jmh530 via Digitalmars-d-learn
On Friday, 22 January 2016 at 04:43:52 UTC, Mike Parker wrote: [snip] Thanks again for your help. I've worked through some simple examples and started trying to write a binding to a C library. I think I've got the .h file converted properly (the D file compiles), but I was getting a linking

Re: Determine type of property

2016-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/16 2:04 PM, NX wrote: On Tuesday, 2 February 2016 at 03:36:25 UTC, Steven Schveighoffer wrote: int y() { return 1;} No need for meta-programming hackery, mark it as @property: int y() @property { return 1;} I don't have control over S. I am passed S and need to figure out that it q

Re: DMD OSX / Segfault 11

2016-02-02 Thread anonymous via Digitalmars-d-learn
On 02.02.2016 19:06, Robert M. Münch wrote: I have a very strange effect, I'm not sure what it is about: Value: {} WordV: Value { Value* get() {} } BaseOperator: Value : { } This isn't valid D code at all, which makes it unnecessarily hard to understand what you mean. Now comes the

Re: Determine type of property

2016-02-02 Thread NX via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 03:36:25 UTC, Steven Schveighoffer wrote: int y() { return 1;} No need for meta-programming hackery, mark it as @property: int y() @property { return 1;}

Re: DMD OSX / Segfault 11

2016-02-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/2/16 1:06 PM, Robert M. Münch wrote: I have a very strange effect, I'm not sure what it is about: Value: {} WordV: Value { Value* get() {} } BaseOperator: Value : { } Now comes the code using this: auto op = cast(BaseOperator)(Word.get()); if (op !is null) {... If get() returns

DMD OSX / Segfault 11

2016-02-02 Thread Robert M. Münch via Digitalmars-d-learn
I have a very strange effect, I'm not sure what it is about: Value: {} WordV: Value { Value* get() {} } BaseOperator: Value : { } Now comes the code using this: auto op = cast(BaseOperator)(Word.get()); if (op !is null) {... If get() returns "Value*" it segfaults, if I change it to

Re: chain(const(array of class)) fails

2016-02-02 Thread SimonN via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 10:58:35 UTC, Marc Schütz wrote: The constraint that fails is the one with `CommonType`: `CommonType` uses the `?:` operator to derive the common type: I filed a bug report: https://issues.dlang.org/show_bug.cgi?id=15638 Interesting reduced case, so it wasn't cha

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Gerald via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 15:59:06 UTC, Atila Neves wrote: Slots are named: the methods are slots. Signals can be named if you use only one struct as the parameter, as above. The signals would be String1 and String2, the slots watch1 and watch2. What I meant is that the connect call didn'

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Chris Wright via Digitalmars-d-learn
On Tue, 02 Feb 2016 15:59:06 +, Atila Neves wrote: > struct String1 { string s; } > struct String2 { string s; } I've seen this sort of thing before. A blogger I used to follow, Jeremy Miller, implemented an event broker using this pattern. I don't like it. It requires a new type for each ev

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Kagamin via Digitalmars-d-learn
http://dpaste.dzfl.pl/f888feb6f743

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:49:21 UTC, Gerald wrote: On Monday, 1 February 2016 at 21:44:28 UTC, Enjoys Math wrote: On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots: https://dlang.org/pho

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:55:42 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: if you mix ints and floats, the common type is deduced correctly: this is a bug for me :). I do not like this. I am ok with (u)byte to int conversion and similar, b

Re: Switch with dynamic case

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 15:01:57 UTC, anonymous wrote: On 02.02.2016 15:07, Daniel Kozak wrote: [...] The key thing to understand is that the foreach is a "static" one. A static foreach is unrolled at compile-time. [...] Thanks :), this is all I need to know

Re: Switch with dynamic case

2016-02-02 Thread anonymous via Digitalmars-d-learn
On 02.02.2016 15:07, Daniel Kozak wrote: import std.stdio; import std.typetuple : TypeTuple; alias cs = TypeTuple!(0, 1, 2, 3); void main(string[] argv) { switch(argv.length) { default: writeln("Uknown number of args"); break; foreach(c; cs) { c

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:47:43 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 14:12:54 UTC, Daniel Kozak wrote: On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issue

Re: How would you implement this in D? (signals & slots)

2016-02-02 Thread Gerald via Digitalmars-d-learn
On Monday, 1 February 2016 at 21:44:28 UTC, Enjoys Math wrote: On Monday, 1 February 2016 at 21:40:45 UTC, Enjoys Math wrote: module signals_and_slots; import std.algorithm: remove; [...] D's signals & slots: https://dlang.org/phobos/std_signals.html I looked at that and perhaps I'm not

Re: Variadic template parameters T... bounding

2016-02-02 Thread Voitech via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: [...] Two possible solutions... If you don't need to know the number of arguments at compile time, you can use normal variadic arguments: [...] Thank you I'll try t

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:57:54 UTC, Marc Schütz wrote: On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640 I would say it is not a bug te

Switch with dynamic case

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
import std.stdio; import std.typetuple : TypeTuple; alias cs = TypeTuple!(0, 1, 2, 3); void main(string[] argv) { switch(argv.length) { default: writeln("Uknown number of args"); break; foreach(c; cs) { case c: writefln("%s args", c); break

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:52:55 UTC, Marc Schütz wrote: The last call should work IMO, but it doesn't. I believe that's a compiler bug. Filed: https://issues.dlang.org/show_bug.cgi?id=15640

Re: Variadic template parameters T... bounding

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers Two possible solutions... If you don't need to

Re: Variadic template parameters T... bounding

2016-02-02 Thread Daniel Kozak via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 13:20:33 UTC, Voitech wrote: Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers import std.stdio; import std.meta: allSatisfy;

Variadic template parameters T... bounding

2016-02-02 Thread Voitech via Digitalmars-d-learn
Hi, Is it possible to bound T... in template with some type ? For single Parameter declaration it can be done by T:SomeType but variadics does not seems to have that possibility ? Cheers

Re: chain(const(array of class)) fails

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 2 February 2016 at 09:51:52 UTC, Marc Schütz wrote: The constraint that fails is the one with `CommonType`: pragma(msg, CommonType!(const(B), const(C))); // void `CommonType` uses the `?:` operator to derive the common type: writeln(true ? b : c); // Error: incompatible

Re: chain(const(array of class)) fails

2016-02-02 Thread Marc Schütz via Digitalmars-d-learn
The constraint that fails is the one with `CommonType`: pragma(msg, CommonType!(const(B), const(C))); // void `CommonType` uses the `?:` operator to derive the common type: writeln(true ? b : c); // Error: incompatible types for ((b) : (c)): 'const(B[])' and 'const(C[])' write