Re: copy must be const?!?

2024-07-25 Thread Quirin Schroll via Digitalmars-d-learn
On Thursday, 25 July 2024 at 13:07:03 UTC, Jonathan M Davis wrote: On Thursday, July 25, 2024 6:00:58 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > And no, in general, you don't want to be casting away const > or immutable. There are cases where it can work (e.g. if the > cast does a copy,

Re: Array concatenation & optimisation

2024-07-22 Thread Quirin Schroll via Digitalmars-d-learn
On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Obviously when writing optimised code it is desirable to reduce heap allocation frequency. With that in mind, I'm used to being told by the compiler that I can't do this in `@nogc` code: ```d void assign(ref int[4] a) @nogc{ a[] =

Re: How to pass in reference a fixed array in parameter

2024-06-06 Thread Quirin Schroll via Digitalmars-d-learn
On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote: I am currently trying to learn how to program in D. I thought that I could start by trying some maze generation algorithms. I have a maze stored as 2D array of structure defined as follow which keep tracks of wall positions: ~~~

Re: bool passed by ref, safe or not ?

2024-06-06 Thread Quirin Schroll via Digitalmars-d-learn
On Wednesday, 5 June 2024 at 18:31:12 UTC, Basile B. wrote: On Wednesday, 5 June 2024 at 01:18:06 UTC, Paul Backus wrote: On Tuesday, 4 June 2024 at 16:58:50 UTC, Basile B. wrote: ```d void main(string[] args) { ushort a = 0b; bool* b = cast(bool*) setIt(*b);

How to set linkage?

2023-12-20 Thread Quirin Schroll via Digitalmars-d-learn
In the DMD compiler frontend, the type `TypeFunction` (cf. astbase.d) representing a function type has a `linkage` member. Setting this member when parsing seems to have no effect. How do I set the linkage of a function type? For alias declarations which support setting function type

Re: opApply seems like it can infer delegate types AND parameters!?

2023-12-11 Thread Quirin Schroll via Digitalmars-d-learn
On Monday, 11 December 2023 at 23:21:45 UTC, Quirin Schroll wrote: […] 1. Instead of implementing a function `opApply(scope int delegate(...))`, write a function template `opApplyImpl(DG)(scope int delegate(...))` (or whatever name) and let it take the delegate type as a template type

opApply seems like it can infer delegate types AND parameters!?

2023-12-11 Thread Quirin Schroll via Digitalmars-d-learn
In an attempt to come up with an [answer to a post](https://forum.dlang.org/post/dnsuyvnfcszwefsfz...@forum.dlang.org), I found something odd, but useful, that I nonetheless don’t understand. As far as I know – or rather thought I knew – `foreach` loops can infer the types of the “loop

Installing DMD on Windows

2023-10-20 Thread Quirin Schroll via Digitalmars-d-learn
I recently removed Visual Studio 2017 and upgraded to 2022. When I installed the latest DMD, it told me it couldn’t find a Visual Studio installation and offered me to download e.g. Visual Studio 2019 or just VS 2019 Build Tools, etc. Unsure what to do, I thought VS 2019 Build Tools is

Re: How can overloads be distinguished on attributes alone?

2023-08-01 Thread Quirin Schroll via Digitalmars-d-learn
On Monday, 31 July 2023 at 18:15:25 UTC, Jonathan M Davis wrote: On Monday, July 31, 2023 4:55:44 AM MDT Quirin Schroll via Digitalmars-d-learn wrote: Apparently, functions can be overloaded solely distinguished by attributes: ```d void f(ref int x) pure { x = 1; } void f(ref int x) { x

How can overloads be distinguished on attributes alone?

2023-07-31 Thread Quirin Schroll via Digitalmars-d-learn
Apparently, functions can be overloaded solely distinguished by attributes: ```d void f(ref int x) pure { x = 1; } void f(ref int x) { x = 2; static int s; ++s; } ``` I thought that, maybe, a `pure` context calls the `pure` function and an impure context calls the impure function, but no:

Re: How to deal with interdependent dlang PRs?

2023-05-26 Thread Quirin Schroll via Digitalmars-d-learn
On Thursday, 25 May 2023 at 20:18:08 UTC, Dennis wrote: On Thursday, 25 May 2023 at 15:37:00 UTC, Quirin Schroll wrote: Is there a process? I can’t be the first one running into this. Doing it in 3 PRs is the process. Okay. It’s not that bad. This is one of the reasons why druntime was

How to deal with interdependent dlang PRs?

2023-05-25 Thread Quirin Schroll via Digitalmars-d-learn
I have 2 PRs, [one on dlang/dlang.org](https://github.com/dlang/dlang.org/pull/3446) and [one on dlang/dmd](https://github.com/dlang/dmd/pull/15245). The latter fails a test because an example on the (current) dlang.org fails. The dlang.org PR changes the example, and fails likewise it’s

Re: How to use Dub and Digger to build Pull Requests?

2023-05-24 Thread Quirin Schroll via Digitalmars-d-learn
On Tuesday, 23 May 2023 at 13:52:15 UTC, Vladimir Panteleev wrote: On Tuesday, 23 May 2023 at 13:50:09 UTC, Quirin Schroll wrote: ``` object.Exception@%LOCALAPPDATA%\dub\packages\ae-0.0.3236\ae\sys\d\manager.d(898): Command ["make", "-f", "win32.mak", "MODEL=32",

How to use Dub and Digger to build Pull Requests?

2023-05-23 Thread Quirin Schroll via Digitalmars-d-learn
The dlang-bot writes a message to every PR: Testing this PR locally If you don't have a local development environment setup, you can use Digger to test this PR: ```bash dub run digger -- build "master + dmd#<>" ``` I installed the current DMD (version 2.103.1) and executed the above

Re: How to use Dub and Digger to build Pull Requests?

2023-05-23 Thread Quirin Schroll via Digitalmars-d-learn
On Tuesday, 23 May 2023 at 13:50:09 UTC, Quirin Schroll wrote: The dlang-bot writes a message to every PR: Testing this PR locally If you don't have a local development environment setup, you can use Digger to test this PR: ```bash dub run digger -- build "master + dmd#<>" ``` I

Re: Given an object, how to call an alias to a member function on it?

2023-05-04 Thread Quirin Schroll via Digitalmars-d-learn
On Wednesday, 3 May 2023 at 11:38:46 UTC, Adam D Ruppe wrote: On Tuesday, 2 May 2023 at 13:57:23 UTC, Steven Schveighoffer wrote: Isn't that what `__traits(child)` is for? https://dlang.org/spec/traits.html#child Yes, `__traits(child, object, method_alias)(args)` is the way to do it. This

Given an object, how to call an alias to a member function on it?

2023-05-02 Thread Quirin Schroll via Digitalmars-d-learn
How do I invoke the member function in a reliable way? Given `obj` of the type of the object, I used `mixin("obj.", __traits(identifier, memberFunc), "(params)")`, but that has issues, among probably others, definitely with visibility. (The member function alias is a template parameter.)

Is there a way to get a template’s parameters and constraints?

2023-01-20 Thread Quirin Schroll via Digitalmars-d-learn
Is there a trait (or a combination of traits) that gives me the constraints of a template? Example: ```D void f(T1 : long, T2 : const(char)[])(T x) { } template constraintsOf(alias templ) { /*Magic here*/ } alias constraints = constraintsOf!f; // tuple(long, const(char)[]) ``` At the moment, I

How to do alligned allocation?

2022-09-30 Thread Quirin Schroll via Digitalmars-d-learn
When I do `new void[](n)`, is that buffer allocated with an alignment of 1 or what are the guarantees? How can I set an alignment? Also, is the alignment of any type guaranteed to be a power of 2?

Re: How to workaround on this (bug?)

2022-09-23 Thread Quirin Schroll via Digitalmars-d-learn
On Friday, 16 September 2022 at 22:43:43 UTC, frame wrote: ```d import std.variant; // error: destructor `std.variant.VariantN!32LU.VariantN.~this` is not `nothrow` void fun(Variant v) nothrow { } void main() { fun(Variant()); } ``` A reference, pointer or slice works. I could do

Re: to delete the '\0' characters

2022-09-23 Thread Quirin Schroll via Digitalmars-d-learn
On Thursday, 22 September 2022 at 10:53:32 UTC, Salih Dincer wrote: Is there a more accurate way to delete the '\0' characters at the end of the string? Accurate? No. Your code works. Correct is correct, no matter efficiency or style. I tried functions in this module: