Re: Checking if a port is listening

2016-03-19 Thread Timothee Cour via Digitalmars-d-learn
see also: https://github.com/rejectedsoftware/vibe.d/issues/1431 api to find an available port On Fri, Mar 18, 2016 at 2:50 AM, Marc Schütz via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Looking at an strace of nmap, it seems it opens a bunch of sockets, puts > them

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 03/18/2016 03:50 AM, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want to know how to use it like

Re: immutable array in constructor

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 11:27:01 UTC, Rene Zwanenburg wrote: Also, if you mark the constructor as pure, new C() should be implicitly convertible to an immutable C. Ah! That's a good tip. Now I understand why I never have to say `new immutable(C)()` in my own code. (I am in the habit of

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 01:57:16 UTC, Jonathan M Davis wrote: Just assigning one to the other really isn't a problem, and sometimes you _want_ the wraparound. If you assume that it's always the case that assigning a negative value to an unsigned type is something that programmers don't

Re: Checking if a port is listening

2016-03-19 Thread Anonymouse via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:44:12 UTC, Lucien wrote: Hello, I want to know if a port of an ip address is listening, actually, I've this : http://pastebin.com/pZhm0ujy (checking port 22/ssh) It works, but it took me ~10min to scan 30 addresses. How can reduce the expiration delay ? I

Re: size_t index=-1;

2016-03-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 18, 2016 21:17:42 Jonathan M Davis via Digitalmars-d-learn wrote: > On Friday, March 18, 2016 23:48:32 tsbockman via Digitalmars-d-learn wrote: > > I'm basically saying, "because information is lost when casting > > between signed and unsigned, all such casts should be explicit".

Re: Destructor order

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/18/16 10:58 AM, Andrea Fontana wrote: On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 22:22:15 UTC, Anonymouse wrote: import core.thread; // for .seconds Nitpick: `seconds` is defined in `core.time`; `core.thread` just reexports it. s.setOption(SocketOptionLevel.SOCKET, SNDTIMEO, 10.seconds); s.setOption(SocketOptionLevel.SOCKET, RCVTIMEO,

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 01:57:16 UTC, Jonathan M Davis wrote: or wrap your integers in types that have more restrictive rules. IIRC, at least one person around here has done that already so that they can catch integer overflow - which is basically what you're complaining about here.

Re: size_t index=-1;

2016-03-19 Thread Ola Fosheim Grøstaf via Digitalmars-d-learn
On Thursday, 17 March 2016 at 22:46:01 UTC, tsbockman wrote: In the same way, using `cast(ulong)` to pass `-1L` to a function that expects a `ulong` results in a de-facto loss of information, because that `-1L` can no longer distinguished from `ulong.max`, despite the fundamental semantic

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote: Change those static if's to just plain old ifs. This only works (sometimes) because D's value range propagation doesn't understand comparisons or normal if statements very well. This will hopefully be fixed sooner or later:

Re: Destructor order

2016-03-19 Thread Jeremy DeHaan via Digitalmars-d-learn
On Friday, 18 March 2016 at 15:07:53 UTC, Andrea Fontana wrote: On Friday, 18 March 2016 at 15:03:14 UTC, Steven Schveighoffer wrote: On 3/18/16 10:58 AM, Andrea Fontana wrote: On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote:

Re: Checking if a port is listening

2016-03-19 Thread Lucien via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 22:22:15 UTC, Anonymouse wrote: On Wednesday, 16 March 2016 at 20:44:12 UTC, Lucien wrote: Hello, I want to know if a port of an ip address is listening, actually, I've this : http://pastebin.com/pZhm0ujy (checking port 22/ssh) It works, but it took me ~10min

Re: size_t index=-1;

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/17/16 6:46 PM, tsbockman wrote: On Thursday, 17 March 2016 at 17:09:46 UTC, Steven Schveighoffer wrote: Converting unsigned to signed or vice versa (of the same size type) is safe. No information is lost. Saying that "no information is lost" in such a case, is like saying that if I

string and char[] in Phobos

2016-03-19 Thread Puming via Digitalmars-d-learn
Hi, I saw from the forum that functions with string like arguments better use `in char[]` instead of `string` type, because then it can accept both string and char[] types. But recently when actually using D, I found that many phobos functions/constructors use `string`, while many returns

Re: size_t index=-1;

2016-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 22:07:39 UTC, Anonymouse wrote: size_t pos = "banana".indexOf("c"); if (pos > 0) { Although I also think it makes sense to warn (in specific cases) about mixed-sign comparisons, the example you give here does nothing that we can warn about. It is a comparison

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread rikki cattermole via Digitalmars-d-learn
On 16/03/16 11:18 PM, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) { static if (is(U ==

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote: On Wednesday, 16 March 2016 at 20:24:38 UTC, data pulverizer wrote: Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread jkpl via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:24:38 UTC, data pulverizer wrote: Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T x){ foreach(i, arg; x) writeln(i, " : ",

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
Looking at an strace of nmap, it seems it opens a bunch of sockets, puts them into non-blocking mode, calls connect on them (which will return EINPROGRESS), and then uses select(2) to wait for them (in a loop, until all have either been accepted or rejected). select(2) accepts a timeout value,

Re: size_t index=-1;

2016-03-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 18 March 2016 at 23:35:42 UTC, tsbockman wrote: `ulong.max` and `-1L` are fundamentally different semantically, even with two's complement modular arithmetic. Different types implies different semantics, but not the literals in isolation. Under modular arithmetics for an ubyte

Re: size_t index=-1;

2016-03-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 19 March 2016 at 10:01:41 UTC, Basile B. wrote: On Saturday, 19 March 2016 at 09:33:25 UTC, tsbockman wrote: [...] The reason that *attempting* such a comparison produces such weird results, is because the signed value is being implicitly cast to an unsigned type. Yes and that's

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Saturday, 19 March 2016 at 08:49:29 UTC, Ola Fosheim Grøstad wrote: On Friday, 18 March 2016 at 23:35:42 UTC, tsbockman wrote: `ulong.max` and `-1L` are fundamentally different semantically, even with two's complement modular arithmetic. Different types implies different semantics, but not

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 17:34:13 UTC, Steven Schveighoffer wrote: On 3/16/16 7:18 AM, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ```

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Saturday, 19 March 2016 at 04:17:42 UTC, Jonathan M Davis wrote: The only thing that I'm aware of that Walter has thought _might_ be something that we should change is allowing the comparison between signed and unsigned integers, and if you read what he says in the bug report for it, he

Re: Checking if a port is listening

2016-03-19 Thread Lucien via Digitalmars-d-learn
On Friday, 18 March 2016 at 09:50:12 UTC, Marc Schütz wrote: Looking at an strace of nmap, it seems it opens a bunch of sockets, puts them into non-blocking mode, calls connect on them (which will return EINPROGRESS), and then uses select(2) to wait for them (in a loop, until all have either

Re: size_t index=-1;

2016-03-19 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Saturday, 19 March 2016 at 09:35:00 UTC, tsbockman wrote: Both of the literals I used in my example explicitly indicate the type, not just the value. Yes, but few people specify unsigned literals and relies on them being implicitly cast to unsigned. You don't want to type 0UL and 1UL all

Re: size_t index=-1;

2016-03-19 Thread Basile B. via Digitalmars-d-learn
On Saturday, 19 March 2016 at 10:24:41 UTC, Ola Fosheim Grøstad wrote: On Saturday, 19 March 2016 at 10:01:41 UTC, Basile B. wrote: On Saturday, 19 March 2016 at 09:33:25 UTC, tsbockman wrote: [...] The reason that *attempting* such a comparison produces such weird results, is because the

Re: size_t index=-1;

2016-03-19 Thread Basile B. via Digitalmars-d-learn
On Saturday, 19 March 2016 at 09:33:25 UTC, tsbockman wrote: [...] The reason that *attempting* such a comparison produces such weird results, is because the signed value is being implicitly cast to an unsigned type. Yes and that's the opposite that should happend: when signed and unsigned

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote: void printVars(Args...)() if (Args.length > 0) { import std.stdio : writefln; foreach (i, arg; Args) { writefln("%s\t%s:\t%s", typeof(Args[i]).stringof, Args[i].stringof, arg); } } void main() { int abc = 3;

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Saturday, 19 March 2016 at 10:01:41 UTC, Basile B. wrote: Yes and that's the opposite that should happend: when signed and unsigned are mixed in a comparison, the unsigned value should be implictly cast to a wider signed value. And then it works! That would be reasonable. Whether it's

Re: string and char[] in Phobos

2016-03-19 Thread Kagamin via Digitalmars-d-learn
When a string is not an in parameter, it can't be declared `in char[]`.

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:24:38 UTC, data pulverizer wrote: Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T x){ foreach(i, arg; x) writeln(i, " : ",

Checking if a port is listening

2016-03-19 Thread Lucien via Digitalmars-d-learn
Hello, I want to know if a port of an ip address is listening, actually, I've this : http://pastebin.com/pZhm0ujy (checking port 22/ssh) It works, but it took me ~10min to scan 30 addresses. How can reduce the expiration delay ?

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Dsby via Digitalmars-d-learn
On Friday, 18 March 2016 at 11:09:37 UTC, Atila Neves wrote: On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ",

Re: size_t index=-1;

2016-03-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 16, 2016 18:40:56 Laeeth Isharc via Digitalmars-d-learn wrote: > should it be a compiler warning to assign a negative literal to > an unsigned without a cast ? Maybe? It's a common enough thing to do that I'm willing to bet that Walter would object, but what you're really

Re: Need help with delegates and vibed

2016-03-19 Thread Suliman via Digitalmars-d-learn
Thanks! I am understand a little bit better, but not all. ``` shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, ); } void handleRequest(HTTPServerRequest req, HTTPServerResponse res) { if

Class member always has the same address

2016-03-19 Thread szymski via Digitalmars-d-learn
Hello! I'm having a big problem with class members. I'm kinda new to D, so this may be my fault, but look at the following code: import std.stdio; class B { int variable; } class A { B b = new B(); } void main() { // Create 10 instances of A foreach(i; 0

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 9:48 PM, tsbockman wrote: On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote: Change those static if's to just plain old ifs. This only works (sometimes) because D's value range propagation doesn't understand comparisons or normal if statements very well. This will

Re: size_t index=-1;

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 4:55 PM, Mathias Lang wrote: On Wednesday, 16 March 2016 at 20:11:41 UTC, Steven Schveighoffer wrote: On 3/16/16 2:40 PM, Laeeth Isharc wrote: should it be a compiler warning to assign a negative literal to an unsigned without a cast ? Why? They implicitly convert. int x = -1;

Re: size_t index=-1;

2016-03-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, March 16, 2016 22:37:40 Mathias Lang via Digitalmars-d-learn wrote: > On Wednesday, 16 March 2016 at 21:49:05 UTC, Steven Schveighoffer > > wrote: > > No, please don't. Assigning a signed value to an unsigned (and > > vice versa) is very useful, and there is no good reason to > >

Re: size_t index=-1;

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 17:09:46 UTC, Steven Schveighoffer wrote: Converting unsigned to signed or vice versa (of the same size type) is safe. No information is lost. Saying that "no information is lost" in such a case, is like saying that if I encrypt my hard drive and then throw away

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread tsbockman via Digitalmars-d-learn
On Thursday, 17 March 2016 at 17:12:07 UTC, Steven Schveighoffer wrote: Yes. I agree. The way I look at it is that the code *is* reached in some cases, so it should compile (and just remove that section in that instance). IMO any time a template value is used for branching, it should turn

Re: Checking if a port is listening

2016-03-19 Thread Lucien via Digitalmars-d-learn
On Saturday, 19 March 2016 at 18:24:38 UTC, Marc Schütz wrote: On Saturday, 19 March 2016 at 09:55:13 UTC, Lucien wrote: const int MAX = 64; Socket[] sockets = new Socket[MAX]; string ipb = "192.168.0."; for (int i = 1; i < MAX; i++) { Here's the reason for your SEGV: You

Re: immutable array in constructor

2016-03-19 Thread Jeff Thompson via Digitalmars-d-learn
On Thursday, 17 March 2016 at 11:27:01 UTC, Rene Zwanenburg wrote: On Thursday, 17 March 2016 at 10:11:43 UTC, Jeff Thompson wrote: This is a simplified example from a larger class I have where I need an immutable constructor. This is because I need to construct an object an pass it to other

Re: Class member always has the same address

2016-03-19 Thread ag0aep6g via Digitalmars-d-learn
On 19.03.2016 21:24, szymski wrote: In my opinion should give different addresses for each instance of A, because it's not static. What am I doing wrong? Thanks in advance. The As are different, but they all reference the same B. Initialize b in a constructor instead.

Re: Need help with delegates and vibed

2016-03-19 Thread Alex Parrill via Digitalmars-d-learn
On Saturday, 19 March 2016 at 19:53:01 UTC, Suliman wrote: Thanks! I am understand a little bit better, but not all. ``` shared static this() { auto settings = new HTTPServerSettings; settings.port = 8080; listenHTTP(settings, ); } void handleRequest(HTTPServerRequest

Re: Destructor order

2016-03-19 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb There's two questions: 1) Is dtors always called in reverse order ? yes 2) Is all the dtors always called when i call destroy ? yes. destroy calls __dtor()

Re: Gdmd compiling error

2016-03-19 Thread Orkhan via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 12:20:32 UTC, Edwin van Leeuwen wrote: On Wednesday, 16 March 2016 at 12:17:42 UTC, Orkhan wrote: On Tuesday, 15 March 2016 at 18:26:48 UTC, Ali Çehreli wrote: I don't know where from shpuld I get help. Thanks. Is the xcomm library available somewhere, maybe if

Re: immutable array in constructor

2016-03-19 Thread Anonymouse via Digitalmars-d-learn
On Thursday, 17 March 2016 at 09:57:37 UTC, Jeff Thompson wrote: In the following code, I explicitly declare array as immutable. But it compiles with the error shown below in the comment. The array object is declared immutable, so how can the compiler say it is a mutable object? In summary,

Re: casting to a voldemort type

2016-03-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 19 March 2016 at 15:10:56 UTC, Alex wrote: void* funVoldemort(size_t my_size) The term 'voldemort type' refers to a public type, just an unnamed one. What you have here is a pointer to a private type... and void* is something you often should avoid since the compiler

casting to a voldemort type

2016-03-19 Thread Alex via Digitalmars-d-learn
Finally. A question about Voldemort types :) I have the following class, with an accompanying function. Skip the code to the link for a runnable version. /*--- code begin ---*/ class roof { int huhu = 9; void* funVoldemort(size_t my_size) { auto gg = huhu;

Re: immutable array in constructor

2016-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 03/17/2016 09:32 AM, Jeff Thompson wrote: On Thursday, 17 March 2016 at 11:27:01 UTC, Rene Zwanenburg wrote: On Thursday, 17 March 2016 at 10:11:43 UTC, Jeff Thompson wrote: This is a simplified example from a larger class I have where I need an immutable constructor. This is because I need

Re: size_t index=-1;

2016-03-19 Thread Mathias Lang via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 21:49:05 UTC, Steven Schveighoffer wrote: No, please don't. Assigning a signed value to an unsigned (and vice versa) is very useful, and there is no good reason to break this. -Steve I'm not talking about removing it completely. The implicit conversion should

Re: How do I extend an enum?

2016-03-19 Thread Basile B. via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived)

Re: How do I extend an enum?

2016-03-19 Thread Simen Kjaeraas via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived)

Re: Destructor order

2016-03-19 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb There's two questions: 1) Is dtors always

Re: module renaming by declaration

2016-03-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 19 March 2016 at 16:02:33 UTC, Christof Schardt wrote: What am I doing wrong? Using rdmd. It assumes the filename will match the module name to locate the file, though the language itself doesn't require this. What you want to do to make this work is use ordinary dmd and pass

module renaming by declaration

2016-03-19 Thread Christof Schardt via Digitalmars-d-learn
The module declaration allows to define a module name different from the filename. (TDPL sec. 11.1.8) I tried a simple example: File test.d: - import bbb; - File aaa.d (same directory): - module bbb; - Running rdmd test.d does give an error: "module bbb is

Re: Gdmd compiling error

2016-03-19 Thread Orkhan via Digitalmars-d-learn
On Tuesday, 15 March 2016 at 18:26:48 UTC, Ali Çehreli wrote: On 03/15/2016 02:45 AM, Orkhan wrote: > output of the gdc is : > > root@ubuntu:/home/alikoza/Downloads/i686-pc-linux-gnu# gdc > gdc: fatal error: no input files > compilation terminated. That makes sense. It should produce an

What is the best minimal runtime for d?

2016-03-19 Thread Taylor Hillegeist via Digitalmars-d-learn
I've been playing around with d with a KL25Z eval board. However it is not easy, It's not easy to know what features are and are not usable. when will i get a linker error to some __eabi_something_not_in_the_runtime. So, question is, does there exist a minimal runtime that will work with

Re: Gdmd compiling error

2016-03-19 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 12:17:42 UTC, Orkhan wrote: On Tuesday, 15 March 2016 at 18:26:48 UTC, Ali Çehreli wrote: I don't know where from shpuld I get help. Thanks. Is the xcomm library available somewhere, maybe if we had a link to the original documentation we could help.

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Atila Neves via Digitalmars-d-learn
On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Ali Çehreli via Digitalmars-d-learn
On 03/18/2016 09:14 AM, Dsby wrote: On Friday, 18 March 2016 at 11:09:37 UTC, Atila Neves wrote: On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int

Re: Implementing virtual dispatch in D

2016-03-19 Thread rikki cattermole via Digitalmars-d-learn
Read the ABI page again, its fairly sufficient about this stuff. --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Re: size_t index=-1;

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 2:40 PM, Laeeth Isharc wrote: should it be a compiler warning to assign a negative literal to an unsigned without a cast ? Why? They implicitly convert. int x = -1; uint y = x; I don't see a difference between this and your code. And we can't change this behavior of the second

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread rikki cattermole via Digitalmars-d-learn
On 17/03/16 5:05 AM, Johan Engelen wrote: On Wednesday, 16 March 2016 at 11:22:02 UTC, rikki cattermole wrote: Change those static if's to just plain old ifs. But then this wouldn't compile, would it? ``` static if(__traits(compiles, __traits(getMember, a, "b"))) { return a.b; } ```

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread Johan Engelen via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:47:35 UTC, QAston wrote: import std.meta; template isBool(U)() = is(U == bool); static if (!allSatisfy!(isBool, T)) { return true; // no longer emits a warning } Something like this should work. Thanks, but: On Wednesday, 16 March 2016 at 11:18:36 UTC,

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote: Hi all, I've found discussions, but not an actual "recommended" solution for the problem of "statement is not reachable" warnings in templates with early returns, e.g.: ``` bool nobool(T...)() { foreach (i, U; T) {

Re: Solution to "statement is not reachable" depending on template variables?

2016-03-19 Thread QAston via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 17:08:20 UTC, Johan Engelen wrote: On Wednesday, 16 March 2016 at 11:47:35 UTC, QAston wrote: import std.meta; template isBool(U)() = is(U == bool); static if (!allSatisfy!(isBool, T)) { return true; // no longer emits a warning } Something like this should

Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T x){ foreach(i, arg; x) writeln(i, " : ", arg); } void main(){ myfun(a = 2, b = "two", c = 2.0); } // should

No property error message

2016-03-19 Thread ric maicle via Digitalmars-d-learn
I got an error message with the following code saying: Error: no property 'length' for type 'int[string]' Shouldn't the error message say 'length()'? ~~~ import std.stdio; void main() { int[string] a; a["one"] = 1; a["two"] = 2; a["three"] = 3; auto len = a.length(); } ~~~ DMD

Re: Destructor order

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb There's two questions: 1) Is dtors always called in reverse order ? yes 2) Is all the dtors always called when i

Re: size_t index=-1;

2016-03-19 Thread Mathias Lang via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 20:11:41 UTC, Steven Schveighoffer wrote: On 3/16/16 2:40 PM, Laeeth Isharc wrote: should it be a compiler warning to assign a negative literal to an unsigned without a cast ? Why? They implicitly convert. int x = -1; uint y = x; I don't see a difference

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/16/16 4:24 PM, data pulverizer wrote: Hi D gurus, is there a way to obtain parameter names within the function body? I am particularly interested in variadic functions. Something like: void myfun(T...)(T x){ foreach(i, arg; x) writeln(i, " : ", arg); } void main(){

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread JR via Digitalmars-d-learn
On Thursday, 17 March 2016 at 11:52:13 UTC, Edwin van Leeuwen wrote: On Wednesday, 16 March 2016 at 20:53:42 UTC, JR wrote: void printVars(Args...)() if (Args.length > 0) { import std.stdio : writefln; foreach (i, arg; Args) { writefln("%s\t%s:\t%s", typeof(Args[i]).stringof,

Re: Checking if a port is listening

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Saturday, 19 March 2016 at 09:55:13 UTC, Lucien wrote: const int MAX = 64; Socket[] sockets = new Socket[MAX]; string ipb = "192.168.0."; for (int i = 1; i < MAX; i++) { Here's the reason for your SEGV: You need to start at 0, because otherwise `sockets[0]` is `null`. When

Re: Obtaining argument names in (variadic) functions

2016-03-19 Thread data pulverizer via Digitalmars-d-learn
On Wednesday, 16 March 2016 at 21:05:43 UTC, JR wrote: On Wednesday, 16 March 2016 at 20:43:09 UTC, jkpl wrote: I try to anticipate the reason why you want this. [...] I use something *kinda* sort of similar in my toy project to print all fields of a struct, for debugging purposes when stuff

Re: Class member always has the same address

2016-03-19 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 19 March 2016 at 20:24:15 UTC, szymski wrote: class A { B b = new B(); } This is *default* initialization, not per instance initialization. The compiler will create one instance of B and it will become the default initializer of b in *every* instance of A. You can

How do I extend an enum?

2016-03-19 Thread Lass Safin via Digitalmars-d-learn
Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived) instead. } void func(Derived d) {} func(Derived.E); // works.

Re: How do I extend an enum?

2016-03-19 Thread Lass Safin via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E = cast(Base)294, // Finally works. Can only be cast(Derived)

Re: immutable array in constructor

2016-03-19 Thread Jeff Thompson via Digitalmars-d-learn
On Thursday, 17 March 2016 at 10:04:53 UTC, Anonymouse wrote: On Thursday, 17 March 2016 at 09:57:37 UTC, Jeff Thompson wrote: In the following code, I explicitly declare array as immutable. But it compiles with the error shown below in the comment. The array object is declared immutable, so

Re: Whitch can replace std::bind/boost::bind ?

2016-03-19 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 18 March 2016 at 10:50:34 UTC, Dsby wrote: foreach (i ; 0..4) { auto th = new Thread(delegate(){listRun(i);});//this is erro _thread[i]= th; th.start(); } void listRun(int i) { writeln("i = ", i); // the value is not(0,1,2,3), it all is 2. } I want

Implementing virtual dispatch in D

2016-03-19 Thread maik klein via Digitalmars-d-learn
So this is mostly curiosity and not completely related to D but I would like to know how a vtable is actually implemented. All the explanations that I have seen so far are a bit vague and it would be nice to actually see some code. I tried to implement the following myself interface

Destructor order

2016-03-19 Thread Temtaime via Digitalmars-d-learn
Hi ! I wonder if i can rely on this code : http://dpaste.dzfl.pl/745cc5b1cdfb There's two questions: 1) Is dtors always called in reverse order ? 2) Is all the dtors always called when i call destroy ? Thanks for a reply !

Re: Destructor order

2016-03-19 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 18 March 2016 at 15:03:14 UTC, Steven Schveighoffer wrote: On 3/18/16 10:58 AM, Andrea Fontana wrote: On Friday, 18 March 2016 at 14:53:20 UTC, Steven Schveighoffer wrote: On 3/18/16 7:44 AM, Nicholas Wilson wrote: On Friday, 18 March 2016 at 10:20:40 UTC, Temtaime wrote: Hi ! I

Re: How do I extend an enum?

2016-03-19 Thread JR via Digitalmars-d-learn
On Saturday, 19 March 2016 at 17:41:29 UTC, Lass Safin wrote: On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote: Why: enum Base { A, B, } enum Derived : Base { C, // Gives error, says it can't implicitly convert expression to Base. D = 1, // Same error E =

Re: No property error message

2016-03-19 Thread JR via Digitalmars-d-learn
On Saturday, 19 March 2016 at 18:36:10 UTC, ric maicle wrote: I got an error message with the following code saying: Error: no property 'length' for type 'int[string]' Shouldn't the error message say 'length()'? ~~~ import std.stdio; void main() { int[string] a; a["one"] = 1;