Re: D RAII with postblit disabled

2018-03-26 Thread Norm via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 02:43:15 UTC, Adam D. Ruppe wrote: On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote: What's the best way to do this in D? I'd also add `@disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that

Re: D RAII with postblit disabled

2018-03-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 27 March 2018 at 02:35:23 UTC, Norm wrote: What's the best way to do this in D? I'd also add `@disable this();` and then a `static O make() { return O(theAllocator.make!int(99)); }` than you construct it with that static make function.

D RAII with postblit disabled

2018-03-26 Thread Norm via Digitalmars-d-learn
Hi All, What's the best way to do this in D? E.g. --- struct O { int* value; @disable this(this); /+ this() { this.value = theAllocator.make!int(99); } +/ ~this() { theAllocator.dispose(this.value); } } O obj = O(); // Ideally this would be allocated but it simply run

Re: Atomic vs Mutex

2018-03-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 26, 2018 23:15:42 Jonathan via Digitalmars-d-learn wrote: > Everywhere I look the advice is to avoid atomic and just mutex > things. > > Why is this `a.atomicStore(b)`(memory order is seq) less safe > than `synchronized{a=b}`? I get that when more operations or > shared values

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 22:13:02 UTC, Johan Engelen wrote: On Monday, 26 March 2018 at 22:07:49 UTC, Nordlöw wrote: When I try build my application using LDC and -flto=thin it fails in the final linking You must also pass `-flto=thin` during linking (a special plugin is needed for LTO,

Atomic vs Mutex

2018-03-26 Thread Jonathan via Digitalmars-d-learn
Everywhere I look the advice is to avoid atomic and just mutex things. Why is this `a.atomicStore(b)`(memory order is seq) less safe than `synchronized{a=b}`? I get that when more operations or shared values are used it is appropriate to mutex the entire set of operations but why would I

Re: The first example in the Learning D book, wont compile

2018-03-26 Thread Graham Fawcett via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:02:26 UTC, Ali wrote: On Sunday, 25 March 2018 at 20:52:29 UTC, Ali wrote: On Sunday, 25 March 2018 at 20:45:58 UTC, Ali wrote: I now see my typo, should be retro, not range We need better IDEs, this would have been easily highlighted by a good ide I pasted

Re: Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Johan Engelen via Digitalmars-d-learn
On Monday, 26 March 2018 at 22:07:49 UTC, Nordlöw wrote: When I try build my application using LDC and -flto=thin it fails in the final linking You must also pass `-flto=thin` during linking (a special plugin is needed for LTO, and LDC will only pass the plugin to the linker when `-flto=` is

Building application with LDC and -flto=thin fails in link stage

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
When I try build my application using LDC and -flto=thin it fails in the final linking as ldmd2 -of.dub/build/application-release-nobounds-lto-linux.posix-x86_64-ldc_2078-9FDE475789CA2E324E9DAE6A959C2B7F/knetquery

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 21:11:12 UTC, jmh530 wrote: Is each optimization level `x` in `-Ox` defined in the same way for clang and ldc? If so, where's the best documentation for it? https://wiki.dlang.org/Using_LDC Thx!

Re: Is socket.send thread safe?

2018-03-26 Thread Jonathan via Digitalmars-d-learn
On Monday, 26 March 2018 at 17:55:10 UTC, bauss wrote: On Monday, 26 March 2018 at 16:14:31 UTC, Jonathan wrote: Can I send data over an std.socket on multiple threads without manual mutexing? If not, can I send data on a separate thread than receive? The docs for std.socket say nothing of

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread jmh530 via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still be settable to "some" value or "no" value because the

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread jmh530 via Digitalmars-d-learn
On Monday, 26 March 2018 at 18:47:17 UTC, Nordlöw wrote: Yes I am, thanks, via the dub spec buildType "release-nobounds" { dflags "-mcpu=native" "-O3" buildOptions "releaseMode" "optimize" "noBoundsCheck" "inline" } I didn't measure any significant difference between -O

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 16:02:30 UTC, Rene Zwanenburg wrote: On Sunday, 25 March 2018 at 22:09:43 UTC, Nordlöw wrote: eventhough I compile with -release -inline -nobounds flags. Just to make sure: are you passing -O as well? Yes I am, thanks, via the dub spec buildType

Re: Is socket.send thread safe?

2018-03-26 Thread bauss via Digitalmars-d-learn
On Monday, 26 March 2018 at 16:14:31 UTC, Jonathan wrote: Can I send data over an std.socket on multiple threads without manual mutexing? If not, can I send data on a separate thread than receive? The docs for std.socket say nothing of it (which I guess means I should assume it is not thread

Is socket.send thread safe?

2018-03-26 Thread Jonathan via Digitalmars-d-learn
Can I send data over an std.socket on multiple threads without manual mutexing? If not, can I send data on a separate thread than receive? The docs for std.socket say nothing of it (which I guess means I should assume it is not thread safe but...). Thanks!

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Rene Zwanenburg via Digitalmars-d-learn
On Sunday, 25 March 2018 at 22:09:43 UTC, Nordlöw wrote: eventhough I compile with -release -inline -nobounds flags. Just to make sure: are you passing -O as well?

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 26, 2018 10:13:08 Simen Kjærås via Digitalmars-d-learn wrote: > On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: > > Have a look at Rebindable: > > https://dlang.org/phobos/std_typecons.html#rebindable > > Allow me to quote from aliak's post: > > what I'm looking

Re: C style array declaration.

2018-03-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:16:55 UTC, Aedt wrote: I'm a big fan of betterC. In C, you can initialize an array without specifying the length like this int ia[ ] = {0, 2, 1}; That's the equivalent of D's static arrays if a variable, and is passed to C functions as a pointer. So important

Re: Homebuilt dmd fails to link my dub application

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:57:28 UTC, Seb wrote: It doesn't add -noboundscheck by default. Typically the Makefiles allow passing an initial DFLAG variable, but that one doesn't seem to allow it, so I just submitted a PR to do so (https://github.com/dlang/dmd/pull/8089). With this PR you

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Seb via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:13:08 UTC, Simen Kjærås wrote: On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: Have a look at Rebindable: https://dlang.org/phobos/std_typecons.html#rebindable Allow me to quote from aliak's post: what I'm looking for is a Rebindable

Re: Homebuilt dmd fails to link my dub application

2018-03-26 Thread Seb via Digitalmars-d-learn
On Monday, 26 March 2018 at 10:01:38 UTC, Nordlöw wrote: On Sunday, 25 March 2018 at 20:35:01 UTC, Seb wrote: For building everything locally, it should be as easy as: --- git clone https://github.com/dlang/dmd git clone https://github.com/dlang/druntime git clone

Re: C style array declaration.

2018-03-26 Thread ag0aep6g via Digitalmars-d-learn
On 03/26/2018 12:16 PM, Aedt wrote: I'm a big fan of betterC. In C, you can initialize an array without specifying the length like this int ia[ ] = {0, 2, 1}; What is the translation of this? The language doesn't have that feature. But there's a PR to add `staticArray` to the standard

Re: C style array declaration.

2018-03-26 Thread rikki cattermole via Digitalmars-d-learn
On 26/03/2018 11:16 PM, Aedt wrote: I'm a big fan of betterC. In C, you can initialize an array without specifying the length like this int ia[ ] = {0, 2, 1}; What is the translation of this? Note that int[] is a different type than C's arrays.

C style array declaration.

2018-03-26 Thread Aedt via Digitalmars-d-learn
I'm a big fan of betterC. In C, you can initialize an array without specifying the length like this int ia[ ] = {0, 2, 1}; What is the translation of this? Note that int[] is a different type than C's arrays. https://dlang.org/spec/interfaceToC.html#data_type_compat says there are no

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 26 March 2018 at 09:46:57 UTC, Nicholas Wilson wrote: Have a look at Rebindable: https://dlang.org/phobos/std_typecons.html#rebindable Allow me to quote from aliak's post: what I'm looking for is a Rebindable implementation that's for value types As can be surmised from the

Re: Homebuilt dmd fails to link my dub application

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 25 March 2018 at 20:35:01 UTC, Seb wrote: For building everything locally, it should be as easy as: --- git clone https://github.com/dlang/dmd git clone https://github.com/dlang/druntime git clone https://github.com/dlang/phobos cd phobos && make -f posix.mak -j10 How do I build a

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: Hi, I have this optional type I'm working on and I've run in to a little snag when it comes to wrapping an immutable. Basically what I want is for an Optional!(immutable T) to still be settable to "some" value or "no" value because the

Re: How to use annotation get key name?

2018-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Monday, 26 March 2018 at 08:29:31 UTC, Brian wrote: Rust sample code: #[cfg(name = "users")] PHP sample code: /* @Table(name = "users") */ Java sample code: @Table(name = "users") How to use dlang get key name? If I understand your question correctly: struct Table { string name;

How to use annotation get key name?

2018-03-26 Thread Brian via Digitalmars-d-learn
Rust sample code: #[cfg(name = "users")] PHP sample code: /* @Table(name = "users") */ Java sample code: @Table(name = "users") How to use dlang get key name?

Re: Help with specific template function

2018-03-26 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Monday, 26 March 2018 at 06:48:45 UTC, rumbu wrote: isNumeric applies to a type, not to a variable => IsNumeric!X On Monday, 26 March 2018 at 06:51:48 UTC, arturg wrote: use the type not the variables: isNumeric!X && isNumeric!Y Ah, missed that. Thanks a bunch!

Re: Optional type - how to correctly reset a wrapped immutable T

2018-03-26 Thread Simen Kjærås via Digitalmars-d-learn
On Sunday, 25 March 2018 at 23:00:11 UTC, Simen Kjærås wrote: On Sunday, 25 March 2018 at 21:26:57 UTC, aliak wrote: struct Optional(T) { Unqual!T value; opAssign(T t) { value = cast(Unqual!T)(t); } } Consider this case: Optional!(immutable int) a = some(3); immutable int* p = a =

Re: Help with specific template function

2018-03-26 Thread arturg via Digitalmars-d-learn
On Monday, 26 March 2018 at 06:40:34 UTC, Vladimirs Nordholm wrote: How would I resolve this issue? use the type not the variables: isNumeric!X && isNumeric!Y

Re: Help with specific template function

2018-03-26 Thread rumbu via Digitalmars-d-learn
On Monday, 26 March 2018 at 06:40:34 UTC, Vladimirs Nordholm wrote: However I do not understand how to use that with my arguments. Eg. I would expect to do something like: void foo(X, Y, Args...)(X x, Y y, Args args) if(isNumeric!(x) && isNumeric!(y) && args.length >= 1) {

Re: Help with specific template function

2018-03-26 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Sunday, 25 March 2018 at 21:31:16 UTC, aliak wrote: On Sunday, 25 March 2018 at 19:06:14 UTC, Vladimirs Nordholm wrote: On Sunday, 25 March 2018 at 18:24:37 UTC, Vladimirs Nordholm wrote: The underlying problems are: * How do I ensure the two first arguments (used as coordinates) are types

Re: Aggressive conditional inlining with ldc only, not dmd

2018-03-26 Thread Nordlöw via Digitalmars-d-learn
On Sunday, 25 March 2018 at 22:30:50 UTC, kinke wrote: void foo() { version(LDC) pragma(inline, true); // affects foo() ... } Wonderful, thanks!