Showing a user specified error message when no overloads match

2014-07-25 Thread via Digitalmars-d-learn
I have a template function with a particular constraint (in this case [1]). When this constraint doesn't match, I want to give the user a suggestion what to do instead. The only way I know of to do this currently is to relax the template constraints, and adding a `static assert`. However, if

Trying to add automatic radix detection in std.conv.parse

2014-07-25 Thread klb via Digitalmars-d-learn
hello, I'd like to test if it's possible to add an automatic radix detection in std.conv, parse. I've added... if (s.length = 2) { if (s[0..2] == 0x || s[0..2] == 0X) { uint radix = 16; Source nbr = s[2..$];

Re: Mocking serial device

2014-07-25 Thread Alfredo Palhares via Digitalmars-d-learn
Hello. Just to finish this thread, umockdev[1] seems to be just what I want. Thank you for your sugestion! [1] https://github.com/martinpitt/umockdev

Re: dual with statement

2014-07-25 Thread Jay Norwood via Digitalmars-d-learn
On Friday, 25 July 2014 at 01:54:53 UTC, Jay Norwood wrote: I don't recall the exact use case for the database expressions, but I believe they were substituting a simple symbol for the fully qualified object. The sql with clause is quite a bit different than I remembered. For one thing, I

Associative array to Struct at compile time

2014-07-25 Thread BlackEdder via Digitalmars-d-learn
Is it possible to automatically convert an associative array to a struct? Basically I want to do the following (for any struct). struct A { double x = 1; } double[string] aa = [x:1]; auto a = toStruct!A( aa ); I've been trying to do this at compile time, but can't work out how setMembers

Re: Associative array to Struct at compile time

2014-07-25 Thread bearophile via Digitalmars-d-learn
BlackEdder: Is this possible at all? I think it's possible, as long as your associative array contents are known at compile-time. You can write a function that given the associative array returns a string that mixed-in defines the struct. And then you can define a toStruct template. Bye,

Array Operations question

2014-07-25 Thread via Digitalmars-d-learn
Hello! I started exploring D today and one of the things that caught my attention was the array operations feature. While playing around and writing some code with it, I came across a problem I wasn't able to find a solution for. The following is a simple example of the assignment array

Re: Array Operations question

2014-07-25 Thread bearophile via Digitalmars-d-learn
Márcio Martins: float[10] a; a[] = uniform(0.0f, 1.0f); This is going to set all values to the result of a single call to uniform(); Is there a way to express my intent that I want one result per array element? Currently D array operations can't be used for that kind of usage. So you

Re: Associative array to Struct at compile time

2014-07-25 Thread John Colvin via Digitalmars-d-learn
On Friday, 25 July 2014 at 15:25:43 UTC, BlackEdder wrote: Is it possible to automatically convert an associative array to a struct? Basically I want to do the following (for any struct). struct A { double x = 1; } double[string] aa = [x:1]; auto a = toStruct!A( aa ); I've been trying

Re: Associative array to Struct at compile time

2014-07-25 Thread BlackEdder via Digitalmars-d-learn
On Friday, 25 July 2014 at 15:48:54 UTC, John Colvin wrote: On Friday, 25 July 2014 at 15:25:43 UTC, BlackEdder wrote: Is it possible to automatically convert an associative array to a struct? Basically I want to do the following (for any struct). struct A { double x = 1; }

Re: D JSON (WAT?!)

2014-07-25 Thread Justin Whear via Digitalmars-d-learn
On Thu, 24 Jul 2014 22:00:43 +, Pavel wrote: On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real problem, which is JSON wrapper class. Is

findSplit

2014-07-25 Thread Gecko via Digitalmars-d-learn
Hello, is there a pretty way to split a range into 3 pieces, like findSplit, just with a predicate instead of comparing it with an element. Like this : void main() { import std.algorithm, std.stdio; auto list = [1,2,3,4,5,6,7]; writeln(findSplit!(x = x == 3 )(list));

Re: findSplit

2014-07-25 Thread Jakob Ovrum via Digitalmars-d-learn
On Friday, 25 July 2014 at 18:56:44 UTC, Gecko wrote: findSplit accepts a predicate but it doesnt compile for me if i use an other function than ((a,b) = a == b). Not at the moment. I've been working on a patch that makes the `findSplit*` family of algorithms as powerful as `find`, including

Re: dual with statement

2014-07-25 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 25 July 2014 at 01:54:53 UTC, Jay Norwood wrote: On Thursday, 24 July 2014 at 20:16:53 UTC, monarch_dodra wrote: Or did I miss something? Yes, sorry, I should have pasted a full example previously. The code at the end is with the Raw_met members renamed (they were originally a

Equivalent of DllMain on OSX?

2014-07-25 Thread Mark Isaacson via Digitalmars-d-learn
I am presently trying to port a driver I wrote for Windows to OSX. The one thing standing in my way is figuring out how to get the equivalent of DllMain on OSX. I need a place to call Runtime.initialize() and whatnot. Reading the wiki, it seemed like `shared static this()` was the

myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Timothee Cour via Digitalmars-d-learn
Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front) it's a common enough operation (analog to myrange[i]; the naming is from C++'s std::vectorT::at)

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, 25 July 2014 at 21:33:23 UTC, Timothee Cour via Digitalmars-d-learn wrote: Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front) it's a common enough operation (analog to myrange[i]; the naming is from C++'s std::vectorT::at) That would

Re: Equivalent of DllMain on OSX?

2014-07-25 Thread Joakim via Digitalmars-d-learn
On Friday, 25 July 2014 at 21:23:00 UTC, Mark Isaacson wrote: I am presently trying to port a driver I wrote for Windows to OSX. The one thing standing in my way is figuring out how to get the equivalent of DllMain on OSX. I need a place to call Runtime.initialize() and whatnot. Reading the

Re: Equivalent of DllMain on OSX?

2014-07-25 Thread Mark Isaacson via Digitalmars-d-learn
Loading multiple D shared libraries isn't supported on OS X yet, see these warnings in druntime: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/sections_osx.d#L198 If you only have a single D shared library, I think it's possible, you just may have to tweak

Re: D JSON (WAT?!)

2014-07-25 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/25/14, 1:06 PM, Justin Whear wrote: On Thu, 24 Jul 2014 22:00:43 +, Pavel wrote: On Thursday, 24 July 2014 at 16:09:25 UTC, Justin Whear wrote: On Thu, 24 Jul 2014 16:04:01 +, Pavel wrote: Thanks to all you folks who explained in operator for me. My bad. Let's focus on the real

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Ary Borenszweig via Digitalmars-d-learn
On 7/25/14, 6:39 PM, Jonathan M Davis wrote: On Friday, 25 July 2014 at 21:33:23 UTC, Timothee Cour via Digitalmars-d-learn wrote: Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front) it's a common enough operation (analog to myrange[i]; the naming is

Re: myrange.at(i) for myrange.dropExactly(i).front

2014-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, 26 July 2014 at 00:28:32 UTC, Ary Borenszweig wrote: On 7/25/14, 6:39 PM, Jonathan M Davis wrote: On Friday, 25 July 2014 at 21:33:23 UTC, Timothee Cour via Digitalmars-d-learn wrote: Is there a function for doing this? myrange.at(i) (with meaning of myrange.dropExactly(i).front)

Re: D JSON (WAT?!)

2014-07-25 Thread Meta via Digitalmars-d-learn
On Saturday, 26 July 2014 at 00:26:08 UTC, Ary Borenszweig wrote: Or use Algebraic, but it currently doesn't support recursive type definitions. Algebraic does support recursive type definitions. import std.variant; alias Rec = Algebraic!(int, This*); void main() { //I'm not sure why