Re: DMD: how to restore old unittest+main

2020-08-13 Thread Jonathan via Digitalmars-d-learn
On Thursday, 13 August 2020 at 07:52:07 UTC, novice3 wrote: Hello. I don't use dub. I use Windows and *.d file association to compile small apps by dmd with "-i -unittest -g" switches. Now i update dmd, and found, that apps compiled with "-unittest" not runs main(). How i can restore old beh

Arguments of function as an array.

2018-04-26 Thread Jonathan via Digitalmars-d-learn
Is there a way in D to take past arguments as an array? A like a normal Variadic function. All the arguments should be of the same type just as an array. Basically I want to allow a function like this to be called without square brackets. void fun(int[] intArray) { //... } void main()

`free` for struct with C bindings.

2018-05-14 Thread Jonathan via Digitalmars-d-learn
I am using a C bindings library (https://code.dlang.org/packages/xcb-d). I am following through a tutorial that was written for the C library directly and just making the minor changes to make it work with D. I ran into a problem. The library ends up giving me a struct pointer. ``` xcb_ge

Use std.traits.getSymbolsByUDA to access members of instance.

2018-10-01 Thread Jonathan via Digitalmars-d-learn
I can use `std.traits.getSymbolsByUDA` to get all the members of a class that have a particular UDA `getSymbolsByUDA(ValueType, UDA)`. But how do I get the values with it? Is there a more convenient way than `__traits(getMember, value, getSymbolsByUDA(ValueType, UDA)[0].stringof)`?

Implicit Casting

2018-02-06 Thread Jonathan via Digitalmars-d-learn
I am trying to make a `Pos` type. But I need it to implicitly cast from an `int[2]`. I am using the `alias this` to get most of what I want but it still doesn't do all an implicit cast can do. What I have now is this: struct Pos { int[2] pos; alias pos this; this (int

Template Constraints

2018-02-23 Thread Jonathan via Digitalmars-d-learn
I am having trouble finding many useful explanations of using template constraints beyond basic usage. I would like to have a template constrant to enforce that a type can be explicitly cast to another type: void (T)(T t) if (cast(int) T)//force `cast(int) T` to be possible

Re: Template Constraints

2018-02-24 Thread Jonathan via Digitalmars-d-learn
On Saturday, 24 February 2018 at 03:04:07 UTC, Adam D. Ruppe wrote: On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote: I am having trouble finding many useful explanations of using template constraints beyond basic usage. The constraint is just like static if as to what it allows

Equivalent to Python with Statement

2018-02-27 Thread Jonathan via Digitalmars-d-learn
I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()` called automatically ``` I know D's `with` statement does something different but is there some sort of equivalent?

Re: Equivalent to Python with Statement

2018-02-27 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 16:18:43 UTC, Stefan Koch wrote: On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote: I know Python's `with` statement can be used to have an automatic close action: ``` with open("x.txt") as file: #do something with file #`file.close()`

Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]

2018-02-27 Thread Jonathan via Digitalmars-d-learn
Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in memory exactly the same?

Re: Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]

2018-02-27 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 27 February 2018 at 22:13:05 UTC, Jonathan wrote: Is it possible to cast a 2d static length array to a 1d static length array? E.g. int[2][2] a = [[1,2],[3,4]]; int[4]b = cast(int[4])a; Is not the byte data in memory exactly the same? *( [pos,size].ptr .cst!(void*) .cst!(int[

Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe wrote: On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend wrote: I don't care if my computer needs to do math on a 4 byte basis, I'm not writing assembly. x86 actually doesn't need to do math that way, if you were writing asse

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: 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 it

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 for

Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn
I am totally lost on why this is happening. I stripped the code down to what appears to be the most minimal code that still causes the problem. --- import core.sync.mutex; import core.thread; import std.stdio; __gshared Mutex m;//__gshared just for testing (; void thread1() { foreach

Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn
On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote: I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line? dmd -run file.d

Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn
On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote: On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote: I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line? dmd -run file.d I am on Window 10 btw.

Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn
On Monday, 9 April 2018 at 22:56:33 UTC, Jonathan wrote: On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote: On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote: I don't know, but I can't reproduce either with dmd or ldc. What was your compilation line? dmd -run file.d I am on Window

Re: Strange Thread Causing Duplicating `writeln`

2018-04-11 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 23:59:08 UTC, Steven Schveighoffer wrote: On 4/9/18 6:56 PM, Jonathan wrote: On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote: On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote: I don't know, but I can't reproduce either with dmd or ldc. What was your com

switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn
Here's the setup, I have a function void main { ... } The main method parses input (via std.getopt) and calls one of three void-return-type functions. The program's three options correspond to significantly different initialization options. In the code we then have: enum RunOpt {op

Re: switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn
Try: enum RunOpt { opt1, opt2, opt3 } // No semicolon here final switch (option) with (RunOpt) { case opt1: fun1(...); break; case opt2: fun2(...); break; case opt3: fun3(...); break; } Bye, bearophile My hero.

Static if to compare two types are the exact same

2015-04-06 Thread Jonathan via Digitalmars-d-learn
What's the best way to do this? I'm assuming this should be best practice: http://dlang.org/traits.html#isSame struct S { } writeln(__traits(isSame, S, S));

Re: Static if to compare two types are the exact same

2015-04-06 Thread Jonathan via Digitalmars-d-learn
static if (is(T == V)) Are static ifs always checked outside of runtime? Is it possible for a static if condition to be undeterminable outside of runtime, or would such a condition throw a compiler error?