Using C++ Classes From D: dmd cannot link, while ldc segfault

2024-01-25 Thread Matheus Catarino via Digitalmars-d-learn
https://forum.dlang.org/post/kawfhminmtmwbmkzh...@forum.dlang.org On Monday, 19 June 2023 at 06:11:59 UTC, mw wrote: LDC - the LLVM D compiler (1.32.2): ``` main.d(32): Error: undefined identifier `vector` in module `core.stdcpp.vector`, did you mean enum member `MIctor`? ``` So what's wrong

Re: Accessing array elements with a pointer-to-array

2024-01-25 Thread Kagamin via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ]; static_array[2][1] = 6; } The static array has length 2, so index 2 is out of bounds, must be 0 or 1.

Re: Accessing array elements with a pointer-to-array

2024-01-25 Thread Sergey via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: Can the elements of an array be accessed with a pointer using the usual indexing notation (e.g."[2][0]") for array elements? - or must we treat the elements associated with the pointer as 1-dimensional list and use pointer

Accessing array elements with a pointer-to-array

2024-01-25 Thread Stephen Tashiro via Digitalmars-d-learn
Can the elements of an array be accessed with a pointer using the usual indexing notation (e.g."[2][0]") for array elements? - or must we treat the elements associated with the pointer as 1-dimensional list and use pointer arithmetic? A more elementary question is why array index 2 is

Re: Why is the following failing?

2024-01-25 Thread ryuukk_ via Digitalmars-d-learn
On Thursday, 25 January 2024 at 17:50:57 UTC, Johan wrote: On Thursday, 25 January 2024 at 16:07:44 UTC, Stefan Koch wrote: On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
On Thursday, 25 January 2024 at 12:19:47 UTC, Paul Backus wrote: On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int

Re: Why is the following failing?

2024-01-25 Thread Johan via Digitalmars-d-learn
On Thursday, 25 January 2024 at 16:07:44 UTC, Stefan Koch wrote: On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above.. Raise a bug, I'll fix it. Hmm.

Re: Why is the following failing?

2024-01-25 Thread Erdem via Digitalmars-d-learn
On Thursday, 25 January 2024 at 16:07:44 UTC, Stefan Koch wrote: On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above.. Raise a bug, I'll fix it. buna

Re: Why is the following failing?

2024-01-25 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 25 January 2024 at 15:39:08 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above.. Raise a bug, I'll fix it.

Re: Why is the following failing?

2024-01-25 Thread ryuukk_ via Digitalmars-d-learn
```D void main() { char[32] id = 0; id = "hello"; } ``` this works fine, and that is what i expect for the example above..

Re: Why is the following failing?

2024-01-25 Thread ryuukk_ via Digitalmars-d-learn
On Thursday, 25 January 2024 at 15:22:35 UTC, Hipreme wrote: On Thursday, 25 January 2024 at 15:20:01 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` it should be a simple memcpy, why DMD complain? ``onlineapp.d(6):

Re: Why is the following failing?

2024-01-25 Thread Hipreme via Digitalmars-d-learn
On Thursday, 25 January 2024 at 15:20:01 UTC, ryuukk_ wrote: ```D void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` it should be a simple memcpy, why DMD complain? ``onlineapp.d(6): Error: mismatched array lengths 32 and 6 for assignment `id[] =

Why is the following failing?

2024-01-25 Thread ryuukk_ via Digitalmars-d-learn
```D void main() { char[32] id = 0; const(char)* str = "hello"; id = str[0 .. 6]; } ``` it should be a simple memcpy, why DMD complain? ``onlineapp.d(6): Error: mismatched array lengths 32 and 6 for assignment `id[] = str[0..6]``` I'm too tired to notice something obvious?

Re: Function Composition

2024-01-25 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 25 January 2024 at 08:25:02 UTC, atzensepp wrote: ```d int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` This leads to: ``` gdc lambda4.d lambda4.d:28:25: error: template compose(E)(E a) has no value int function(int) t = compose!(f,g,g,f,g,g,f,g,g,f); ``` Try using

Re: User defined type and foreach

2024-01-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, January 25, 2024 1:57:56 AM MST Jim Balter via Digitalmars-d- learn wrote: > The specification of ranges, which is independent of > the D language, says that the way to copy a range is to use > save(). I'm sorry, but you're misunderstanding the range specification if you think that

Re: Error "Outer Function Context is Needed" when class declared in unittest

2024-01-25 Thread Kagamin via Digitalmars-d-learn
Looks like the context is currently passed for nested functions, not for nested classes.

Re: Setting field of struct object

2024-01-25 Thread zjh via Digitalmars-d-learn
On Thursday, 25 January 2024 at 08:46:34 UTC, Renato wrote: ```d void main() { Person p = { "Joe", "j...@ab.com", 30}; writeln(p); } ``` I just tested it and it works. It's `great`!

Re: User defined type and foreach

2024-01-25 Thread Jim Balter via Digitalmars-d-learn
On Friday, 19 January 2024 at 18:13:55 UTC, Jonathan M Davis wrote: On Friday, January 19, 2024 3:49:29 AM MST Jim Balter via Digitalmars-d-learn wrote: On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis wrote: > When you have > > foreach(e; range) > > it gets lowered to something

Re: Setting field of struct object

2024-01-25 Thread Renato via Digitalmars-d-learn
On Monday, 22 January 2024 at 11:31:11 UTC, zjh wrote: On Monday, 22 January 2024 at 08:54:54 UTC, zjh wrote: ```d struct Person { string name, email; ulong age; } Person a{"n","email",33}; ``` C++ can achieve ultimate `simplicity` without violating `DRY`, And here, D violates the

Re: Function Composition

2024-01-25 Thread atzensepp via Digitalmars-d-learn
On Wednesday, 24 January 2024 at 21:34:26 UTC, user1234 wrote: On Wednesday, 24 January 2024 at 21:30:23 UTC, user1234 wrote: On Wednesday, 24 January 2024 at 21:12:20 UTC, atzensepp wrote: [...] what a bummer! Have you tried https://dlang.org/phobos/std_functional.html#compose ? Well