Re: Constraining template with function signature

2016-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/16 9:42 PM, Carl Vogel wrote: Hi, What's the best way, when using a Callable as a template parameter, to constrain it by signature? For example, if you have a function that sorts an array like so: T[] sortArray(alias less, T)(T[] arr) { ... } Then you know that you'd want `less` to hav

Constraining template with function signature

2016-06-07 Thread Carl Vogel via Digitalmars-d-learn
Hi, What's the best way, when using a Callable as a template parameter, to constrain it by signature? For example, if you have a function that sorts an array like so: T[] sortArray(alias less, T)(T[] arr) { ... } Then you know that you'd want `less` to have signature (T, T) -> bool. Now,

Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-07 Thread Mike Parker via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 22:28:57 UTC, Steven Schveighoffer wrote: It's news to me that while opCast for all other types is for explicit casting, opCast for bool works for implicit casting. as ag0... mentioned in another thread, opCast is NOT implicitly being invoked here, but rather expl

Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/16 6:15 PM, Ali Çehreli wrote: On 06/06/2016 08:28 AM, Adam D. Ruppe wrote: On Monday, 6 June 2016 at 15:23:50 UTC, chmike wrote: I would like an implicit conversion of Info to bool that return false if category_ is null so that I can write add: bool opCast(T : bool)() { return wha

Re: a lambda with arguments has type void?

2016-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/08/2016 12:02 AM, cy wrote: import std.stdio; void foo(Callable)(Callable bar) { bar(); } void foo2(Callable)(Callable bar, int baz) { bar(baz); } void main() { foo({ writeln("okay"); }); foo2((bar) { writeln("got",bar); },42); foo2((bar) => writeln

Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 06/06/2016 08:28 AM, Adam D. Ruppe wrote: On Monday, 6 June 2016 at 15:23:50 UTC, chmike wrote: I would like an implicit conversion of Info to bool that return false if category_ is null so that I can write add: bool opCast(T : bool)() { return whatever; } to the struct and it should w

Re: Parse File at compile time, but not embedded

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:57:20 UTC, Pie? wrote: On Monday, 6 June 2016 at 21:31:32 UTC, Alex Parrill wrote: But reading sensitive data at compile-time strikes me as dangerous, depending on your use case. If you are reading sensitive information at compile time, you are presumably going to

a lambda with arguments has type void?

2016-06-07 Thread cy via Digitalmars-d-learn
This program errors out, when I try to pass lambdas that take arguments. How am I getting the syntax wrong here? Is there some reason you can't do this? import std.stdio; void foo(Callable)(Callable bar) { bar(); } void foo2(Callable)(Callable bar, int baz) { bar(baz); } void main() {

Re: Error: mutable method isolated.graphics.g3d.model.Model.begin is not callable using a const object

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 June 2016 at 21:55:00 UTC, ag0aep6g wrote: On 06/06/2016 11:25 PM, Alex Parrill wrote: You might be able to get away with casting the const away, if you are sure it won't modify the hash or equality check. Casting away const and then mutating has undefined behavior. The compiler

Re: Enum that can be 0 or null

2016-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 06/07/2016 08:50 PM, ParticlePeter wrote: On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote: I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later. It does for type bool, but I fear that's the only exception. No, op

Re: Enum that can be 0 or null

2016-06-07 Thread ParticlePeter via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 14:31:40 UTC, Alex Parrill wrote: I don't think opCast gets called for implicit conversions; it only gets called for explicit casts. I'll test it later. It does for type bool, but I fear that's the only exception.

Re: Recommended coding convention for combining unix and windows code ?

2016-06-07 Thread wobbles via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:33:57 UTC, chmike wrote: Hello I'm writing some code that I want to be portable across Posix and Windows. What is the recommended code convention for such type of code ? 80% of the class implementation is the same for both OS. Should I write the following and c

Re: Recommended coding convention for combining unix and windows code ?

2016-06-07 Thread Johan Engelen via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:33:57 UTC, chmike wrote: or should I do it the C way with multiple embedded static if... In your example, `version` would also work instead of `static if`. I would not copy much code needlessly, and go with the embedded version/static ifs. - Johan

Re: Implicit conversion of struct to bool for if (s) operation ?

2016-06-07 Thread Basile B. via Digitalmars-d-learn
On Monday, 6 June 2016 at 15:34:18 UTC, chmike wrote: On Monday, 6 June 2016 at 15:28:35 UTC, John wrote: Thank you John and Adam. That was a quick answer ! Too late but another option would have been to put an alias this on a bool getter: struct Info { bool getStuff() { retu

Re: struct on heap with std.experimental.allocator

2016-06-07 Thread jmh530 via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:43:34 UTC, Adam D. Ruppe wrote: On Tuesday, 7 June 2016 at 15:39:59 UTC, jmh530 wrote: My sense is that putting it on the GC heap gives the struct reference semantics. It doesn't matter what heap it is on, you are just using a pointer here. Struct pointers in D

Re: Recommended coding convention for combining unix and windows code ?

2016-06-07 Thread FreeSlave via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:33:57 UTC, chmike wrote: Hello I'm writing some code that I want to be portable across Posix and Windows. What is the recommended code convention for such type of code ? 80% of the class implementation is the same for both OS. Should I write the following and c

Re: struct on heap with std.experimental.allocator

2016-06-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 15:39:59 UTC, jmh530 wrote: My sense is that putting it on the GC heap gives the struct reference semantics. It doesn't matter what heap it is on, you are just using a pointer here. Struct pointers in D will automatically dereference with a.x, so no need for the *

struct on heap with std.experimental.allocator

2016-06-07 Thread jmh530 via Digitalmars-d-learn
I modified one of the first examples from std.experimental.allocator to put a struct on the heap (below). My sense is that putting it on the GC heap gives the struct reference semantics. I was struck by two things. First, I didn't have to use (*a).x, I could just use a.x. Also, when I assign a

Recommended coding convention for combining unix and windows code ?

2016-06-07 Thread chmike via Digitalmars-d-learn
Hello I'm writing some code that I want to be portable across Posix and Windows. What is the recommended code convention for such type of code ? 80% of the class implementation is the same for both OS. Should I write the following and copy past the 80% version( Windows ) { import core.s

Re: Enum that can be 0 or null

2016-06-07 Thread Alex Parrill via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 04:31:56 UTC, ParticlePeter wrote: On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote: They'd be the same type, since you would define the vulkan functions to take these structures instead of pointer or integer types. It relies on a lot of assumptions about

Re: Error: castSwitch

2016-06-07 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 03:55:03 UTC, none wrote: import std.algorithm.iteration : map; import std.algorithm : castSwitch; import std.format : format; class A { int value; this(int value) { this.value = value; }} interface I { } class B : I { } Object[] arr = [new A(5), new B

Re: Easier way to add libraries to visual d?

2016-06-07 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 7 June 2016 at 08:49:16 UTC, TheDGuy wrote: On Friday, 3 June 2016 at 16:20:53 UTC, TheDGuy wrote: On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote: colorize works. You meant "serial-port" ? Does Coedit have the possibility to debug? Yes / No? No

Re: Enum that can be 0 or null

2016-06-07 Thread tsbockman via Digitalmars-d-learn
On Monday, 6 June 2016 at 20:32:23 UTC, Alex Parrill wrote: It relies on a lot of assumptions about the ABI that make a raw pointer work the same as a structure containing just one pointer, which is why I did not give it much consideration. At least some of those assumptions could be verified

Re: Easier way to add libraries to visual d?

2016-06-07 Thread TheDGuy via Digitalmars-d-learn
On Friday, 3 June 2016 at 16:20:53 UTC, TheDGuy wrote: On Thursday, 26 May 2016 at 17:06:03 UTC, Basile B. wrote: colorize works. You meant "serial-port" ? Does Coedit have the possibility to debug? Yes / No?

Testing D stuff

2016-06-07 Thread Russel Winder via Digitalmars-d-learn
Are there any test frameworks for D that are not specifically unit test frameworks? I thought testing had gone beyond being obsessed with units. Has anyone got property-based testing with shrinking? -- Russel. = Dr Russ