Re: Unittests pass, and then an invalid memory operation happens after?

2024-04-06 Thread Lance Bachmeier via Digitalmars-d-learn
On Wednesday, 3 April 2024 at 21:57:00 UTC, Liam McGillivray wrote: Alright. I suppose that some of the optimization decisions I have made so far may have resulted in less readable code for little performance benefit. Now I'm trying to worry less about optimization. Everything has been very

Re: Unittests pass, and then an invalid memory operation happens after?

2024-04-06 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Apr 03, 2024 at 09:57:00PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Friday, 29 March 2024 at 01:18:22 UTC, H. S. Teoh wrote: > > Take a look at the docs for core.memory.GC. There *is* a method > > GC.free that you can use to manually deallocate GC-a

Re: Using core/sys/posix/mqueue.d on FreeBSD

2024-04-06 Thread Arjan via Digitalmars-d-learn
On Saturday, 6 April 2024 at 12:05:56 UTC, Jonathan M Davis wrote: Actually, since I'm usually the one who does the FreeBSD ones anyway, here you go: https://github.com/dlang/dmd/pull/16359 The declarations compile, and they should match the ones in C, since I copied them over and then

Re: Using core/sys/posix/mqueue.d on FreeBSD

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
Actually, since I'm usually the one who does the FreeBSD ones anyway, here you go: https://github.com/dlang/dmd/pull/16359 The declarations compile, and they should match the ones in C, since I copied them over and then tweaked them, but I haven't actually tested them. All that being said, even

Re: Using core/sys/posix/mqueue.d on FreeBSD

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, April 6, 2024 3:57:46 AM MDT Arjan via Digitalmars-d-learn wrote: > I'm using posix mqueue in a D application on Linux. Works fine. > But on FreeBSD it fails to compile due to the version statement: > > [version (CRuntime_Glibc):]( > https://github.com

Re: Inconsistent chain (implicitly converts to int)

2024-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Saturday, 6 April 2024 at 09:21:34 UTC, rkompass wrote: I checked: ```d import std.stdio, std.range, std.algorithm; struct N(T) { T last, step, first; bool empty() => first >= last; T front() => first; auto popFront() => first += step; } void main() { auto r1 =

Re: Inconsistent chain (implicitly converts to int)

2024-04-06 Thread rkompass via Digitalmars-d-learn
On Friday, 5 April 2024 at 21:26:10 UTC, Salih Dincer wrote: On Friday, 5 April 2024 at 21:16:42 UTC, rkompass wrote: In the first example the int's are converted to doubles (also common type). But they appear as int's because writeln does not write a trailing .0. But it doesn't work as

Re: impure

2024-04-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, April 5, 2024 3:11:42 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > On Sunday, 24 March 2024 at 09:16:20 UTC, Jonathan M Davis wrote: > > So, yes, you've run into a problem that it would be nice to > > have a better fix for, but even if we could negate attributes

Re: CTFE write message to console

2024-04-05 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 5 April 2024 at 14:41:12 UTC, Carl Sturtivant wrote: On Friday, 5 April 2024 at 07:37:20 UTC, Paolo Invernizzi wrote: pragma(msg, x) ? No. `__ctfeWrite(x)` is executed inside an executing function like any other statement in it, and can have an argument `x` computed during that

Re: Inconsistent chain (implicitly converts to int)

2024-04-05 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 5 April 2024 at 21:16:42 UTC, rkompass wrote: In the first example the int's are converted to doubles (also common type). But they appear as int's because writeln does not write a trailing .0. But it doesn't work as you say! I even tried it on an older version and got the same

Re: Inconsistent chain (implicitly converts to int)

2024-04-05 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 5 April 2024 at 16:05:20 UTC, H. S. Teoh wrote: On Fri, Apr 05, 2024 at 03:18:09PM +, Salih Dincer via Digitalmars-d-learn wrote: Hi everyone, Technically r1 and r2 are different types of range. Isn't it inconsistent to chain both? If not, why is the char type converted to int

Re: Inconsistent chain (implicitly converts to int)

2024-04-05 Thread rkompass via Digitalmars-d-learn
On Friday, 5 April 2024 at 16:05:20 UTC, H. S. Teoh wrote: On Fri, Apr 05, 2024 at 03:18:09PM +, Salih Dincer via Digitalmars-d-learn wrote: Hi everyone, Technically r1 and r2 are different types of range. Isn't it inconsistent to chain both? If not, why is the char type converted to int

Re: Inconsistent chain (implicitly converts to int)

2024-04-05 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 05, 2024 at 03:18:09PM +, Salih Dincer via Digitalmars-d-learn wrote: > Hi everyone, > > Technically r1 and r2 are different types of range. Isn't it > inconsistent to chain both? If not, why is the char type converted to > int? [...] It's not inconsistent

Inconsistent chain (implicitly converts to int)

2024-04-05 Thread Salih Dincer via Digitalmars-d-learn
Hi everyone, Technically r1 and r2 are different types of range. Isn't it inconsistent to chain both? If not, why is the char type converted to int? ```d import std.stdio, std.range; void main() { auto r1 = N!size_t(10, 1, 1); auto r2 = N!real(15, .5, 10);

Re: CTFE write message to console

2024-04-05 Thread Carl Sturtivant via Digitalmars-d-learn
On Friday, 5 April 2024 at 07:37:20 UTC, Paolo Invernizzi wrote: pragma(msg, x) ? No. `__ctfeWrite(x)` is executed inside an executing function like any other statement in it, and can have an argument `x` computed during that execution. It is defined to output the computed text `x` to

Re: How to resolve two packages requiring different versions of another package?

2024-04-05 Thread IchorDev via Digitalmars-d-learn
On Thursday, 4 April 2024 at 14:29:56 UTC, WhatMeWorry wrote: Error: Unresolvable dependencies to package bindbc-loader: bindbc-opengl 0.13.0 depends on bindbc-loader ~>0.3.0 bindbc-sdl 1.4.7 depends on bindbc-loader ~>1.1.0 Please update `bindbc-opengl` to `1.1.0`. I think it's

Re: impure

2024-04-05 Thread Dom DiSc via Digitalmars-d-learn
On Sunday, 24 March 2024 at 09:16:20 UTC, Jonathan M Davis wrote: So, yes, you've run into a problem that it would be nice to have a better fix for, but even if we could negate attributes in general, there are good reasons to prefer to avoid mass-applying attributes. I don't see it as

Re: CTFE write message to console

2024-04-05 Thread Paolo Invernizzi via Digitalmars-d-learn
On Thursday, 4 April 2024 at 15:43:55 UTC, Carl Sturtivant wrote: On Thursday, 4 April 2024 at 15:07:21 UTC, Richard (Rikki) Andrew Cattermole wrote: Ah yes, I forgot about that particular thing, doesn't see much use as far as I'm aware. It should be working though. ```D enum X =

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 4 April 2024 at 21:23:00 UTC, user1234 wrote: On Thursday, 4 April 2024 at 19:56:50 UTC, Ferhat Kurtulmuş wrote: [...] ```d module runnable; import std.stdio : writeln; import std.range : chain; void main() @nogc { auto s = chain("as ", "df ", "j"); // s is lazy

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 4 April 2024 at 19:56:50 UTC, Ferhat Kurtulmuş wrote: My favorite d feature is lazy ranges. No allocation here. ```d auto s = chain("as ", "df ", "j"); // s is lazy writeln(s); ``` ```d import std.range : chain; void main() { string word = "hello"; auto noError = chain(word,

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread user1234 via Digitalmars-d-learn
On Thursday, 4 April 2024 at 19:56:50 UTC, Ferhat Kurtulmuş wrote: On Thursday, 4 April 2024 at 18:14:54 UTC, BoQsc wrote: I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Thursday, 4 April 2024 at 18:14:54 UTC, BoQsc wrote: I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm not here to discuss that. I'm looking for a function inside standard

Re: How to add a character literal to a string without ~ operator?

2024-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 4 April 2024 at 18:14:54 UTC, BoQsc wrote: I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm not here to discuss that. I'm looking for a function inside standard

How to add a character literal to a string without ~ operator?

2024-04-04 Thread BoQsc via Digitalmars-d-learn
I'm looking for more readable standard function to add a **character** literal to a **string**. The `~` operator is clearly not great while reading a source code. I'm not here to discuss that. I'm looking for a function inside standard library. The function should be straightforward, up to

Re: CTFE write message to console

2024-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 4 April 2024 at 15:47:53 UTC, Richard (Rikki) Andrew Cattermole wrote: Oh hey! https://github.com/dlang/dmd/pull/16250 It was implemented literally 2 weeks ago! Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly Good news, thanks... SDB@79

Re: CTFE write message to console

2024-04-04 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 4 April 2024 at 15:47:53 UTC, Richard (Rikki) Andrew Cattermole wrote: Oh hey! https://github.com/dlang/dmd/pull/16250 It was implemented literally 2 weeks ago! Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly Wow! Happy that's in. It was a bit

Re: CTFE write message to console

2024-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Oh hey! https://github.com/dlang/dmd/pull/16250 It was implemented literally 2 weeks ago! Nightly should have it https://github.com/dlang/dmd/releases/tag/nightly

Re: CTFE write message to console

2024-04-04 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 4 April 2024 at 15:07:21 UTC, Richard (Rikki) Andrew Cattermole wrote: Ah yes, I forgot about that particular thing, doesn't see much use as far as I'm aware. It should be working though. ```D enum X = computeX("A message"); string computeX(string msg) { auto s = "CTFE

Re: CTFE write message to console

2024-04-04 Thread Carl Sturtivant via Digitalmars-d-learn
On Thursday, 4 April 2024 at 14:06:19 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d static assert(0, "message"); ``` Or if it is known to be CTFE'd ```d assert(0, "message"); ``` Just a warning, its a one time use only for both. No other way to do it. That's ... unfortunate. Some

Re: CTFE write message to console

2024-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 05/04/2024 4:04 AM, Carl Sturtivant wrote: On Thursday, 4 April 2024 at 14:06:19 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d static assert(0, "message"); ``` Or if it is known to be CTFE'd ```d assert(0, "message"); ``` Just a warning, its a one time use only for both. No other

Re: How to resolve two packages requiring different versions of another package?

2024-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 05/04/2024 3:29 AM, WhatMeWorry wrote:   Error: Unresolvable dependencies to package bindbc-loader:   bindbc-opengl 0.13.0 depends on bindbc-loader ~>0.3.0   bindbc-sdl 1.4.7 depends on bindbc-loader ~>1.1.0 https://github.com/BindBC/bindbc-opengl/issues/47

Re: CTFE write message to console

2024-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 05/04/2024 2:54 AM, Carl Sturtivant wrote: I'm writing CTFE on Windows, latest DMD compiler. How should I write a message to the console (stderr) from a CTFE function call during compilation? ```d static assert(0, "message"); ``` Or if it is known to be CTFE'd ```d assert(0, "message");

How to resolve two packages requiring different versions of another package?

2024-04-04 Thread WhatMeWorry via Digitalmars-d-learn
Error: Unresolvable dependencies to package bindbc-loader: bindbc-opengl 0.13.0 depends on bindbc-loader ~>0.3.0 bindbc-sdl 1.4.7 depends on bindbc-loader ~>1.1.0

Re: How best to implement items and weapons in my RPG. Nested classes? Delegates?

2024-04-04 Thread Olivier Pisano via Digitalmars-d-learn
Hi, You should have a look at the decorator design pattern, it reduces the amount of classes to implement if you need to combine different effects such as elemental damage to your weapons (e.g. if you want flame arrows). https://en.wikipedia.org/wiki/Decorator_pattern

How best to implement items and weapons in my RPG. Nested classes? Delegates?

2024-04-03 Thread Liam McGillivray via Digitalmars-d-learn
For my tactical role-playing game, I want to finally implement items and weapons. These are objects that a `Unit` object can make use of. Just as tools are often said to be an extension of their user, I want items to be an extension of the unit who uses them. I'm trying to figure out how to

Re: How can I get an identifiquer of an usb or a harddisk? using C or Cpp or Dlang

2024-04-03 Thread dany via Digitalmars-d-learn
On Wednesday, 3 April 2024 at 00:20:51 UTC, Jonathan M Davis wrote: On Monday, April 1, 2024 5:37:56 PM MDT dany via Digitalmars-d-learn wrote: Actually I would get an ID's Usb That's going to depend on the operating system, and it's also going to depend on exactly what kind of ID you're

Re: Unittests pass, and then an invalid memory operation happens after?

2024-04-03 Thread Liam McGillivray via Digitalmars-d-learn
On Friday, 29 March 2024 at 01:18:22 UTC, H. S. Teoh wrote: Take a look at the docs for core.memory.GC. There *is* a method GC.free that you can use to manually deallocate GC-allocated memory if you so wish. Keep in mind, though, that manually managing memory in this way invites

Re: How can I get an identifiquer of an usb or a harddisk? using C or Cpp or Dlang

2024-04-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, April 1, 2024 5:37:56 PM MDT dany via Digitalmars-d-learn wrote: > Actually I would get an ID's Usb That's going to depend on the operating system, and it's also going to depend on exactly what kind of ID you're looking for. - Jonathan M Davis

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2024 at 18:21:58 UTC, Mike Shah wrote: An easier fix may be perhaps to just use 'dub' and install the glfw dependency. In my talk, I did everything from scratch (my preferred way), though I suspect using dub with glfw-d (https://code.dlang.org/packages/glfw-d) may provide

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Mike Shah via Digitalmars-d-learn
On Monday, 1 April 2024 at 21:23:50 UTC, WhatMeWorry wrote: Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 1 April 2024 at 21:23:50 UTC, WhatMeWorry wrote: Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop

Re: std.traits.ParameterIdentifierTuple problem

2024-04-02 Thread Carl Sturtivant via Digitalmars-d-learn
On Monday, 1 April 2024 at 18:28:16 UTC, Nick Treleaven wrote: On Sunday, 31 March 2024 at 23:05:44 UTC, Carl Sturtivant wrote: Yes, it's not possible to instantiate a function type. But with extern it seems the semantics is fine as a function is not being instantiated. It is merely

Boneheaded question regarding compilation...

2024-04-01 Thread WhatMeWorry via Digitalmars-d-learn
Huge fan of Mike Shah's YouTube videos regarding D and his latest for D conference: https://mshah.io/conf/24/DConf%20%20Online%202024%20_%20The%20Case%20for%20Graphics%20Programming%20in%20Dlang.pdf So I installed github desktop app and cloned his Talks repo. There is a build command

Re: std.traits.ParameterIdentifierTuple problem

2024-04-01 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 31 March 2024 at 23:05:44 UTC, Carl Sturtivant wrote: Yes, it's not possible to instantiate a function type. But with extern it seems the semantics is fine as a function is not being instantiated. It is merely associating a name with a type: in what sense is this instantiation in

Re: Dub generated a visuald project for me that includes pegged + dqt (Qt widgets). Basic linking error fix?

2024-03-31 Thread Daniel via Digitalmars-d-learn
I see now. https://github.com/tim-dlang/dqt has examples of where these libs are found within Qt itself.

Dub generated a visuald project for me that includes pegged + dqt (Qt widgets). Basic linking error fix?

2024-03-31 Thread Daniel via Digitalmars-d-learn
``` Build started at 7:16 PM... -- Build started: Project: d--, Configuration: debug x64 -- Building C:\Users\fruit\OneDrive\Desktop\Code\StateMachine\D--\d--.exe... LINK : fatal error LNK1181: cannot open input file 'Qt5Widgets.lib' Building

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Monday, 1 April 2024 at 04:54:46 UTC, cc wrote: I scoured [Traits](https://dlang.org/spec/traits.html) and [std.traits](https://dlang.org/phobos/std_traits.html) looking for a simple method to tell whether a member was declared as enum but couldn't find one, so if anyone knows a proper way

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-31 Thread cc via Digitalmars-d-learn
On Thursday, 28 March 2024 at 17:23:39 UTC, Andy Valencia wrote: I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: That's pretty much the best way to do it. While `.tupleof` does look kind of hacky, and you could instead

Re: Best way to use large C library in D as of 2024

2024-03-31 Thread Lance Bachmeier via Digitalmars-d-learn
On Saturday, 30 March 2024 at 05:01:32 UTC, harakim wrote: On Tuesday, 26 March 2024 at 20:42:00 UTC, Chris Piker wrote: On Tuesday, 26 March 2024 at 20:19:27 UTC, bachmeier wrote: Should be able to just use it, as described here:

Re: std.traits.ParameterIdentifierTuple problem

2024-03-31 Thread Carl Sturtivant via Digitalmars-d-learn
On Sunday, 31 March 2024 at 11:35:39 UTC, Nick Treleaven wrote: If a function type does include identifiers, then would two function types with the same argument types but different identifiers compare equal using `is`? Yes. That is the idea. Define `is` to work this way. Yes, it's not

Re: Limits of implicit conversion of class arrays

2024-03-31 Thread Per Nordlöw via Digitalmars-d-learn
On Thursday, 28 March 2024 at 01:53:52 UTC, Steven Schveighoffer wrote: ```d class Base {} class Derived : Base {} @safe pure nothrow unittest { Base b; Derived d; b = d; // pass Base[] bs; Derived[] ds; bs ~= ds; // pass bs = ds; // fail

Re: LDC Internal Compiler Error (ICE) mentioning attribute 'nocapture'

2024-03-31 Thread Basile B. via Digitalmars-d-learn
On Saturday, 30 March 2024 at 09:35:24 UTC, Per Nordlöw wrote: Does anybody recognize the error ``` Attribute 'nocapture' does not apply to function return values %12 = call noalias nocapture align 8 ptr @_D3xxx(ptr nonnull %10, { i64, ptr } %11) #2, !dbg !7978 Attribute 'nocapture' does

Re: std.traits.ParameterIdentifierTuple problem

2024-03-31 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 30 March 2024 at 22:37:53 UTC, Carl Sturtivant wrote: I'm inclined to a view that keeps more "it just works" options open. Regard the parameter names as a part of the type (which I am very grateful for them being currently) and just regard part of the definition of "type equality"

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Carl Sturtivant via Digitalmars-d-learn
On Saturday, 30 March 2024 at 22:37:53 UTC, Carl Sturtivant wrote: Incidentally, I tried ```D extern typeof(foo) func; ``` to say that func was an actual function (`extern` so defined elsewhere) whose type was the type of the function `int foo(int num, string name, int);` so I can then use

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Carl Sturtivant via Digitalmars-d-learn
On Saturday, 30 March 2024 at 21:07:35 UTC, Nick Treleaven wrote: Although `.stringof` on a function type does include the parameter names, the names are not really part of the type - see: https://github.com/dlang/phobos/pull/3620#issuecomment-288469685 Perhaps `ParameterIdentifierTuple`

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Carl Sturtivant via Digitalmars-d-learn
On Saturday, 30 March 2024 at 21:51:34 UTC, Nick Treleaven wrote: On Saturday, 30 March 2024 at 21:45:34 UTC, Nick Treleaven wrote: On Saturday, 30 March 2024 at 21:25:45 UTC, Carl Sturtivant wrote: OK, so how can I get them? Am I forced to take that string and parse it with CTFE? Lookup the

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 30 March 2024 at 21:45:34 UTC, Nick Treleaven wrote: On Saturday, 30 March 2024 at 21:25:45 UTC, Carl Sturtivant wrote: OK, so how can I get them? Am I forced to take that string and parse it with CTFE? Lookup the source of ParameterIdentifierTuple and change

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 30 March 2024 at 21:25:45 UTC, Carl Sturtivant wrote: OK, so how can I get them? Am I forced to take that string and parse it with CTFE? Lookup the source of ParameterIdentifierTuple and change `FunctionTypeOf!func` to just `func` inside the first `static if`.

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Carl Sturtivant via Digitalmars-d-learn
On Saturday, 30 March 2024 at 21:07:35 UTC, Nick Treleaven wrote: On Saturday, 30 March 2024 at 19:23:07 UTC, Carl Sturtivant wrote: $ dmd -c bug1.d int(int num, string name, int) ["", "", ""] bug1.d(9): Error: static assert: "wrong!" ``` Please explain. How do I get the names of the

Re: std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 30 March 2024 at 19:23:07 UTC, Carl Sturtivant wrote: $ dmd -c bug1.d int(int num, string name, int) ["", "", ""] bug1.d(9): Error: static assert: "wrong!" ``` Please explain. How do I get the names of the identifiers out of a parameter list at compile time reliably? Although

std.traits.ParameterIdentifierTuple problem

2024-03-30 Thread Carl Sturtivant via Digitalmars-d-learn
Using the [ParameterIdentifierTuple](https://dlang.org/phobos/std_traits.html#ParameterIdentifierTuple) example just there, with one more step stops working. Details: ```D import std.traits; int foo(int num, string name, int); static assert([ParameterIdentifierTuple!foo] == ["num", "name",

LDC Internal Compiler Error (ICE) mentioning attribute 'nocapture'

2024-03-30 Thread Per Nordlöw via Digitalmars-d-learn
Does anybody recognize the error ``` Attribute 'nocapture' does not apply to function return values %12 = call noalias nocapture align 8 ptr @_D3xxx(ptr nonnull %10, { i64, ptr } %11) #2, !dbg !7978 Attribute 'nocapture' does not apply to function return values ptr @_D3xyz1 Attribute

Re: Best way to use large C library in D as of 2024

2024-03-30 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 30 March 2024 at 05:01:32 UTC, harakim wrote: @D Language Foundation - This is a HUGE selling point. I had to use cups the other day and I just copied some code from a d file and linked the library. It was so easy I was suspicious but it worked. Using C from D is pretty much as

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-30 Thread zjh via Digitalmars-d-learn
On Saturday, 30 March 2024 at 03:25:02 UTC, matheus wrote: Interesting! Matheus. Yes, it's just a small modification.

Re: Best way to use large C library in D as of 2024

2024-03-29 Thread harakim via Digitalmars-d-learn
On Tuesday, 26 March 2024 at 20:42:00 UTC, Chris Piker wrote: On Tuesday, 26 March 2024 at 20:19:27 UTC, bachmeier wrote: Should be able to just use it, as described here: https://forum.dlang.org/post/qxctappnigkwvaqak...@forum.dlang.org Create a .c file that includes the header files and

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread matheus via Digitalmars-d-learn
On Saturday, 30 March 2024 at 02:11:25 UTC, zjh wrote: On Friday, 29 March 2024 at 22:50:53 UTC, curiousprogramma08 wrote: you can use openD. Wait a minute, they already added this modification into their language? Interesting! Matheus.

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread zjh via Digitalmars-d-learn
On Friday, 29 March 2024 at 22:50:53 UTC, curiousprogramma08 wrote: you can use openD.

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread matheus via Digitalmars-d-learn
On Friday, 29 March 2024 at 22:50:53 UTC, curiousprogramma08 wrote: ... If I'm not mistaken, like in classes "private" is module based: https://wiki.dlang.org/Access_specifiers_and_visibility Matheus.

Re: How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, March 29, 2024 4:50:53 PM MDT curiousprogramma08 via Digitalmars-d- learn wrote: > ```d > struct QueueNode > { > > private int data; > private QueueNode *next = null; > > this(int data) > { > this.data = data; > }

How to make fields inaccessible (unreadable and unachangeable) outside of the structure?

2024-03-29 Thread curiousprogramma08 via Digitalmars-d-learn
```d struct QueueNode { private int data; private QueueNode *next = null; this(int data) { this.data = data; } } ``` I also tried to write it like this too: ```d struct QueueNode { private: int data; QueueNode *next = null; public: this(int

Re: Setting up a final switch from a list

2024-03-29 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 March 2024 at 00:37:21 UTC, Jonathan M Davis wrote: On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote: How can we add all members of an enum type to a list without duplicating code? As the documentation for EnumMembers explains, you can use

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 11:49:19PM +, Liam McGillivray via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote: > > The whole point of a GC is that you leave everything up to it to > > clean up. If you want to manage your own memory, d

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Friday, 29 March 2024 at 00:04:14 UTC, Serg Gini wrote: On Thursday, 28 March 2024 at 23:15:26 UTC, Salih Dincer wrote: There is no such thing as parallel programming in D anyway. At least it has modules, but I didn't see it being works. Whenever I use toys built in foreach() it always ends

Re: Setting up a final switch from a list

2024-03-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, March 28, 2024 4:21:03 PM MDT Salih Dincer via Digitalmars-d- learn wrote: > How can we add all members of an enum type to a list without > duplicating code? As the documentation for EnumMembers explains, you can use std.meta.NoDuplicates to strip out duplicates if you want

Re: Why is this code slow?

2024-03-28 Thread Serg Gini via Digitalmars-d-learn
On Thursday, 28 March 2024 at 23:15:26 UTC, Salih Dincer wrote: There is no such thing as parallel programming in D anyway. At least it has modules, but I didn't see it being works. Whenever I use toys built in foreach() it always ends in disappointment I think it just works :) Which issues

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-28 Thread Liam McGillivray via Digitalmars-d-learn
On Thursday, 28 March 2024 at 04:46:27 UTC, H. S. Teoh wrote: The whole point of a GC is that you leave everything up to it to clean up. If you want to manage your own memory, don't use the GC. D does not force you to use it; you can import core.stdc.stdlib and use malloc/free to your heart's

Re: Two chunks but No allocation

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 23:08:54 UTC, rkompass wrote: You can drop and take from the folded values range. I got `[1, 0.67, 0.625, 0.619048, 0.618182, 0.618056, 0.618037, 0.618034, 0.618034, 0.618034]` from the above code. Thank you so much... I solved the problem: r.back doesn't

Re: range.chunks(2) error

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 17:50:17 UTC, Salih Dincer wrote: Hi, When I use the chunks() template with iota(), for instance, with chunks(2), I can access both r.front and r.back. However, in a range of my own type (named iras in the code below), only r.front is working. I think the error

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 20:18:10 UTC, rkompass wrote: I didn't know that OpenMP programming could be that easy. Binary size is 16K, same order of magnitude, although somewhat less. D advantage is gone here, I would say. There is no such thing as parallel programming in D anyway. At

Re: Two chunks but No allocation

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 03:54:05 UTC, Salih Dincer wrote: On Wednesday, 27 March 2024 at 20:50:05 UTC, rkompass wrote: This works: I decided to give the full code. Maybe then it will be better understood what I mean. I actually pointed out the indirect solution above but it's a bit

Re: Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 10:10:43PM +, jms via Digitalmars-d-learn wrote: > On Thursday, 28 March 2024 at 02:30:11 UTC, jms wrote: [...] > I think I figured it out and the difference is probably in the mode. > This documentation > https://learn.microsoft.com/en-us/cpp/c-run

Re: Setting up a final switch from a list

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 10 August 2023 at 08:33:13 UTC, Christian Köstlin wrote: I think one part of the original question (now fanished in the nntp backup) was how to get all enum members into a list without duplicating code. ```d import std.traits : EnumMembers; import std.stdio : writeln; import

Re: Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-28 Thread jms via Digitalmars-d-learn
On Thursday, 28 March 2024 at 02:30:11 UTC, jms wrote: Why in the below silly program am I reading both the \r and \n characters when using rawRead in block a, but when looping by 1 byte chunks in block b only appear to be reading the \n characters? I'm on Windows 11 using DMD64 D Compiler

Re: Why is this code slow?

2024-03-28 Thread Sergey via Digitalmars-d-learn
On Thursday, 28 March 2024 at 20:18:10 UTC, rkompass wrote: D advantage is gone here, I would say. It's hard to compare actually. Std.parallelism has a bit different mechanics, and I think easier to use. The syntax is nicer. OpenMP is an well-known and highly adopted tool, which is also

Re: Why is this code slow?

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 14:07:43 UTC, Salih Dincer wrote: On Thursday, 28 March 2024 at 11:50:38 UTC, rkompass wrote: Turning back to this: Are there similarly simple libraries for C, that allow for parallel computation? You can achieve parallelism in C using libraries such as

range.chunks(2) error

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
Hi, When I use the chunks() template with iota(), for instance, with chunks(2), I can access both r.front and r.back. However, in a range of my own type (named iras in the code below), only r.front is working. I think the error given by r.back is not a bug related to chunks, is it? ```d

Re: Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 05:23:39PM +, Andy Valencia via Digitalmars-d-learn wrote: [...] > auto t = T(); > foreach (i, ref val; t.tupleof) { > static if (is(typeof(val) == int)) { > val = this.get_int(); > } else { >

Opinions on iterating a struct to absorb the decoding of a CSV?

2024-03-28 Thread Andy Valencia via Digitalmars-d-learn
I wanted a lightweight and simpler CSV decoder. I won't post the whole thing, but basically you instantiate one as: struct Whatever { ... } ... f = File("path.csv", "r"); auto c = CSVreader!Whatever(f); foreach (rec; c) { ... CSVreader is, of course, templated: struct

Re: Why is this code slow?

2024-03-28 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 28 March 2024 at 11:50:38 UTC, rkompass wrote: Turning back to this: Are there similarly simple libraries for C, that allow for parallel computation? You can achieve parallelism in C using libraries such as OpenMP, which provides a set of compiler directives and runtime

Re: Why is this code slow?

2024-03-28 Thread rkompass via Digitalmars-d-learn
On Thursday, 28 March 2024 at 01:09:34 UTC, Salih Dincer wrote: Good thing you're digressing; I am 45 years old and I still cannot say that I am finished as a student! For me this is version 4 and it looks like we don't need a 3rd variable other than the function parameter and return value:

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Mar 28, 2024 at 03:56:10AM +, Liam McGillivray via Digitalmars-d-learn wrote: [...] > I may be now starting to see why the use of a garbage collector is > such a point of contention for D. Not being able to predict how the > garbage collection process will happen seems lik

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread Liam McGillivray via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 22:14:16 UTC, H. S. Teoh wrote: What's the definition of this.map, this.faction, and this.currentTile? As was said, and can be found on the linked repository, they are references to class objects. On Thursday, 28 March 2024 at 01:47:27 UTC, Steven

Re: Two chunks but No allocation

2024-03-27 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 20:50:05 UTC, rkompass wrote: This works: I decided to give the full code. Maybe then it will be better understood what I mean. I actually pointed out the indirect solution above but it's a bit ugly and I'm sure there must be a better way? ```d import

Difference between chunks(stdin, 1) and stdin.rawRead?

2024-03-27 Thread jms via Digitalmars-d-learn
Why in the below silly program am I reading both the \r and \n characters when using rawRead in block a, but when looping by 1 byte chunks in block b only appear to be reading the \n characters? I'm on Windows 11 using DMD64 D Compiler v2.107.1 if that matters, but I'm thinking this maybe

Re: Limits of implicit conversion of class arrays

2024-03-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Monday, 25 March 2024 at 07:16:35 UTC, Per Nordlöw wrote: On Saturday, 23 March 2024 at 11:04:04 UTC, Dmitry Olshansky wrote: The first and second is unsound (infamously allowed in Java). In the general case, yes. But, do you see any errors with the code ```d class Base {} class Derived

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 21:43:48 UTC, Liam McGillivray wrote: In my current [game project](https://github.com/LiamM32/Open_Emblem), [something strange](https://github.com/LiamM32/Open_Emblem/issues/20) has happened as of a recent commit. When running `dub test`, all the unittests

Re: Why is this code slow?

2024-03-27 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 08:22:42 UTC, rkompass wrote: I apologize for digressing a little bit further - just to share insights to other learners. Good thing you're digressing; I am 45 years old and I still cannot say that I am finished as a student! For me this is version 4 and it

Re: Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 27, 2024 at 09:43:48PM +, Liam McGillivray via Digitalmars-d-learn wrote: [...] > ``` > ~this() { > this.alive = false; > if (this.map !is null) this.map.removeUnit(this); > if (this.faction !is null) this.fac

Unittests pass, and then an invalid memory operation happens after?

2024-03-27 Thread Liam McGillivray via Digitalmars-d-learn
In my current [game project](https://github.com/LiamM32/Open_Emblem), [something strange](https://github.com/LiamM32/Open_Emblem/issues/20) has happened as of a recent commit. When running `dub test`, all the unittests appear to pass, but then after the last unittest has concluded an "Invalid

Re: Two chunks but No allocation

2024-03-27 Thread rkompass via Digitalmars-d-learn
On Wednesday, 27 March 2024 at 13:38:29 UTC, Salih Dincer wrote: So, not works this: ```d fib(1, 1).take(48) //.array .chunks(2) .map!"a[1] / a[0]" .back .writeln; // 1.61803 ``` Thanks... SDB@79 This works: ```d import std.stdio; import

<    1   2   3   4   5   6   7   8   9   10   >