Re: automate tuple creation

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 01:33:16 UTC, Steven Schveighoffer wrote: That second `valuesPerRecord` is not used in the lambda, and also it's not referring to the original element, it's the name of a parameter in the lambda. Are you sure this is doing what you want? -Steve It just

Is anyone planning to participate in Google HashCode 2022?

2022-01-22 Thread Siarhei Siamashka via Digitalmars-d-learn
Hello, I'm just trying to see if it's maybe possible to find some teammates here for https://codingcompetitions.withgoogle.com/hashcode ? That said, I have never participated in HashCode before and I'm not exactly committed yet. So I may abandon this idea if it doesn't work out and/or

forward tuple arg to local variable + dtor

2022-01-22 Thread vit via Digitalmars-d-learn
Hello, Why is tuple variable `params` immediately destructed after its construction? Why is `check(-2)` after `dtor(2)`? Code: ```d import std.stdio : writeln; import core.lifetime : forward, move; struct Foo{ int i; this(int i){ this.i = i; writeln("ctor(", i,

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Adam Ruppe via Digitalmars-d-learn
You can't forward to a local variable. Local variables will be a copy of the tuple. forward only actually works if sent *directly* to another function call. There's a bunch of things in D that only work in function parameter lists and not local variables. This is one of them.

How to do same as 'nmap' command from within a D program?

2022-01-22 Thread Daren Scot Wilson via Digitalmars-d-learn
I'm writing a command line program to control certain hardware devices. I can hardcode or have in a config file the IP addresses for the devices, if I know that info. If I don't? Then I run an 'nmap' command and look for the devices. But why should I, a human, have to do any work like that?

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread frame via Digitalmars-d-learn
On Saturday, 22 January 2022 at 20:55:38 UTC, Daren Scot Wilson wrote: I don't see any D std.* libraries that do this. Are there a Dub packages I should look at? If you really want to this in D without any external app or OS API you could just ping all possible hosts, see which respond and

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread vit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 17:23:12 UTC, Ali Çehreli wrote: On 1/22/22 07:17, vit wrote: > Why local variable of type tuple call destructors immediately after > initialization? I don't even understand where the local variable comes from. If you want a pair of Foo objects, I would use

Re: Ensuring allocation isn't thread-local?

2022-01-22 Thread Jaime via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:06:38 UTC, Adam D Ruppe wrote: No. Anything allocated with `new` is not thread local... and even if it was, you can send the pointer to other threads anyway. The only things in thread local storage are the direct values in the non-shared global variables.

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread vit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 14:23:32 UTC, Adam Ruppe wrote: You can't forward to a local variable. Local variables will be a copy of the tuple. forward only actually works if sent *directly* to another function call. There's a bunch of things in D that only work in function parameter

map question

2022-01-22 Thread forkit via Digitalmars-d-learn
trying to make sense of the below: // --- module test; import std; void main() { auto rnd = Random(unpredictableSeed); int howManyTimes = 5; // ok - using 'e =>' makes sense writeln(howManyTimes.iota.map!(e => rnd.dice(0.6, 1.4)).format!"%(%s,%)"); // ok - though

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 1/22/22 07:17, vit wrote: > Why local variable of type tuple call destructors immediately after > initialization? I don't even understand where the local variable comes from. If you want a pair of Foo objects, I would use std.typeconst.Tuple. Otherwise I would use AliasSeq as I understand

Ensuring allocation isn't thread-local?

2022-01-22 Thread Jaime via Digitalmars-d-learn
Howdy. How do I make sure data isn't allocated thread-local, if I also want to immediately use it in a thread-local way, because, for instance, I happen to already possess its intended mutex, which was allocated before it? Is this sufficient? Also, is it even something to worry about? ```d

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 18:00:58 UTC, vit wrote: I want implement something like this: Scratch the previous reply, 'twas a brain fart... Simply take by value, no need for extra copies at all in that case. Arguments themselves will become those copies as needed. ```d import

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread vit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:01:09 UTC, Stanislav Blinov wrote: On Saturday, 22 January 2022 at 18:00:58 UTC, vit wrote: [...] Take by value and make a copy without forwarding: ```d import std.typecons : Tuple; import std.meta : allSatisfy; [...] Thanks, second options is what I

Re: map question

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:32:07 UTC, forkit wrote: trying to make sense of the below: // --- module test; import std; void main() { auto rnd = Random(unpredictableSeed); int howManyTimes = 5; // ok - using 'e =>' makes sense writeln(howManyTimes.iota.map!(e =>

Re: forward tuple arg to local variable + dtor

2022-01-22 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 22 January 2022 at 18:00:58 UTC, vit wrote: I want implement something like this: ... Take by value and make a copy without forwarding: ```d import std.typecons : Tuple; import std.meta : allSatisfy; enum bool isRcPtr(T) = is(T == RcPtr!U, U); //@safe access to data of

Re: map question

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 19:55:43 UTC, Stanislav Blinov wrote: thanks for the explanation. That really helped :-) writeln( generate!(() => dice(0.6, 1.4)).take(howManyTimes) ); [1, 1, 1, 1, 0] (or after reading Ali's response - getting rid of rnd, and using _ ) writeln(

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 20:55:38 UTC, Daren Scot Wilson wrote: is this helpful: // --- module test; import std; void main() { auto result = execute(["bash", "-c", "nmap -sn 192.168.11.0/24 | ack -B2 \"Phillips\""]); if(canFind(result.to!string, "Host is up"))

Re: Ensuring allocation isn't thread-local?

2022-01-22 Thread Adam D Ruppe via Digitalmars-d-learn
On Saturday, 22 January 2022 at 18:55:30 UTC, Jaime wrote: A) Do I need to worry about data being / not being in thread-local storage? No. Anything allocated with `new` is not thread local... and even if it was, you can send the pointer to other threads anyway. The only things in thread

Re: map question

2022-01-22 Thread Ali Çehreli via Digitalmars-d-learn
On 1/22/22 11:32, forkit wrote: > trying to make sense of the below: The generate() solution shown by Stanislav Blinov is suitable here. > auto rnd = Random(unpredictableSeed); Somebody else mentioned this before but none of the programs we've seen so far seemed to need a special random

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 22:44:31 UTC, forkit wrote: and here is how to get the ip (depending on the formatting of your output of course) // --- module test; import std; void main() { auto result = execute(["bash", "-c", "nmap -sn 192.168.11.0/24 | ack -B2 \"Philips\""]);

Re: How to do same as 'nmap' command from within a D program?

2022-01-22 Thread forkit via Digitalmars-d-learn
On Saturday, 22 January 2022 at 23:15:18 UTC, forkit wrote: oh.. this is better i think... ip = str[ ((lastIndexOf(str, "(")) + 1) .. lastIndexOf(str, ")") ];