Re: D feature request

2024-08-07 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 4 August 2024 at 10:06:49 UTC, aberba wrote: So if I have a feature request, but I don't have the necessary technical skills to draft a DIP with the implementation details, is there a process in D community to submit such a request? please continue here:

Re: D feature request

2024-08-06 Thread IchorDev via Digitalmars-d-learn
On Monday, 5 August 2024 at 12:25:48 UTC, user1234 wrote: On Monday, 5 August 2024 at 03:09:41 UTC, IchorDev wrote: Also sometimes if a feature is very minor you can submit a ‘feature request’ issue. "enhancement" is the bugzilla word for this. IIRC it's in the "severity" field. Yes,

Re: importC with struct name and function conflict

2024-08-05 Thread Dakota via Digitalmars-d-learn
On Monday, 5 August 2024 at 11:35:56 UTC, Dennis wrote: On Monday, 5 August 2024 at 11:02:24 UTC, Dakota wrote: This will not work for me. (huge code base I can not change and maintain) You don't have to change the code where the type is defined per se, you just need to put it in any C file

Re: D feature request

2024-08-05 Thread Dom DiSc via Digitalmars-d-learn
On Sunday, 4 August 2024 at 10:06:49 UTC, aberba wrote: So if I have a feature request, but I don't have the necessary technical skills to draft a DIP with the implementation details, is there a process in D community to submit such a request? DIP Ideas?

Re: D feature request

2024-08-05 Thread user1234 via Digitalmars-d-learn
On Monday, 5 August 2024 at 03:09:41 UTC, IchorDev wrote: On Sunday, 4 August 2024 at 10:32:38 UTC, Richard (Rikki) Andrew Cattermole wrote: Chuck it into the ideas forum. If it interests somebody, somebody else can work on it. Also sometimes if a feature is very minor you can submit a

Re: importC with struct name and function conflict

2024-08-05 Thread Dennis via Digitalmars-d-learn
On Monday, 5 August 2024 at 11:02:24 UTC, Dakota wrote: This will not work for me. (huge code base I can not change and maintain) You don't have to change the code where the type is defined per se, you just need to put it in any C file that can access the C symbol. clib_helpers.c: ```C

Re: importC with struct name and function conflict

2024-08-05 Thread Dakota via Digitalmars-d-learn
On Saturday, 3 August 2024 at 11:55:53 UTC, Dennis wrote: On Saturday, 3 August 2024 at 05:10:37 UTC, Dakota wrote: How can I get the function and type from importC? is there a auto rename mechanism ? The most pragmatic workaround is to add a typedef to the C code: ```C int S; struct S {

Re: D feature request

2024-08-04 Thread IchorDev via Digitalmars-d-learn
On Sunday, 4 August 2024 at 10:32:38 UTC, Richard (Rikki) Andrew Cattermole wrote: Chuck it into the ideas forum. If it interests somebody, somebody else can work on it. Also sometimes if a feature is very minor you can submit a ‘feature request’ issue.

Re: D feature request

2024-08-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 04/08/2024 10:06 PM, aberba wrote: So if I have a feature request, but I don't have the necessary technical skills to draft a DIP with the implementation details, is there a process in D community to submit such a request? Other communities using GitHub have a way to file an issue which

D feature request

2024-08-04 Thread aberba via Digitalmars-d-learn
So if I have a feature request, but I don't have the necessary technical skills to draft a DIP with the implementation details, is there a process in D community to submit such a request? Other communities using GitHub have a way to file an issue which then gets labelled as a feature request

Re: Get compile time string of dmd command line options "-os" & "-target"

2024-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 3 August 2024 at 12:15:46 UTC, Dennis wrote: On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote: pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os

Re: Get compile time string of dmd command line options "-os" & "-target"

2024-08-03 Thread Dennis via Digitalmars-d-learn
On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote: pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os = "windows"; else version(AArch64) enum os =

Re: importC with struct name and function conflict

2024-08-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 August 2024 at 05:10:37 UTC, Dakota wrote: How can I get the function and type from importC? is there a auto rename mechanism ? The most pragmatic workaround is to add a typedef to the C code: ```C int S; struct S { int a, b; }; typedef struct S S_t;// add this typedef ```

Re: importC error: can not find the #define ERR_INVALID -1

2024-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 3 August 2024 at 05:07:55 UTC, Dakota wrote: ```c #define ERR_SUCCESS 0 #define ERR_INVALID -1 // invalid argument ``` If the number >=0, it work. < 0 will not work. DMD64 D Compiler v2.110.0-beta.1 https://issues.dlang.org/show_bug.cgi?id=24639 -Steve

importC with struct name and function conflict

2024-08-02 Thread Dakota via Digitalmars-d-learn
```c struct type_name { int a; } int type_name(int a); ``` How can I get the function and type from importC? is there a auto rename mechanism ?

importC error: can not find the #define ERR_INVALID -1

2024-08-02 Thread Dakota via Digitalmars-d-learn
```c #define ERR_SUCCESS 0 #define ERR_INVALID -1 // invalid argument ``` If the number >=0, it work. < 0 will not work. DMD64 D Compiler v2.110.0-beta.1

Re: How to work with long paths on Windows?

2024-08-02 Thread James Carter via Digitalmars-d-learn
On Monday, 14 November 2022 at 18:45:40 UTC, Imperatorn wrote: On Monday, 14 November 2022 at 14:43:50 UTC, Preetpal wrote: On Monday, 14 November 2022 at 10:44:11 UTC, Imperatorn wrote: On Tuesday, 13 September 2022 at 19:54:15 UTC, Preetpal wrote: [...] Have you set longPathAware in the

Re: Any way to automatically convert structs on return?

2024-08-02 Thread Juraj via Digitalmars-d-learn
On Thursday, 1 August 2024 at 07:25:53 UTC, Emma wrote: ```d Option!int something() { return None(); // Error: cannot implicitly convert expression `None()` of type `None` to `Option!int` } ``` Not D per se, but you can check Adam D. Ruppe's current work. If I am not mistaken, the thing

Re: Segmentation fault while reading a file

2024-08-01 Thread IchorDev via Digitalmars-d-learn
On Thursday, 1 August 2024 at 14:42:36 UTC, Ruby The Roobster wrote: Thank you. I am not very well acquainted with the standard library, and this cleans up things significantly. Question: Is there a good guide to Phobos anywhere? I would like to learn the more commonly used algorithms /

Re: Any way to automatically convert structs on return?

2024-08-01 Thread IchorDev via Digitalmars-d-learn
On Thursday, 1 August 2024 at 14:20:29 UTC, user1234 wrote: That was a general criticism of implicit construction. We are only talking about it in the context of returning from a function. The classic example is ```d struct S {int i;} function f(S s); function f(int i); unittest { f(0);

Re: Any way to automatically convert structs on return?

2024-08-01 Thread Emma via Digitalmars-d-learn
Thanks everyone for the replies! I just thought it was weird that implicit construction is seemingly supported when directly initialising a struct but not in any other case. I guess it's because it's clearly less ambiguous. On Thursday, 1 August 2024 at 13:07:09 UTC, Lance Bachmeier wrote:

Re: Any way to automatically convert structs on return?

2024-08-01 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 1 August 2024 at 08:46:00 UTC, IchorDev wrote: P.S. You might want to put `value = void`, otherwise it’ll always be default-constructed. Doing `= void` can violate the assumptions of a destructor of T. Nullable uses a union to store T, so it can decide when to call the

Re: Segmentation fault while reading a file

2024-08-01 Thread Ruby The Roobster via Digitalmars-d-learn
On Thursday, 1 August 2024 at 07:03:04 UTC, IchorDev wrote: Hey just a heads up, you might wanna use [`readText`](https://dlang.org/library/std/file/read_text.html) and [`lineSplitter`](https://dlang.org/library/std/string/line_splitter.html) just so you don’t have to deal with file handles.

Re: Any way to automatically convert structs on return?

2024-08-01 Thread user1234 via Digitalmars-d-learn
On Thursday, 1 August 2024 at 10:59:03 UTC, IchorDev wrote: On Thursday, 1 August 2024 at 09:55:08 UTC, user1234 wrote: The problem would be that sorting the candidates of an overload set would be more complicated. Also in certain cases it would be less obvious to get which one is selected.

Re: Any way to automatically convert structs on return?

2024-08-01 Thread Lance Bachmeier via Digitalmars-d-learn
On Thursday, 1 August 2024 at 07:25:53 UTC, Emma wrote: but this doesn't: ```d Option!int something() { return None(); // Error: cannot implicitly convert expression `None()` of type `None` to `Option!int` } ``` For the program you've written, I'm happy it doesn't compile, because a lot

Re: Any way to automatically convert structs on return?

2024-08-01 Thread IchorDev via Digitalmars-d-learn
On Thursday, 1 August 2024 at 09:55:08 UTC, user1234 wrote: The problem would be that sorting the candidates of an overload set would be more complicated. Also in certain cases it would be less obvious to get which one is selected. Please elaborate about how this would interact with function

Re: Any way to automatically convert structs on return?

2024-08-01 Thread user1234 via Digitalmars-d-learn
On Thursday, 1 August 2024 at 08:46:00 UTC, IchorDev wrote: [...] I’m pretty sure this is intentional to prevent ambiguity, but I can’t quite remember what the point of that is. The problem would be that sorting the candidates of an overload set would be more complicated. Also in certain

Re: Any way to automatically convert structs on return?

2024-08-01 Thread Dukc via Digitalmars-d-learn
Emma kirjoitti 1.8.2024 klo 10.25: This kind of prevents ergonomic code like the above. Instead you have to use a function like `Option!T None(T)() => Option!T()` and then you have to repeat yourself with `return None!int` and etc... it's quite annoying :( While this isn't exactly less

Re: Any way to automatically convert structs on return?

2024-08-01 Thread IchorDev via Digitalmars-d-learn
On Thursday, 1 August 2024 at 07:25:53 UTC, Emma wrote: This code works: ```d struct None {} struct Option(T) { bool hasSome; T value; this(None) {} this(T v) { hasSome = true; value = v; } } Option!int a = 123;// automatically constructs an

Re: Any way to automatically convert structs on return?

2024-08-01 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
No, D does not support implicit construction. However in saying that, I will continue to argue in support of sum types when they get added to the language to support implicit construction!

Any way to automatically convert structs on return?

2024-08-01 Thread Emma via Digitalmars-d-learn
This code works: ```d struct None {} struct Option(T) { bool hasSome; T value; this(None) {} this(T v) { hasSome = true; value = v; } } Option!int a = 123;// automatically constructs an Option!int from a bare int Option!int b = None(); // same as

Re: Segmentation fault while reading a file

2024-08-01 Thread IchorDev via Digitalmars-d-learn
Hey just a heads up, you might wanna use [`readText`](https://dlang.org/library/std/file/read_text.html) and [`lineSplitter`](https://dlang.org/library/std/string/line_splitter.html) just so you don’t have to deal with file handles. Also you can use something like

Re: Segmentation fault while reading a file

2024-07-31 Thread Ruby The Roobster via Digitalmars-d-learn
Nevermind. The segfault happened because I accidentally used the Mesh class before loading OpenGL. I don't know if it works as intended, but it no longer crashes.

Get compile time string of dmd command line options "-os" & "-target"

2024-07-31 Thread An Pham via Digitalmars-d-learn
pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); what is use case for this? mixin & import Long list of version. version(Windows) mixin(import("foo_windows.enum.")); else version(AArch64) mixin(import("foo_aarch64.enum")); else static

Re: Segmentation fault while reading a file

2024-07-31 Thread matheus via Digitalmars-d-learn
On Wednesday, 31 July 2024 at 23:06:30 UTC, Ruby The Roobster wrote: ... or is `readln` bugging out because the file (backpack.obj contained in the linked .zip file) is too large? ... I don't have I compiler in hand to try your code at moment, but about your concern over the size of the

Segmentation fault while reading a file

2024-07-31 Thread Ruby The Roobster via Digitalmars-d-learn
I decided to attempt to write my own OBJ loading library, seeing as the spec for the format is readily available online. Building with DMD and on Windows, and testing on [this model](https://learnopengl.com/data/models/backpack.zip), the code acts normally for a while, and then apparently

vibedist status

2024-07-30 Thread Menjanahary R. R. via Digitalmars-d-learn
What has become of the project? What are the workaround apart from using ngnix?

Re: copy must be const?!?

2024-07-30 Thread swigy food via Digitalmars-d-learn
Hello A const copy ensures the copied value remains unchanged, providing safety and predictability. If the original is const, copying it as non-const could introduce unintended side effects. To modify a copied value, create a mutable copy explicitly. For file systems, copying write-protected

Re: copy must be const?!?

2024-07-29 Thread Dom DiSc via Digitalmars-d-learn
On Friday, 26 July 2024 at 10:04:45 UTC, Jonathan M Davis wrote: On Friday, July 26, 2024 2:17:21 AM MDT Dom DiSc via Digitalmars-d-learn wrote: If you are not able to construct a mutable copy of a type, why on earth are you handing it over by value?!? Why not? Because you can't make a

Re: Libraries for Model Loading

2024-07-26 Thread Chance Snow via Digitalmars-d-learn
On Thursday, 18 July 2024 at 14:02:09 UTC, Ruby The Roobster wrote: Is there a good package available that can load models, Wavefront .obj files in particular? I tried to use the existing bindings to old versions of Assimp, but I could not get Assimp itself to build on my machine. Thanks in

Re: copy must be const?!?

2024-07-26 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 26, 2024 2:17:21 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > 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 > > > >> But a parameter given by value is ALWAYS a copy. > > > > It has to be a _full_,

Re: Libraries for Model Loading

2024-07-26 Thread IchorDev via Digitalmars-d-learn
On Thursday, 18 July 2024 at 14:02:09 UTC, Ruby The Roobster wrote: Is there a good package available that can load models, Wavefront .obj files in particular? I tried to use the existing bindings to old versions of Assimp, but I could not get Assimp itself to build on my machine. Thanks in

Re: copy must be const?!?

2024-07-26 Thread Dom DiSc 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 But a parameter given by value is ALWAYS a copy. It has to be a _full_, independent copy. If you're talking about integer types, that's a non-issue, but if you're talking

Re: copy must be const?!?

2024-07-26 Thread Dom DiSc via Digitalmars-d-learn
On Friday, 26 July 2024 at 02:34:12 UTC, Andy Valencia wrote: On Thursday, 25 July 2024 at 13:07:03 UTC, Jonathan M Davis wrote: It's most definitely not a bug that IFTI (Implicit Function Template Instantiation) instantiates the template with the exact type that it's given. The "principle

Re: Prevent self-comparison without taking the address

2024-07-26 Thread Dom DiSc via Digitalmars-d-learn
On Thursday, 25 July 2024 at 15:40:29 UTC, Nick Treleaven wrote: On Thursday, 25 July 2024 at 15:06:35 UTC, IchorDev wrote: I think your function most likely has a safe interface, so it can be marked as `@trusted` as-per [the spec](https://dlang.org/spec/function.html#safe-interfaces). Just

Yadier Molina joins Cardinals entrance workplace

2024-07-25 Thread vitreous via Digitalmars-d-learn
NASHVILLE, Tenn. Yadier Molina, a franchise fixture at catcher for 19 seasons and the powering tension powering Planet Sequence wins inside 2006 and 11, rejoined the Cardinals as a exceptional assistant toward president of baseball functions John Mozeliak, the club declared upon 41 yr

5/18 Gamethread: Giants vs. Rockies

2024-07-25 Thread vitreous via Digitalmars-d-learn
Luis Matos strike a 3 operate dwelling function as I was positioning this thread collectively hence, youre welcome. Only overall look at it pay attention in direction of it soak it up and saLUte RFZoKVfgyJ SFGiants May perhaps 18, 2024Its a wonder what a 3 function property function can do.

Re: What is an rvalue constructor?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 4:48:06 PM MDT Quirin Schroll via Digitalmars-d- learn wrote: > It seems one can’t have one in a struct together with a copy > constructor, but what is it? When is it called? What is it for? An rvalue constructor is a constructor that takes the same type as the struct

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 4:50:04 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > I have copied some source from C++, where the following pattern > is common (operator== already renamed): > > ```d > @safe: > struct S > { > bool opEquals(const ref S x) const > { >if(==) return

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: Prevent self-comparison without taking the address

2024-07-25 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 25 July 2024 at 15:06:35 UTC, IchorDev wrote: I think your function most likely has a safe interface, so it can be marked as `@trusted` as-per [the spec](https://dlang.org/spec/function.html#safe-interfaces). Just to mention that with -dip1000, taking the address of variables is

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 14:05:50 UTC, Dom DiSc wrote: As he said: no. It's only true for @safe: No they did not, they specifically said that my assertion holds true for all other [function attributes](https://dlang.org/spec/attribute.html#function-attributes). This does not tell me

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
On Thursday, 25 July 2024 at 13:20:59 UTC, IchorDev wrote: On Thursday, 25 July 2024 at 13:01:53 UTC, Dennis wrote: That's true for the other function attributes, but `@safe:` actually does penetrate scopes The spec doesn’t mention this at all! Is this the case for any other

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 13:01:53 UTC, Dennis wrote: That's true for the other function attributes, but `@safe:` actually does penetrate scopes The spec doesn’t mention this at all! Is this the case for any other `AttributeSpecifier` declarations?

Re: copy must be const?!?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
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, which it would with an integer type) > > But a parameter given

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 July 2024 at 11:46:29 UTC, IchorDev wrote: Also just so you know, placing `@safe:` there will not affect the contents of `S`. It has to be inside the struct declaration to affect its contents. That's true for the other function attributes, but `@safe:` actually does penetrate

Re: copy must be const?!?

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
On Thursday, 25 July 2024 at 08:42:29 UTC, Jonathan M Davis wrote: It's not a cast. Casts in D use the keyword, cast - e.g. return --(cast(T)x); Rather, Dennis' solution is constructing a value of the given type. For it to work, T must be constructible from an immutable T - which works

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 10:50:04 UTC, Dom DiSc wrote: ```d @safe: struct S{ ``` Also just so you know, placing `@safe:` there will not affect the contents of `S`. It has to be inside the struct declaration to affect its contents.

Re: Prevent self-comparison without taking the address

2024-07-25 Thread IchorDev via Digitalmars-d-learn
On Thursday, 25 July 2024 at 10:50:04 UTC, Dom DiSc wrote: Can I replace this pattern with ```(x is this)``` or are there some special cases where this doen't work? When a parameter is `ref` it is treated as a value type (i.e. it has value semantics), even though it is a reference; therefore

Prevent self-comparison without taking the address

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
I have copied some source from C++, where the following pattern is common (operator== already renamed): ```d @safe: struct S { bool opEquals(const ref S x) const { if(==) return true; ... } } ``` Can I replace this pattern with ```(x is this)``` or are there some special

Re: copy must be const?!?

2024-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, July 25, 2024 12:50:04 AM MDT Dom DiSc via Digitalmars-d-learn wrote: > On Wednesday, 24 July 2024 at 15:40:28 UTC, Dennis wrote: > >> Is there a way to tell the compiler that it should discard > >> "const" and "immutable" if it needs to create a copy? > >> Unqual!T doesn't work :-(

Re: copy must be const?!?

2024-07-25 Thread Dom DiSc via Digitalmars-d-learn
On Wednesday, 24 July 2024 at 15:40:28 UTC, Dennis wrote: Is there a way to tell the compiler that it should discard "const" and "immutable" if it needs to create a copy? Unqual!T doesn't work :-( When you add `const` or `immutable` before the template type parameter, it will infer T as

copy must be const?!?

2024-07-24 Thread Dom DiSc via Digitalmars-d-learn
In following code: ```d int test(int x) { return --x; } T test2(T)(T x) { return --x; } void main() { const int v = 3; writeln(test(v)); writeln(test2(v)); // doesn't compile } ``` test2 (just like test) works on a copy of x. Why is this copy const?!? If I copy a const or immutable

Re: Array concatenation & optimisation

2024-07-22 Thread IchorDev via Digitalmars-d-learn
On Monday, 22 July 2024 at 12:03:33 UTC, Quirin Schroll wrote: this has no effect on whether the function is `@nogc`. That is a highly amusing (but obviously understandable) logical contradiction that I’d never considered before. ‘Sometimes you can’t use non-GC code in `@nogc` code.’

Re: Array concatenation & optimisation

2024-07-22 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 21 July 2024 at 10:33:38 UTC, Nick Treleaven wrote: On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Does this mean that array literals are *always* separately allocated first, or is this usually optimised out? My understanding is that they do not allocate if used to

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: Using FFI to write a std::string to a buffer passed in from D

2024-07-21 Thread Troy via Digitalmars-d-learn
On Sunday, 21 July 2024 at 15:31:47 UTC, Johan wrote: On Sunday, 21 July 2024 at 13:35:46 UTC, Troy wrote: void create(void* b) { std::string s = "engineer again"; *(std::string*)(b) = s;// Segfault here } You have to construct an empty string object first in location `b`

Re: Array concatenation & optimisation

2024-07-21 Thread IchorDev via Digitalmars-d-learn
On Sunday, 21 July 2024 at 15:41:50 UTC, Johan wrote: https://d.godbolt.org/z/sG5Kancs4 The short array is not dynamically allocated (it's allocated on the stack, or for larger arrays it will be a hidden symbol in the binary image), even at `-O0` (i.e. `-O` was not passed). Wow thanks,

Re: Array concatenation & optimisation

2024-07-21 Thread IchorDev via Digitalmars-d-learn
On Sunday, 21 July 2024 at 10:33:38 UTC, Nick Treleaven wrote: Just to mention that if you assign to the static array it works: `a = [1,3,6,9];`. Bonkers. `array[]` is meant to be 'all of `array` as a slice', so you'd think that's how you copy a slice to a static array, but no! My

Re: Array concatenation & optimisation

2024-07-21 Thread Johan via Digitalmars-d-learn
On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Does this mean that array literals are *always* separately allocated first, or is this usually optimised out? Not always allocated, see your example below. I don't quite know what the heuristic is for allocation or not... For

Re: Using FFI to write a std::string to a buffer passed in from D

2024-07-21 Thread Johan via Digitalmars-d-learn
On Sunday, 21 July 2024 at 13:35:46 UTC, Troy wrote: void create(void* b) { std::string s = "engineer again"; *(std::string*)(b) = s;// Segfault here } You have to construct an empty string object first in location `b` (emplacement new). Then you can assign to it as you do.

Using FFI to write a std::string to a buffer passed in from D

2024-07-21 Thread Troy via Digitalmars-d-learn
I have a weird issue I've been running into while trying to write D bindings to some C++ code. I'm trying to call some C++ functions that take in a std::string but don't make a copy of it. To do this, I want to write a std::string to a buffer passed in from D so I can keep it from being

Re: Array concatenation & optimisation

2024-07-21 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 21 July 2024 at 10:33:38 UTC, Nick Treleaven wrote: For instance, will this example *always* allocate a new dynamic array for the array literal, and then append it to the existing one, even in optimised builds? ```d void append(ref int[] a){ a ~= [5, 4, 9]; } ``` If there

Re: Tuple deconstruction in Phobos

2024-07-21 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 21 July 2024 at 04:05:52 UTC, IchorDev wrote: On Saturday, 20 July 2024 at 20:48:29 UTC, Nick Treleaven wrote: Instead of the `tie` assignment, you can just do: ```d import std.meta; AliasSeq!(y, x) = tupRetFn().expand; ``` And here I was trying to use comma

Re: Array concatenation & optimisation

2024-07-21 Thread Nick Treleaven 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[] =

Array concatenation & optimisation

2024-07-20 Thread IchorDev via Digitalmars-d-learn
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[] = [1,3,6,9]; //Error: array literal in `@nogc` function `assign`

Re: Tuple deconstruction in Phobos

2024-07-20 Thread IchorDev via Digitalmars-d-learn
On Saturday, 20 July 2024 at 20:48:29 UTC, Nick Treleaven wrote: Instead of the `tie` assignment, you can just do: ```d import std.meta; AliasSeq!(y, x) = tupRetFn().expand; ``` And here I was trying to use comma expressions for this like a buffoon! Of course they didn't work,

Re: Tuple deconstruction in Phobos

2024-07-20 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 20 July 2024 at 14:02:21 UTC, IchorDev wrote: Why does Phobos not provide a method to easily deconstruct tuples? Here's a trivial implementation: ... tie!(y, x) = tupRetFn().expand; writeln(x,", ",y); } ``` Not having this is like if Phobos didn't have `AliasSeq`.

Tuple deconstruction in Phobos

2024-07-20 Thread IchorDev via Digitalmars-d-learn
Why does Phobos not provide a method to easily deconstruct tuples? Here's a trivial implementation: ```d //Similar to C++'s `std::tie`. Can anyone tell me why it's called `tie`? void tie(T...)(typeof(T) src){ static foreach(ind, i; src){ T[ind] = i; } } //Usage

Re: Unexpected range assignment behaviour

2024-07-19 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, July 19, 2024 12:02:55 PM MDT H. S. Teoh via Digitalmars-d-learn wrote: > On Fri, Jul 19, 2024 at 05:48:37PM +, Dennis via Digitalmars-d-learn wrote: > > On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: > > > couldn't this case for example be caught during the compiling

Re: Unexpected range assignment behaviour

2024-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 19, 2024 at 05:48:37PM +, Dennis via Digitalmars-d-learn wrote: > On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: > > couldn't this case for example be caught during the compiling time? > > The RangeError is only thrown when at runtime, the key doesn't exist, > so that

Re: Unexpected range assignment behaviour

2024-07-19 Thread Dennis via Digitalmars-d-learn
On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: couldn't this case for example be caught during the compiling time? The RangeError is only thrown when at runtime, the key doesn't exist, so that can't be caught. The real problem is implicit slicing of static arrays, which I'm not a

Re: Unexpected range assignment behaviour

2024-07-19 Thread matheus via Digitalmars-d-learn
On Friday, 19 July 2024 at 15:33:34 UTC, Dennis wrote: On Friday, 19 July 2024 at 09:34:13 UTC, Lewis wrote: But the value of $ here is 3. Why do I get a RangeError at runtime even though the slice is the correct size (and the same size as the hardcoded one that works)? The range `0 .. 3`

Re: Unexpected range assignment behaviour

2024-07-19 Thread Lance Bachmeier via Digitalmars-d-learn
On Friday, 19 July 2024 at 09:34:13 UTC, Lewis wrote: ``` string[3][string] lookup; string[] dynArray = ["d", "e", "f"]; lookup["test"] = dynArray[0..$]; ``` This fails at runtime with RangeError. But if I change that last line to: ``` lookup["test"] = dynArray[0..3]; ``` then it works. But

Re: Unexpected range assignment behaviour

2024-07-19 Thread Dennis via Digitalmars-d-learn
On Friday, 19 July 2024 at 09:34:13 UTC, Lewis wrote: But the value of $ here is 3. Why do I get a RangeError at runtime even though the slice is the correct size (and the same size as the hardcoded one that works)? The range `0 .. 3` has compile time known length, so it gets converted to

Re: Unexpected range assignment behaviour

2024-07-19 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Jul 19, 2024 at 09:34:13AM +, Lewis via Digitalmars-d-learn wrote: > ``` > string[3][string] lookup; > string[] dynArray = ["d", "e", "f"]; > lookup["test"] = dynArray[0..$]; > ``` > > This fails at runtime with RangeError. But if I change that last line to: > > ``` > lookup["test"]

Unexpected range assignment behaviour

2024-07-19 Thread Lewis via Digitalmars-d-learn
``` string[3][string] lookup; string[] dynArray = ["d", "e", "f"]; lookup["test"] = dynArray[0..$]; ``` This fails at runtime with RangeError. But if I change that last line to: ``` lookup["test"] = dynArray[0..3]; ``` then it works. But the value of $ here is 3. Why do I get a RangeError

Re: Error: circular reference to variable cause by order (bugs?)

2024-07-18 Thread monkyyy via Digitalmars-d-learn
On Thursday, 18 July 2024 at 12:25:37 UTC, Dakota wrote: I am trying to translate some c code into d, get this error: ```d struct A { void* sub; } struct B { void* subs; } __gshared { const A[1] a0 = [ { _ptr }, ]; const A[2] a1 = [

Libraries for Model Loading

2024-07-18 Thread Ruby The Roobster via Digitalmars-d-learn
Is there a good package available that can load models, Wavefront .obj files in particular? I tried to use the existing bindings to old versions of Assimp, but I could not get Assimp itself to build on my machine. Thanks in advance.

Error: circular reference to variable cause by order (bugs?)

2024-07-18 Thread Dakota via Digitalmars-d-learn
I am trying to translate some c code into d, get this error: ```d struct A { void* sub; } struct B { void* subs; } __gshared { const A[1] a0 = [ { _ptr }, ]; const A[2] a1 = [ { _ptr }, ]; const B b1 =

Re: Recommendations on porting Python to D

2024-07-17 Thread rkompass via Digitalmars-d-learn
On Monday, 15 July 2024 at 19:40:01 UTC, mw wrote: On Friday, 12 July 2024 at 18:07:50 UTC, mw wrote: [...] FYI, now merged into the main branch: https://github.com/py2many/py2many/tree/main/pyd This is great and certainly deserves an own discussion contribution in General. Did you try

Re: Recommendations on porting Python to D

2024-07-15 Thread mw via Digitalmars-d-learn
On Friday, 12 July 2024 at 18:07:50 UTC, mw wrote: On Friday, 3 May 2024 at 17:38:10 UTC, Chris Piker wrote: On Thursday, 25 April 2024 at 16:57:53 UTC, mw wrote: On Wednesday, 24 April 2024 at 22:07:41 UTC, Chris Piker wrote: Python-AST to D source converter may already exist?

Re: need help to check symbol is static variable or not

2024-07-15 Thread Dakota via Digitalmars-d-learn
On Monday, 15 July 2024 at 11:16:23 UTC, Nick Treleaven wrote: I put `type_s` in a file anonstruct.c, then: ```d import anonstruct; pragma(msg, isStatic!(type_s.c)); ``` That outputs `false`, because the symbol is not a compile-time value. Is that what you meant? No, I am here deal with a

Re: need help to check symbol is static variable or not

2024-07-15 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 15 July 2024 at 06:44:12 UTC, Dakota wrote: ```d struct type_s { union { struct { int a; int b; } c; }; }; ``` `type c` will return false with `enum isStatic(alias V) = __traits(compiles, { enum v = V; });` I put `type_s` in

Re: need help to check symbol is static variable or not

2024-07-15 Thread Dakota via Digitalmars-d-learn
On Monday, 1 July 2024 at 11:15:46 UTC, Nick Treleaven wrote: ``` There is a case check will give wrong resutls: ```d struct type_s { union { struct { int a; int b; } c; }; }; ``` `type c` will return false with `enum isStatic(alias

Re: std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-14 Thread mw via Digitalmars-d-learn
On Sunday, 14 July 2024 at 02:01:44 UTC, Steven Schveighoffer wrote: On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote: Hi, on doc: https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree I cannot find any search method?! e.g. `contains`, `canFind`. Is this a over look? Or there

Re: How to build a statically linked executable, before i loose my mind

2024-07-14 Thread ryuukk_ via Digitalmars-d-learn
On Sunday, 14 July 2024 at 06:34:54 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/07/2024 5:06 AM, ryuukk_ wrote: On Saturday, 13 July 2024 at 16:44:22 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/07/2024 4:37 AM, ryuukk_ wrote: On Saturday, 13 July 2024 at 16:16:20 UTC, Richard

Re: Wrapper around a recursive data type

2024-07-14 Thread drug007 via Digitalmars-d-learn
On 09.07.2024 06:54, Steven Schveighoffer wrote: On Monday, 8 July 2024 at 08:56:51 UTC, drug007 wrote: How can I "break" this recursion or some other work around to fix it? A few ideas: 1. If it's immediately recursive (that is, contains a pointer to itself), just use the type itself

Re: How to build a statically linked executable, before i loose my mind

2024-07-14 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 14/07/2024 5:06 AM, ryuukk_ wrote: On Saturday, 13 July 2024 at 16:44:22 UTC, Richard (Rikki) Andrew Cattermole wrote: On 14/07/2024 4:37 AM, ryuukk_ wrote: On Saturday, 13 July 2024 at 16:16:20 UTC, Richard (Rikki) Andrew Cattermole wrote: Seeing ``_d_arraybounds_slice`` missing sounds

Re: std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote: Hi, on doc: https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree I cannot find any search method?! e.g. `contains`, `canFind`. Is this a over look? Or there are such functions else where? The functions are called `equalRange`

  1   2   3   4   5   6   7   8   9   10   >