Re: How to make a generic function to take a class or struct by reference?

2022-03-27 Thread drug via Digitalmars-d-learn
Auto ref? ```D int* getX(T)(auto ref T t) { ... ```

Re: A debug class has started

2021-12-13 Thread drug via Digitalmars-d-learn
On 13.12.2021 14:26, ag0aep6g wrote: On 13.12.21 12:09, drug wrote: That's because `str` is initialized by a literal and you can not change it by definition. When you call `toStringz` it duplicates that literal (adding terminating zero at the end) and the duplicate is mutable. I would

Re: A debug class has started

2021-12-13 Thread drug via Digitalmars-d-learn
On 13.12.2021 13:49, forkit wrote: On Monday, 13 December 2021 at 09:49:05 UTC, forkit wrote: char* w = cast(char*)str.toStringz; // this seems to be the solution class has ended ;-) That's because `str` is initialized by a literal and you can not change it by definition. When you

Re: I need some help for my DCV update

2021-11-26 Thread drug via Digitalmars-d-learn
On 26.11.2021 12:16, Ferhat Kurtulmuş wrote: I am working on the DCV to make it compilable with the recent versions of LDC, mir libraries, and stuff. I have not yet simply forked it to work on it. I am including modules one by one for my convenience instead. Hope, I am close to the end. Here

Re: What is the proper way to outline static-if-conditions ?

2021-10-10 Thread drug via Digitalmars-d-learn
On 10.10.2021 18:01, Elmar wrote: Well, I just wondered why your code would compile and mine wouldn't. The `version(all)` variant will not compile on my computer with `rdmd` because `PointerTarget` only allows pointers. It depends on compiler version. This variant is compiled on version

Re: What is the proper way to outline static-if-conditions ?

2021-10-10 Thread drug via Digitalmars-d-learn
You just need to check if T is a pointer: ```D import std; alias DA = int[]; alias SA = int[3]; alias PSA = SA*; alias PDA = DA*; version(all) enum isPointedStaticArray(T) = isPointer!T && isStaticArray!(PointerTarget!T); else enum isPointedStaticArray(T) = isPointer!T &&

Re: GDC - program runs in one thread, DMD - in 4 threads, why?

2021-09-10 Thread drug via Digitalmars-d-learn
10.09.2021 12:27, eugene пишет: //import std.container.dlist; // dmd (v2.097.2) import std.container: DList; // gdc (4.9.2) It is off-topic a bit but I think none can compare gdc 4.9.2 to dmd 2.097.2 because gdc has older version than dmd. I would compare gdc to appropriate dmd version,

Re: How to get element type of a slice?

2021-08-17 Thread drug via Digitalmars-d-learn
17.08.2021 15:21, Ferhat Kurtulmuş пишет: Hello folks, Hope everyone is doing fine. Considering the following code, in the first condition, I am extracting the type Point from the slice Point[]. I searched in the std.traits, and could not find a neater solution something like

Re: I do not understand copy constructors

2021-08-12 Thread drug via Digitalmars-d-learn
12.08.2021 14:32, Paul Backus пишет: This is not true. Qualifying the ctor as `inout` works fine: https://run.dlang.io/is/Kpzp5M The problem in this example is that `.dup` always returns a mutable array, even if the array being copied is `inout`. The solution is to cast the copy back to

Re: I do not understand copy constructors

2021-08-12 Thread drug via Digitalmars-d-learn
12.08.2021 14:07, drug пишет: 12.08.2021 12:36, Learner пишет:  > It seems that there is no easy way to transition from a postblit to a copy constructor, no? You just need both const and mutable copy ctors to replace inout one: ```D struct A {     int[] data;     this(ref return scope A

Re: I do not understand copy constructors

2021-08-12 Thread drug via Digitalmars-d-learn
12.08.2021 12:36, Learner пишет: > It seems that there is no easy way to transition from a postblit to a copy constructor, no? You just need both const and mutable copy ctors to replace inout one: ```D struct A { int[] data; this(ref return scope A rhs) { data = rhs.data.dup; }

Re: Performance issue with fiber

2021-07-28 Thread drug via Digitalmars-d-learn
28.07.2021 17:39, Mathias LANG пишет: On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote: Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code. I took a quick look, and the first problem I saw was that you

Re: Initializing a complex dynamic array (with real part from one array, and imaginary from other array)?

2021-07-21 Thread drug via Digitalmars-d-learn
I wouldn't state it is the best way but you can try something like that: ```D import std.complex; import std.range : zip; import std.algorithm : equal, map; import std.array : array; void main(){ auto N=2; double[] x,y; x.length = N; y.length = N; x[0] = 1.1; x[1] =

Re: Trivial simple OpenGl working example

2021-07-08 Thread drug via Digitalmars-d-learn
08.07.2021 19:11, Виталий Фадеев пишет: I fix source code, as drug say. I've fixed the issue upstream, shortly gfm7 v1.1.2 will be available.

Re: Trivial simple OpenGl working example

2021-07-08 Thread drug via Digitalmars-d-learn
08.07.2021 18:46, Виталий Фадеев пишет: On Thursday, 8 July 2021 at 15:30:07 UTC, drug wrote: 08.07.2021 17:20, Виталий Фадеев пишет: [...] I failed to reproduce that. What platform you use and what is the compiler version? drug, Linux, Ubuntu, x64 # uname -a Linux unknown

Re: Trivial simple OpenGl working example

2021-07-08 Thread drug via Digitalmars-d-learn
08.07.2021 17:20, Виталий Фадеев пишет: vital@unknown:~/src/dtest/working-example/gfm7/examples/simpleshader$ dub run Fetching bindbc-opengl 0.15.0 (getting selected version)... Fetching colorize 1.0.5 (getting selected version)... Fetching gfm 8.0.6 (getting selected version)... Fetching

Re: Trivial simple OpenGl working example

2021-07-08 Thread drug via Digitalmars-d-learn
08.07.2021 16:51, Виталий Фадеев пишет: Hi! I searching trivial simple D/OpenGL working in 2021 year example. It may be triangle. It may be based on any library: SDL, GLFW, Derelict, etc. Can you help me ? https://github.com/drug007/gfm7/tree/master/examples/simpleshader it's not trivial

Re: How to disable assigning a value to a property?

2021-07-06 Thread drug via Digitalmars-d-learn
06.07.2021 13:06, Jack Applegame пишет: Code: ```d import std.stdio; struct Field {     void opAssign(int a) {     writefln("Field.opAssign(%s)", a);     } } struct Register {     Field clock(int a) {     writefln("Register.clock(%s)", a);     return Field();     } } void

Re: Any 3D Game or Engine with examples/demos which just work (compile) out of the box on linux ?

2021-06-07 Thread drug via Digitalmars-d-learn
07.06.2021 17:02, Prokop Hapala пишет: Basically I'm desperate do find anything which encapsulates OpenGL calls into some nice D-lang classes Did you try gfm? specifically its 7th version - [gfm7](https://github.com/drug007/gfm7)? It has nice

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-06-02 Thread drug via Digitalmars-d-learn
02.06.2021 12:50, Ola Fosheim Grøstad пишет: Depends on the data, I guess, if they are all visible at once then you basically have to very carefully write your own GPU render stage for that view and carefully cache things that does not move by rendering them to buffers (in GPU memory).

Re: wanting to try a GUI toolkit: needing some advice on which one to choose

2021-06-02 Thread drug via Digitalmars-d-learn
02.06.2021 00:47, Ola Fosheim Grøstad пишет: Note: Many simple GUI toolkits are horribly inefficient as they let each object render themselves.  An efficient GUI engine will have to replicate some of the browser complexity... I tried retained and immediate GUI, both fail (imho) for my use

Re: Format

2021-05-21 Thread drug via Digitalmars-d-learn
21.05.2021 16:45, newbie пишет: I am following https://wiki.dlang.org/Defining_custom_print_format_specifiers, why sink and formatValue are not @safe? What are the best practice for toString in safe code? Thank you sink is obsolete now, use W(riter) ```D import std.range : isOutputRange;

Re: gtkd ,drawingarea, capture mouse pressed

2021-05-21 Thread drug via Digitalmars-d-learn
21.05.2021 15:39, Alain De Vos пишет: I'll have a look at that website. With this code I capture the mouse press event ``` this() { addEvents(GdkEventMask.BUTTON_PRESS_MASK); addOnDraw(); addOnButtonPress(); } ``` ``` public bool onButtonPress(Event event, Widget widget) { writeln("Button

Re: Is inc function part of the library ?

2021-05-13 Thread drug via Digitalmars-d-learn
13.05.2021 16:30, Alain De Vos пишет: Shouldn't the compiler error it is not pure ? Or have I a wrong understanding of pure or the compiler. The function is pure. If you call it several times passing the same argument it will return the same result. https://run.dlang.io/is/futqjP

Re: Question about property & method access scope.

2021-05-11 Thread drug via Digitalmars-d-learn
11.05.2021 12:10, Vinod K Chandran пишет: Hi all, I am practising D with a win api GUI hobby project. I have a Window class and it resides in module window.d My WndProc function resides in another module named wnd_proc_module.d Inside my WndProc, I get the Window class like this. ```d Window win

Re: Iteratable single linked list of floats.

2021-04-21 Thread drug via Digitalmars-d-learn
21.04.2021 16:19, Alain De Vos пишет: import std.stdio; void main(){ struct List {     struct Node {     float f;     Node *next;     }     Node * root=null;     bool empty() const {return !root;}     void popFront() {root=root.next;}    

[OT]

2021-04-02 Thread drug via Digitalmars-d-learn
02.04.2021 15:06, Ali Çehreli пишет: For those who prefer a video description with some accent :) here is how What about accent - I'm curious what would you say about this old Russian sketch about English and its dialects (in English, no facebook account required):

Re: How to parse JSON in D?

2021-03-29 Thread drug via Digitalmars-d-learn
I use asdf https://code.dlang.org/packages/asdf Also vibe-d https://code.dlang.org/packages/vibe-d has vibe-d:data subpackage

Re: Can't call splitter with range struct

2021-03-16 Thread drug via Digitalmars-d-learn
On 3/16/21 1:58 AM, David Skluzacek wrote: > > Error: template std.algorithm.iteration.splitter cannot deduce function from argument types !()(GZippedFile, string), candidates are: > /usr/include/dlang/dmd/std/algorithm/iteration.d(4678): splitter(alias pred = "a == b", Range, Separator)(Range

Re: Profiling

2021-02-10 Thread drug via Digitalmars-d-learn
On 2/10/21 2:52 PM, JG wrote: On Tuesday, 9 February 2021 at 18:33:16 UTC, drug wrote: On Tuesday, 9 February 2021 at 07:45:13 UTC, JG wrote: I was trying to profile a d program. So I ran: dub build --build=profile. I then ran the program and it produced trace.log and trace.def. I then ran

Re: Profiling

2021-02-09 Thread drug via Digitalmars-d-learn
On Tuesday, 9 February 2021 at 07:45:13 UTC, JG wrote: I was trying to profile a d program. So I ran: dub build --build=profile. I then ran the program and it produced trace.log and trace.def. I then ran d-profile-viewer and got the following error:

Re: Using mir to work with matrices

2021-02-01 Thread drug via Digitalmars-d-learn
On 1/29/21 8:20 PM, 9il wrote: On Friday, 29 January 2021 at 15:35:49 UTC, drug wrote: Between is there a plan to implement some sort of static slice where the lengths of the dimensions are known in compile time? Compiler help is very useful. No. BLAS/LAPACK API's can't use compile-time

Re: Using mir to work with matrices

2021-01-29 Thread drug via Digitalmars-d-learn
On 1/29/21 4:50 PM, 9il wrote: On Tuesday, 26 January 2021 at 14:43:08 UTC, drug wrote: It is not easy to understand what mir library one should use to work with matrices. mir-glas turns out unsupported now and I try to use mir-blas. I need to reimplement my Kalman filter version to use more

Using mir to work with matrices

2021-01-26 Thread drug via Digitalmars-d-learn
It is not easy to understand what mir library one should use to work with matrices. mir-glas turns out unsupported now and I try to use mir-blas. I need to reimplement my Kalman filter version to use more high dimension matrix than 4x4 plus Kronecker product. Is mir-blas recommended to work

Re: Convert double to long if lossless

2021-01-20 Thread drug via Digitalmars-d-learn
On 1/19/21 9:28 PM, Per Nordlöw wrote: On Tuesday, 19 January 2021 at 16:14:17 UTC, drug wrote:    https://dlang.org/phobos/std_bitmanip.html#FloatRep Doesn't this pattern already cover all possible cases of `value` needed? void f(double value) {     auto lvalue = cast(long)value;     if

Re: Convert double to long if lossless

2021-01-19 Thread drug via Digitalmars-d-learn
On 1/19/21 6:50 PM, Ali Çehreli wrote: On 1/19/21 6:04 AM, drug wrote: > Another (low level) way is to shift mantissa left by exponent value. Luckily, we already have a helper in Phobos:   https://dlang.org/phobos/std_bitmanip.html#FloatRep Ali That makes life simpler, thanks for

Re: Convert double to long if lossless

2021-01-19 Thread drug via Digitalmars-d-learn
On 1/19/21 5:04 PM, drug wrote: On 1/19/21 4:48 PM, Per Nordlöw wrote: On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer wrote: Use a cast instead. const lvalue = cast(long)value; Ahh, good point. Followd by a compare of the original value I presume. don't forget to check

Re: Convert double to long if lossless

2021-01-19 Thread drug via Digitalmars-d-learn
On 1/19/21 4:48 PM, Per Nordlöw wrote: On Tuesday, 19 January 2021 at 13:36:58 UTC, Steven Schveighoffer wrote: Use a cast instead. const lvalue = cast(long)value; Ahh, good point. Followd by a compare of the original value I presume. don't forget to check by std.math.isFinite before

Re: Directory recursive walking

2021-01-14 Thread drug via Digitalmars-d-learn
On 1/14/21 7:06 PM, dog2002 wrote: On Thursday, 14 January 2021 at 16:01:43 UTC, drug wrote: On 1/14/21 6:55 PM, drug wrote: But this method consumes a huge amount of memory (up to 4 GB and more). Is there a more appropriate way to walk directories recursively that does not consume a lot of

Re: Directory recursive walking

2021-01-14 Thread drug via Digitalmars-d-learn
On 1/14/21 7:30 PM, dog2002 wrote: On Thursday, 14 January 2021 at 16:18:28 UTC, drug wrote: On 1/14/21 7:06 PM, dog2002 wrote: On Thursday, 14 January 2021 at 16:01:43 UTC, drug wrote: [...] Yes. I forgot to add it in the original post. Does using `ref` changed anything? Try following:

Re: Directory recursive walking

2021-01-14 Thread drug via Digitalmars-d-learn
On 1/14/21 7:06 PM, dog2002 wrote: On Thursday, 14 January 2021 at 16:01:43 UTC, drug wrote: On 1/14/21 6:55 PM, drug wrote: But this method consumes a huge amount of memory (up to 4 GB and more). Is there a more appropriate way to walk directories recursively that does not consume a lot of

Re: Directory recursive walking

2021-01-14 Thread drug via Digitalmars-d-learn
On 1/14/21 6:55 PM, drug wrote: But this method consumes a huge amount of memory (up to 4 GB and more). Is there a more appropriate way to walk directories recursively that does not consume a lot of memory? DirEntry is a struct. First of all I would try this: ```D foreach(ref entry;

Re: Directory recursive walking

2021-01-14 Thread drug via Digitalmars-d-learn
On 1/14/21 6:46 PM, dog2002 wrote: I need to make some operations with all the files in a directory and subdirectories. Currently, I do it like this: import std; void DirIteration(string path) {     try {     foreach(entry; dirEntries(path, SpanMode.shallow, false)) {

Re: How to debug D on Linux

2021-01-13 Thread drug via Digitalmars-d-learn
On 1/13/21 4:47 PM, Roguish wrote: Also, what does it mean to "always emit a stackframe" (compiler option -gs) ? Short answer - sometimes the compiler does not emit a stackframe (due to optimization for example). In general if you are able to debug your binary by gdb then you don't need to

Re: How to debug D on Linux

2021-01-13 Thread drug via Digitalmars-d-learn
On 1/13/21 4:47 PM, Roguish wrote: On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote: Anything else I need to know when debugging on Linux, without an IDE? One specific question I have is: what's the difference between -g and -debug and -d-debug? Also, what does it mean to

Re: Can I output strings using core.stdc.stdio?

2020-12-23 Thread drug via Digitalmars-d-learn
On 12/23/20 3:23 PM, Godnyx wrote: Any ideas? Just fix your typos: ```D import std : printf, toStringz; void put(A...)(string prompt, A args) { static foreach (ulong i; 0..args.length) { static if (is(typeof(args[i]) == string)) printf("%s\n", args[i].toStringz);

Re: Running unit tests from DUB single file packages

2020-12-22 Thread drug via Digitalmars-d-learn
On 12/22/20 8:32 PM, jmh530 wrote: On Tuesday, 22 December 2020 at 15:06:09 UTC, drug wrote: [snip] But what do you mean exactly by "work with dependency"? As I understand, `dub test` does not run unit tests in dependencies and single file packages work with dependencies in general. Do you

Re: Running unit tests from DUB single file packages

2020-12-22 Thread drug via Digitalmars-d-learn
On 12/22/20 10:52 AM, drug wrote: On 12/21/20 7:31 PM, jmh530 wrote: On Monday, 21 December 2020 at 11:31:49 UTC, drug wrote: [snip] Unfortunately I'm very busy. But I check it again and it turns out that the fix does not resolve the problem completely. This PR just remove the single file

Re: Running unit tests from DUB single file packages

2020-12-21 Thread drug via Digitalmars-d-learn
On 12/21/20 7:31 PM, jmh530 wrote: On Monday, 21 December 2020 at 11:31:49 UTC, drug wrote: [snip] Unfortunately I'm very busy. But I check it again and it turns out that the fix does not resolve the problem completely. This PR just remove the single file from testing so currently dub does

Re: Running unit tests from DUB single file packages

2020-12-21 Thread drug via Digitalmars-d-learn
On 12/20/20 9:31 PM, jmh530 wrote: On Wednesday, 2 December 2020 at 12:51:11 UTC, drug wrote: [snip] Thanks! Let's see if it gets merged or if a slightly more involved solution is needed. Remake it - https://github.com/dlang/dub/pull/2052 This has more chances to be merged Looks like

Re: binary search

2020-12-06 Thread drug via Digitalmars-d-learn
Phobos provides this by SortedRange: https://dlang.org/phobos/std_range.html#.SortedRange Example of usage: https://run.dlang.io/is/WW2bn0

Re: Running unit tests from DUB single file packages

2020-12-02 Thread drug via Digitalmars-d-learn
On 12/1/20 5:18 PM, Johannes Loher wrote: Am 01.12.20 um 14:55 schrieb drug: On 12/1/20 2:40 PM, Johannes Loher wrote: ... However, I am having trouble running the unit tests when using the ... This can be one of solution https://github.com/dlang/dub/pull/2050 Thanks! Let's see if it gets

Re: Running unit tests from DUB single file packages

2020-12-01 Thread drug via Digitalmars-d-learn
On 12/1/20 2:40 PM, Johannes Loher wrote: ... However, I am having trouble running the unit tests when using the ... This can be one of solution https://github.com/dlang/dub/pull/2050

Re: Druntime undefined references

2020-11-02 Thread drug via Digitalmars-d-learn
On 11/2/20 1:50 PM, Severin Teona wrote: Hi guys! I build the druntime for an ARM Cortex-M based microcontroller and I trying to create an application and link it with the druntime. I am also using TockOS[1], which does not implement POSIX thread calls and other OS-dependent implementations.

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread drug via Digitalmars-d-learn
There are two other way: ```D import std; void main() { int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]; // using foreach foreach (i; 0..a.length) write(a[i], ", "); writeln; // using stride writeln(stride(a, 2)); } ```

Re: GC-less string formatting

2020-10-20 Thread drug via Digitalmars-d-learn
On 10/20/20 9:42 AM, Per Nordlöw wrote: If I want GC-free string formatting and outputting to stdout/stderr what packages should I prefer at code.dlang.org? Probably https://code.dlang.org/packages/nogc

Re: question on dub and postgresql

2020-10-05 Thread drug via Digitalmars-d-learn
On 10/5/20 12:05 PM, Alaindevos wrote: On Monday, 5 October 2020 at 08:54:39 UTC, Daniel Kozak wrote: On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: Can I say python has pip, ruby has bundle and D has dub. Meaning they perform

Re: help: cannot build profdump, dub error (bug): Enforcement failed

2020-09-29 Thread drug via Digitalmars-d-learn
On 9/29/20 4:38 PM, drug wrote: It reproduces. As a workaround you can use ``` dub run profdump ``` this command works as expected, I guess it is a bug of dub Do not execute this command in cloned `profdump` repository - it will fail too. It works if is called from other places, for example

Re: help: cannot build profdump, dub error (bug): Enforcement failed

2020-09-29 Thread drug via Digitalmars-d-learn
On 9/29/20 3:41 PM, mw wrote: I remember I used to able to build this package: https://github.com/AntonMeep/profdump but now, I cannot. Since that package haven't changed for 2 years, maybe it's a dub bug? System information $ uname -a Linux  4.15.0-117-generic #118-Ubuntu SMP Fri Sep 4

Re: Why is dtor called for lazy parameter?

2020-09-18 Thread drug via Digitalmars-d-learn
On 9/18/20 4:30 PM, drug wrote: Can't you put a var on the stack? ``` auto instance = create(); instance     .do_lazy()     .do_something(); ``` Ah, I totally missed your point. Now I see you can't...

Re: Why is dtor called for lazy parameter?

2020-09-18 Thread drug via Digitalmars-d-learn
Can't you put a var on the stack? ``` auto instance = create(); instance .do_lazy() .do_something(); ```

Re: UDA inheritance

2020-09-10 Thread drug via Digitalmars-d-learn
On 9/10/20 4:06 PM, Joseph Rushton Wakeling wrote: Hello folks, Is there any way to define UDAs such that they automatically inherit other UDA definitions? For example, suppose I define:     enum BaseUDA { A, B } Is there a way to define `AnotherUDA` such that if `hasUDA!(T, AnotherUDA)`

Re: Where can I find the DEFINITION of vibe IOMode ??

2020-09-05 Thread drug via Digitalmars-d-learn
05.09.2020 23:19, Andy Balba пишет: https://github.com/vibe-d/eventcore/blob/a027c233c2542de8372bbff25d0a4804f32a094e/source/eventcore/driver.d#L1087 @drug: thank you..I'm now left with resolving @blocking you are welcome! Probably this?

Re: Where can I find the DEFINITION of vibe IOMode ??

2020-09-05 Thread drug via Digitalmars-d-learn
05.09.2020 22:17, Andy Balba пишет: Where do I fine where IOMode is defined..  as in the last line of ... module vibe.core.stream; import vibe.internal.traits : checkInterfaceConformance, validateInterfaceConformance; import vibe.internal.interfaceproxy; import core.time; import

Re: Install multiple executables with DUB

2020-09-04 Thread drug via Digitalmars-d-learn
On 9/4/20 10:27 AM, glis-glis wrote: On Thursday, 3 September 2020 at 14:34:48 UTC, Jacob Carlborg wrote: Oh, multiple binaries, I missed that. You can try to add multiple configurations [1]. Or if you have executables depending on only one source file, you can use single-file packages [2].

Re: Problem with gfm.math.matrix (some gamedevs out there ?)

2020-09-03 Thread drug via Digitalmars-d-learn
On 9/3/20 3:36 PM, Thomas wrote: Hi! I am following some examples in C++ about how OpenGL is working. There are great tutorials out there and most of it works also with D. For my code I am using gfm.math.matrix (Version 8.0.3) to be able to calculate the mouse position in a 3d world. Now I

Re: Unable to open filename passed as command line argument

2020-09-03 Thread drug via Digitalmars-d-learn
On 9/3/20 1:47 PM, Curious wrote: Given the following: =a== void main(string[] args) {     FILE* fp = fopen(args[1].ptr, "r");     if (!fp) throw new Exception("fopen"); } =b== void main(string[] args) {     FILE* fp = fopen(args[1].dup.ptr, "r");     if (!fp) throw new

Re: Accurately serializing and deserializing a SysTime in binary format

2020-07-21 Thread drug via Digitalmars-d-learn
On 7/21/20 2:44 PM, Ecstatic Coder wrote: Ah thanks for telling me :) The loaded byte array in the union type was indeed the same as the saved one, so I immediately thought it was crashing because of some hidden pointer for timezone or something which was then pointing to garbage at

Re: Accurately serializing and deserializing a SysTime in binary format

2020-07-21 Thread drug via Digitalmars-d-learn
On 7/20/20 10:04 PM, Ecstatic Coder wrote: I'm currently implementing a small open source backup tool (dub), and therefore I need to accurately store the file modification SysTime in binary format, so that I can later load this SysTime from the snapshot file to compare it with the current file

Re: Storing a reference to the calling object

2020-05-23 Thread drug via Digitalmars-d-learn
23.05.2020 12:27, Tim пишет: class Sprite{     /// Postional components of the sprite     int* x, y;     SDL_Surface* image_surface;     auto parent;     this(const char* path, auto parent){     writeln(*x);     this.parent = parent;     }     void update(){     // Copy

Re: Getting FieldNameTuple including all base-classes.

2020-05-20 Thread drug via Digitalmars-d-learn
On 5/20/20 12:03 PM, realhet wrote: On Wednesday, 20 May 2020 at 01:18:24 UTC, Paul Backus wrote: On Tuesday, 19 May 2020 at 23:15:45 UTC, realhet wrote: I think what you want is `std.meta.staticMap`. Something like this: alias FieldNameTuple2(T) = staticMap!(FieldNameTuple,

Re: How to get rid of "nothrow" ?

2020-05-18 Thread drug via Digitalmars-d-learn
On 5/18/20 11:47 PM, Vinod K Chandran wrote: On Sunday, 17 May 2020 at 19:37:05 UTC, drug wrote: 17.05.2020 17:35, Vinod K Chandran пишет: It worked. Thanks :) I have one more question. Which is better, to include all the switch cases inside a single try catch or write separate try catch

Re: How to get rid of "nothrow" ?

2020-05-17 Thread drug via Digitalmars-d-learn
17.05.2020 17:35, Vinod K Chandran пишет: It worked. Thanks :) I have one more question. Which is better, to include all the switch cases inside a single try catch or write separate try catch for each switch cases ? all the switch cases inside a single try catch is better

Re: Error running concurrent process and storing results in array

2020-05-07 Thread drug via Digitalmars-d-learn
07.05.2020 17:49, data pulverizer пишет: On Thursday, 7 May 2020 at 02:06:32 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 10:23:17 UTC, data pulverizer wrote: D:  ~ 1.5 seconds This is going to sound absurd but can we do even better? If none of the optimizations we have so

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 13:23, data pulverizer пишет: On Wednesday, 6 May 2020 at 08:28:41 UTC, drug wrote: What is current D time? ... Current Times: D:  ~ 1.5 seconds Chapel: ~ 9 seconds Julia:  ~ 35 seconds Oh, I'm impressed. I thought that D time has been decreased by 1.5 seconds but it is

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 16:57, Steven Schveighoffer пишет: ``` foreach(i; 0..n) // instead of for(long i = 0; i < n;) ``` I guess that `proc` delegate cant capture `i` var of `foreach` loop so the range violation doesn't happen. foreach over a range of integers is lowered to an equivalent for loop, so

Re: How to port C++ std::is_reference to D ?

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 12:07, wjoe пишет: Hello, I'm choking on a piece of C++ I have no idea about how to translate to D.   template     typename std::enable_if< std::is_const::value == true, void>::type* = nullptr>     constexpr const char *modifier() const {     return "[in] ";     }  

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 11:18, data pulverizer пишет: CPU usage now revs up almost has time to touch 100% before the process is finished! Interestingly using `--boundscheck=off` without `--ffast-math` gives a timing of around 4 seconds and, whereas using `--ffast-math` without `--boundscheck=off` made no

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 10:42, data pulverizer пишет: On Wednesday, 6 May 2020 at 07:27:19 UTC, data pulverizer wrote: On Wednesday, 6 May 2020 at 06:54:07 UTC, drug wrote: Thing are really interesting. So there is a space to improve performance in 2.5 times :-) Yes, `array` is smart enough and if you call

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 09:43, data pulverizer пишет: On Wednesday, 6 May 2020 at 05:50:23 UTC, drug wrote: General advice - try to avoid using `array` and `new` in hot code. Memory allocating is slow in general, except if you use carefully crafted custom memory allocators. And that can easily be the

Re: Error running concurrent process and storing results in array

2020-05-06 Thread drug via Digitalmars-d-learn
06.05.2020 09:24, data pulverizer пишет: On Wednesday, 6 May 2020 at 05:44:47 UTC, drug wrote: proc is already a delegate, so is a pointer to the delegate, just pass a `proc` itself Thanks done that but getting a range violation on z which was not there before. ```

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 07:52, data pulverizer пишет: On Wednesday, 6 May 2020 at 04:04:14 UTC, Mathias LANG wrote: On Wednesday, 6 May 2020 at 03:41:11 UTC, data pulverizer wrote: Yes, that's exactly what I want the actual computation I'm running is much more expensive and much larger. It shouldn't matter

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 07:25, data pulverizer пишет: On Wednesday, 6 May 2020 at 03:56:04 UTC, Ali Çehreli wrote: On 5/5/20 8:41 PM, data pulverizer wrote:> On Wednesday, 6 May 2020 at 03:33:12 UTC, Mathias LANG wrote: >> On Wednesday, 6 May 2020 at 03:25:41 UTC, data pulverizer wrote: > Is there

Re: Error running concurrent process and storing results in array

2020-05-05 Thread drug via Digitalmars-d-learn
06.05.2020 06:25, data pulverizer пишет: ``` onlineapp.d(14): Error: template std.concurrency.spawn cannot deduce function from argument types !()(void delegate(double x, double y, long i, shared(double[]) z) pure nothrow @nogc @safe, double, double, long, shared(double[])), candidates are:

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 18:04, notna пишет: hmmm, whích results in:  Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 15:29, Steven Schveighoffer пишет: Don't do this, use to!(dchar[]) as you have above. This will create incorrect dchars for non-ascii text. -Steve Argh, as always you're right. Funny that I never did that and sadly that I posted wrong code. Thank you, Steven, for correction of

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 10:38, Chris Katko пишет: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the google results on the

Re: Help, what is the code mean?

2020-04-27 Thread drug via Digitalmars-d-learn
27.04.2020 18:28, data pulverizer пишет: I'm probably not the first person to say this but. Isn't @trusted an odd label to give unsafe functions and open to abuse by unscrupulous programmers? It almost says "nothing to see, this here piece of code is a-ok". Shouldn't it be explicitly labelled

Re: Idiomatic way to write a range that tracks how much it consumes

2020-04-26 Thread drug via Digitalmars-d-learn
27.04.2020 06:38, Jon Degenhardt пишет: Is there a better way to write this? --Jon I don't know a better way, I think you enlist all possible ways - get a value using either `front` or special range member. I prefer the second variant, I don't think it is less consistent with range

Re: GtkD - how to list 0..100K strings

2020-04-26 Thread drug via Digitalmars-d-learn
26.04.2020 11:06, mark пишет: snipped Sorry for offtopic, imho both Qt and Gtk are too complex in case of virtual list/tree view. I think the reason is they are retained mode gui. I gave up to use them for that and develop custom virtual tree view that is easy in use and currently capable

Re: Integration testing, unit-threaded, and threads

2020-04-23 Thread drug via Digitalmars-d-learn
23.04.2020 14:01, Russel Winder пишет: Hi, I need to start a process before the tests run, and terminate it after the tests run. A module with a shared static constructor and shared static destructor sounds like the way of doing this since the constructor is run before main and the destructor

Re: Integration testing, unit-threaded, and threads

2020-04-23 Thread drug via Digitalmars-d-learn
23.04.2020 14:41, drug пишет: terminate it after in `` terminate it after in `shutdown()`

[dmd] Types and ScopeDsymbol

2020-04-01 Thread drug via Digitalmars-d-learn
Is it true that user defined types are resolved to ScopeDsymbol and basic types aren't?

Re: assert expression in release mode

2020-03-23 Thread drug via Digitalmars-d-learn
On 3/23/20 2:14 PM, Steven Schveighoffer wrote: E.g. https://dlang.org/dmd-osx.html#switch-release There are also other switches like -boundscheck and -check. It’s possible you have some library or project that is causing the behavior. -Steve Thank you, Steve. In my case I guess it was

assert expression in release mode

2020-03-23 Thread drug via Digitalmars-d-learn
Before I lived in assurance that asserts are actual only in debug mode and in release mode they are nothing (except `assert(0)`). But today my whole life is going sour because I stumbled upon assert in release mode and of course that assert is failing. This doc

Re: What is the wrong with my C++ interfacing

2020-03-16 Thread drug via Digitalmars-d-learn
On 3/16/20 12:24 PM, Ferhat Kurtulmuş wrote: Ok, here is a solution. I opened my lib (yielded by my auxilary cpp) using 7zip. There are two files containing symbol names, 1.txt and 2.txt. I searched for names of member functions. They were not there because c++ compiler does not compile

Re: What is the wrong with my C++ interfacing

2020-03-16 Thread drug via Digitalmars-d-learn
On 3/16/20 10:11 AM, Ferhat Kurtulmuş wrote: On Sunday, 15 March 2020 at 22:25:27 UTC, Arine wrote: On Sunday, 15 March 2020 at 21:27:32 UTC, Ferhat Kurtulmuş extern(C++, cv){ extern(C++, class) struct Size_(_Tp){     @disable this(); ~this() { }     final _Tp area() const;     final

Re: What is the wrong with my C++ interfacing

2020-03-15 Thread drug via Digitalmars-d-learn
15.03.2020 23:53, Ferhat Kurtulmuş пишет: I doubt it because in https://dlang.org/spec/cpp_interface.html#using_cpp_classes_from_d cpp code: Derived *createInstance(int i) d code: extern (C++){     ...     Derived createInstance(int i); } Ah, really, you use classes on D side.

Re: What is the wrong with my C++ interfacing

2020-03-15 Thread drug via Digitalmars-d-learn
15.03.2020 23:25, Ferhat Kurtulmuş пишет: On Sunday, 15 March 2020 at 20:21:57 UTC, drug wrote: 15.03.2020 22:39, Ferhat Kurtulmuş пишет: What is the D version of `createSizeIntWH`? In C++ it returns a pointer but in D version it returns an instance. extern(C++){     cv.Size_!int

Re: What is the wrong with my C++ interfacing

2020-03-15 Thread drug via Digitalmars-d-learn
15.03.2020 22:39, Ferhat Kurtulmuş пишет: The original C++ class https://github.com/opencv/opencv/blob/master/modules/core/include/opencv2/core/types.hpp#L315: template class Size_ { public:     typedef _Tp value_type;     //! default constructor     Size_();     Size_(_Tp _width, _Tp

  1   2   3   4   >