Re: How does D lang handle multithreaded applications and static members of classes?

2025-04-03 Thread Inkrementator via Digitalmars-d-learn
On Wednesday, 2 April 2025 at 08:38:32 UTC, Daniel Donnelly, Jr. wrote: On Wednesday, 2 April 2025 at 08:33:05 UTC, Inkrementator wrote: All global variables in D, including static class members, are thread local by default. You have to explicitly add the `__gshared` attribute to the static var

Re: How does D lang handle multithreaded applications and static members of classes?

2025-04-02 Thread Inkrementator via Digitalmars-d-learn
On Tuesday, 1 April 2025 at 23:01:23 UTC, Daniel Donnelly, Jr. wrote: Say I have a static context stack in my class Context, will each new thread receive their own copy of the static member or do I have to account for multiple threads and do it myself? All global variables in D, including stat

Re: What are the pointer aliasing rules in D?

2025-03-07 Thread Inkrementator via Digitalmars-d-learn
On Thursday, 6 March 2025 at 10:46:20 UTC, tmp wrote: Do the same rules exist in D? If they do, do workarounds exist? LDC and GDC offer nonstandard extensions to enable optimizations regarding non-aliasing pointers with the @restrict https://gcc.gnu.org/onlinedocs/gcc-14.2.0/gdc/Common-Attr

Re: How to specity a list of fields with default to a mixin template?

2025-03-02 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 2 March 2025 at 19:31:06 UTC, realhet wrote: Anyone have an idea? While template mixins have access to the caller scope, the default values for parameters apparently don't. If you `inline` the default value, it will work ``` import std.traits; mixin template T(string def) { enum

Re: Names and design of partial sumtypes

2025-03-02 Thread Inkrementator via Digitalmars-d-learn
On Saturday, 15 February 2025 at 19:49:59 UTC, monkyyy wrote: I think full sumtypes are probably usually overkill and I rarely use it; but I have some lib ideas that need... something This PR would probably make sumtypes easier to use in some scenarios: https://github.com/dlang/phobos/pull/106

Re: when should ranges be static

2025-02-16 Thread Inkrementator via Digitalmars-d-learn
On Saturday, 15 February 2025 at 19:21:33 UTC, monkyyy wrote: On Saturday, 15 February 2025 at 11:47:58 UTC, Inkrementator wrote: Would you expect that style change would remove this flavor of bugs? Do you think this is a compiler bug? It looks similar to this: https://github.com/dlang/dmd/issu

Re: Get parent function of nested delegate

2025-02-16 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 16 February 2025 at 07:38:09 UTC, Anonymouse wrote: How can I make this work? As a workaround, you can define a useless symbol and get the parent of that. ``` module foo; void bar(string s, int i) { assert(__FUNCTION__ == "foo.bar"); alias parentModule = __traits(parent, m

Re: when should ranges be static

2025-02-15 Thread Inkrementator via Digitalmars-d-learn
On Saturday, 15 February 2025 at 11:47:58 UTC, Inkrementator wrote: Wrapping foo in another delegate seems to at least compile. Same as splitting out the struct. I don't understand why a struct outside of a function gets treated differently than a static struct. ``` auto split(alias F,R)(R

Re: when should ranges be static

2025-02-15 Thread Inkrementator via Digitalmars-d-learn
On Thursday, 6 February 2025 at 20:08:36 UTC, monkyyy wrote: I have template hell code; eventually 5 nested range calls have dual context-y issues and maybe compiler bugs; adding static makes those errors go away, adding static to everything makes new bugs. Wack-a-mole when the compiler gets

Re: what's the use of empty structs in C-style languages ?

2024-12-02 Thread Inkrementator via Digitalmars-d-learn
On Monday, 2 December 2024 at 17:03:22 UTC, Basile B. wrote: Big question is what is the problem if we specify that empty struct is an error ? It's pretty useful in combination with `std.sumtype`.

Re: Using a tuple as a function parameter

2024-11-22 Thread Inkrementator via Digitalmars-d-learn
On Friday, 22 November 2024 at 16:36:43 UTC, Andrew wrote: Error: variable \`i\` cannot be read at compile time Tuple access seems to be internally coded as a template (with unusual syntax) for the reasons already said. `i` has to be known at compile time for this to work, so a template param

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-16 Thread Inkrementator via Digitalmars-d-learn
On Saturday, 16 March 2024 at 13:09:13 UTC, Adam D Ruppe wrote: On Thursday, 14 March 2024 at 23:19:37 UTC, Inkrementator wrote: @(__traits(getAttributes, thingYouWantToForward)) void yourNewThing() {} Thanks, that should solve my problem. http://dpldocs.info/this-week-in-d/Blog.Posted_2020_01

Re: Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-16 Thread Inkrementator via Digitalmars-d-learn
On Friday, 15 March 2024 at 19:13:38 UTC, cc wrote: This is trivially easy if your types are visible at module level, and mixin is a fine tool for the job. It doesn't work quite so well with [Voldemort types](https://wiki.dlang.org/Voldemort_types). I used the following lines to make it work f

Re: dub: Could not resolve configuration for package demo

2024-03-15 Thread Inkrementator via Digitalmars-d-learn
On Friday, 15 March 2024 at 17:48:26 UTC, mw wrote: ``` $ dub build Could not resolve configuration for package demo ``` Trying to build your dependency msgpack-rpc, it spits out ``` Warning The sub configuration directive "vibe-d" -> [libevent] references a configuration that does not ex

Deriving a struct from another one via template: Easy way to propagate UDAs?

2024-03-14 Thread Inkrementator via Digitalmars-d-learn
Hello, I am trying to derive a struct from another. I want to modify each field such that type of it goes from some T to Nullable!T, preserving all fieldnames and UDAs. I think that fieldnames and UDAs can only be duplicated via string-mixins. This means that all field-types that aren't visi

Re: Recommendation about templating engine library

2024-03-14 Thread Inkrementator via Digitalmars-d-learn
On Monday, 11 March 2024 at 16:10:24 UTC, Andrea wrote: just trying it out and kinda fits my needs; the main issues are lack of documentation and the need to explicit loop on array data structures in the code (using sub-contexts) instead of having a "foreach" loop statement in the template itse

Re: Function Composition

2024-01-29 Thread Inkrementator via Digitalmars-d-learn
On Thursday, 25 January 2024 at 18:44:26 UTC, atzensepp wrote: However this works: ```d int delegate (int) td = (x) => compose!(f,g,g,f,g,g,f,g,g,f)(x); ``` While not a real function pointer, this might already fit your needs. ```d alias td = compose!(f,g); ```

Re: DMD: How to compile executable without producing .obj file?

2023-11-09 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 5 November 2023 at 18:58:48 UTC, BoQsc wrote: When you compile using `dmd` compiler you will often get `.exe` and `.obj` file. I would like to only produce `.exe` file: On linux, gdc automatically cleans up object files by default. Passing it the -pipe option will prevent their cr

Re: Member field of type nested struct must be initialized in constructor: Why?

2023-10-23 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 22 October 2023 at 23:49:40 UTC, Paul Backus wrote: Nested structs contain a context pointer that needs to be initialized at runtime. If you don't initialize them, the pointer gets set to `null`, and the struct will not be able to access its context. I see, thanks for the explanati

Re: Member field of type nested struct must be initialized in constructor: Why?

2023-10-22 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 22 October 2023 at 21:02:32 UTC, Inkrementator wrote: Running the code with `rdmd -version=fix app.d` works, but running `rdmd -version=fix app.d` produces: `Error: field `member` must be initialized in constructor, because it is nested struct` Sorry, obviously it should be: Running

Member field of type nested struct must be initialized in constructor: Why?

2023-10-22 Thread Inkrementator via Digitalmars-d-learn
Consider this almost minimal example: ``` import std.algorithm; import std.range; import std.stdio; struct S(Nested){ Nested member; // = I.init; // Uncommenting this wouldn't help int g; this(Nested member){ this.member = member; }

Re: Proper way to handle "alias this" deprecation for classes

2023-05-10 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 21:12:22 UTC, Chris Piker wrote: On the other hand, your first suggestion of using opCast() does seem like a reasonable choice to me. Can you provide a short code snippet using opCast to achieve the same result? I've never used it, and particularly I know that I don't

Re: Proper way to handle "alias this" deprecation for classes

2023-05-07 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 7 May 2023 at 18:19:04 UTC, Ali Çehreli wrote: alias this is for implicit type conversions, which can be achieved explicitly as well. Open question to everybody: What you're opinion on using opCast for this? Since it's a type conversion, it seems fitting to me. And another suggest

Re: Step by step tutorials for using bindings in D

2023-03-30 Thread Inkrementator via Digitalmars-d-learn
On Monday, 27 March 2023 at 00:45:28 UTC, Salih Dincer wrote: Likes **17** Views **265** Released on March **8, 2023** I'm surprised that you can get 300 views in a month on a primarily D video, but it's nice to see

Re: Step by step tutorials for using bindings in D

2023-03-26 Thread Inkrementator via Digitalmars-d-learn
On Sunday, 26 March 2023 at 18:49:57 UTC, eXodiquas wrote: On Sunday, 26 March 2023 at 14:09:19 UTC, Inkrementator wrote: But you said static bindings are the main portion of bindings we use. So I tried to get static Lua bindings going. Static Binding != Static Linking. Like I said, the termin

Re: Step by step tutorials for using bindings in D

2023-03-26 Thread Inkrementator via Digitalmars-d-learn
On Friday, 24 March 2023 at 23:45:15 UTC, eXodiquas wrote: Hello everyone, once again, I am here for your help. My last questions were answered really competently so I try again. :P So, maybe this is a stupid question, but I have read a lot about Bindings to C and C++ libraries for D. For ex