Re: C to D: please help translate this weird macro

2023-09-23 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D

Re: C to D: please help translate this weird macro

2023-09-22 Thread Ki Rill via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:50:51 UTC, Imperatorn wrote: On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ```

Re: C to D: please help translate this weird macro

2023-09-22 Thread Ki Rill via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: The 1st argument of `getMember` can just be T, like the original macro. The 2nd argument needs to be a compile-time string. Also the `char*` cast needs to apply to `ptr` before subtracting the offset AFAICS. So

Re: C to D: please help translate this weird macro

2023-09-21 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D

Re: C to D: please help translate this weird macro

2023-09-21 Thread user1234 via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: (Untested) There might be a `need this` error

Re: C to D: please help translate this weird macro

2023-09-21 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 21 September 2023 at 16:28:25 UTC, Nick Treleaven wrote: return cast(T*)(cast(void*)(cast(char*)ptr - __traits(getMember, T, member).offsetof))); There's a trailing `)` that needs removing. Also pretty sure it can be simplified to: return cast(T*)(cast(char*)ptr

Re: C to D: please help translate this weird macro

2023-09-21 Thread Nick Treleaven via Digitalmars-d-learn
On Thursday, 21 September 2023 at 02:57:07 UTC, Ki Rill wrote: On Thursday, 21 September 2023 at 02:23:32 UTC, Ki Rill wrote: wrote: [...] Translated it to this eventually: ```D auto nk_container_of(P, T)(P ptr, T type, const(char)* member) { return cast(T*)(cast(void*)(cast(char*)

Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn
On Thursday, 21 September 2023 at 02:23:32 UTC, Ki Rill wrote: wrote: [...] Translated it to this eventually: ```D auto nk_container_of(P, T)(P ptr, T type, const(char)* member) { return cast(T*)(cast(void*)(cast(char*) (ptr - __traits(getMember, type, member).offsetof))); } ```

Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 17:14:41 UTC, Dejan Lekic wrote: [...] NK_CONTAINER_OF should probably be translated to: `cast(T*)((cast(void*)ptr - __traits(getMember, T, member).offsetof))` PS. I did not invent this. My original idea was far worse than this. - It was suggested on IRC

Re: C to D: please help translate this weird macro

2023-09-20 Thread Dejan Lekic via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote: On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm

Re: C to D: please help translate this weird macro

2023-09-20 Thread ryuukk_ via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D

Re: C to D: please help translate this weird macro

2023-09-20 Thread Dejan Lekic via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:55:14 UTC, Ki Rill wrote: On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm

Re: C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn
On Wednesday, 20 September 2023 at 13:53:08 UTC, Ki Rill wrote: Here is the macro: ```C #define NK_CONTAINER_OF(ptr,type,member)\ (type*)((void*)((char*)(1 ? (ptr): &((type*)0)->member) - NK_OFFSETOF(type, member))) ``` I'm trying to translate the Nuklear GUI library to D

Re: C to D convertor

2021-08-24 Thread Виталий Фадеев via Digitalmars-d-learn
On Tuesday, 24 August 2021 at 11:52:45 UTC, Dennis wrote: On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: Any more ? CPP2D https://github.com/lhamot/CPP2D Dennis, thank!

Re: C to D convertor

2021-08-24 Thread Dennis via Digitalmars-d-learn
On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: Any more ? CPP2D https://github.com/lhamot/CPP2D

Re: C to D convertor

2021-08-21 Thread Виталий Фадеев via Digitalmars-d-learn
On Saturday, 21 August 2021 at 08:59:55 UTC, evilrat wrote: On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: I know, i know... It not possible, but part of the C code we can to convert to the D. Show me, please, solutions, projects, tools, scripts, docs. Can you give the link

Re: C to D convertor

2021-08-21 Thread evilrat via Digitalmars-d-learn
On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: I know, i know... It not possible, but part of the C code we can to convert to the D. Show me, please, solutions, projects, tools, scripts, docs. Can you give the link ? `htod` is 1. Any more ? dstep

Re: C++ or D?

2021-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 1 January 2021 at 18:00:57 UTC, SealabJaster wrote: Meanwhile I believe C++ (keep in mind I very rarely touch or look at C++) already has a standard allocator interface that parts of the STL (and I assume libraries, when/if they care) are able to use? I'm unaware of the issues it

Re: C++ or D?

2021-01-01 Thread SealabJaster via Digitalmars-d-learn
On Friday, 1 January 2021 at 16:45:16 UTC, Ola Fosheim Grøstad wrote: I don't know anything about any official positions other than the fact that Walter dislikes having more than one pointer type and is working on some kind of "liveness" verification for a C-style free/malloc regime, which is

Re: C++ or D?

2021-01-01 Thread Paulo Pinto via Digitalmars-d-learn
On Thursday, 31 December 2020 at 07:17:45 UTC, RSY wrote: On Wednesday, 30 December 2020 at 21:03:36 UTC, Paulo Pinto wrote: On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: [...] C++ you need to write duplicate code

Re: C++ or D?

2021-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 1 January 2021 at 16:23:45 UTC, SealabJaster wrote: Slightly off but also on topic but, has there been any general consensus yet around standard pointer types (e.g. shared_ptr) and standard allocator-aware data structures, or just in general any discussions around non-GC memory

Re: C++ or D?

2021-01-01 Thread SealabJaster via Digitalmars-d-learn
On Friday, 1 January 2021 at 15:12:43 UTC, Ola Fosheim Grøstad wrote: On Friday, 1 January 2021 at 15:01:15 UTC, RSY wrote: one big move would be to finally put the allocators out of std.experimental, and finally embrace this everywhere (just like ziglang) I am bit torn on this, the less the

Re: C++ or D?

2021-01-01 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Friday, 1 January 2021 at 15:01:15 UTC, RSY wrote: one big move would be to finally put the allocators out of std.experimental, and finally embrace this everywhere (just like ziglang) I am bit torn on this, the less the compiler knows about allocation strategies, the less opportunity

Re: C++ or D?

2021-01-01 Thread RSY via Digitalmars-d-learn
On Thursday, 31 December 2020 at 19:57:53 UTC, Ola Fosheim Grøstad wrote: On Thursday, 31 December 2020 at 19:27:23 UTC, Sebastiaan Koppe wrote: On Thursday, 31 December 2020 at 16:03:54 UTC, Ola Fosheim Grøstad wrote: What would you like to see? For shared to mean something. Stackless

Re: C++ or D?

2020-12-31 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 31 December 2020 at 19:27:23 UTC, Sebastiaan Koppe wrote: On Thursday, 31 December 2020 at 16:03:54 UTC, Ola Fosheim Grøstad wrote: What would you like to see? For shared to mean something. Stackless coroutines. Compile-time lifetime management, i.e. better ways to define

Re: C++ or D?

2020-12-31 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Thursday, 31 December 2020 at 16:03:54 UTC, Ola Fosheim Grøstad wrote: On Thursday, 31 December 2020 at 14:56:37 UTC, Sebastiaan Koppe wrote: It could take a few years indeed, but what will D do in that same time window? What would you like to see? For shared to mean something. Stackless

Re: C++ or D?

2020-12-31 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 31 December 2020 at 18:13:40 UTC, Imperatorn wrote: I was a bit unclear. I meant features as in built in language constructs etc, not necessarily like keywords and so on. You mean like associative arrays and dynamic arrays? If so then I guess people have different taste, I think

Re: C++ or D?

2020-12-31 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 31 December 2020 at 11:29:55 UTC, Ola Fosheim Grostad wrote: On Thursday, 31 December 2020 at 09:57:01 UTC, Imperatorn wrote: On Thursday, 31 December 2020 at 07:32:31 UTC, RSY wrote: nowhere. Just use D and be happy and let others use C++ and let them be happy. But they should be

Re: C++ or D?

2020-12-31 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 31 December 2020 at 14:56:37 UTC, Sebastiaan Koppe wrote: On Thursday, 31 December 2020 at 09:57:01 UTC, Imperatorn wrote: On Thursday, 31 December 2020 at 07:32:31 UTC, RSY wrote: [...] But they should be aware that C++ *as a language* has a long way to go before it gets all

Re: C++ or D?

2020-12-31 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Thursday, 31 December 2020 at 14:56:37 UTC, Sebastiaan Koppe wrote: It could take a few years indeed, but what will D do in that same time window? What would you like to see?

Re: C++ or D?

2020-12-31 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Thursday, 31 December 2020 at 09:57:01 UTC, Imperatorn wrote: On Thursday, 31 December 2020 at 07:32:31 UTC, RSY wrote: Sorry for the spam, but this is because of people like him that people like me (i discovered D recently) that can't be aware of why D is a great language They diminish

Re: C++ or D?

2020-12-31 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Thursday, 31 December 2020 at 09:57:01 UTC, Imperatorn wrote: On Thursday, 31 December 2020 at 07:32:31 UTC, RSY wrote: nowhere. Just use D and be happy and let others use C++ and let them be happy. But they should be aware that C++ *as a language* has a long way to go before it gets all

Re: C++ or D?

2020-12-31 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 31 December 2020 at 07:32:31 UTC, RSY wrote: Sorry for the spam, but this is because of people like him that people like me (i discovered D recently) that can't be aware of why D is a great language They diminish all arguments that makes D better than alternatives You guys

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grostad via Digitalmars-d-learn
On Thursday, 31 December 2020 at 07:17:45 UTC, RSY wrote: It's like the story with the GC You want everyone to like D because it has a GC despite it being not updated in ages, and proved to not scale well Fun fact: the c++ GC Oilpan ( used in Chrome ) has more features than the one in D...

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
Sorry for the spam, but this is because of people like him that people like me (i discovered D recently) that can't be aware of why D is a great language They diminish all arguments that makes D better than alternatives You guys have to help me fight that kind of behavior, because it

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
On Thursday, 31 December 2020 at 07:23:17 UTC, RSY wrote: C++ you need to write duplicate code (.h and .cpp) C++ you need to care about header include order C++ you need to forward declare everything you gonna use if it is not included before C++ you need to waste time waiting for compile

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
C++ you need to write duplicate code (.h and .cpp) C++ you need to care about header include order C++ you need to forward declare everything you gonna use if it is not included before C++ you need to waste time waiting for compile Fixed with C++20 modules. --- He said fixed with

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 21:03:36 UTC, Paulo Pinto wrote: On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: On Wednesday, 23 December 2020 at 18:03:56 UTC, frame wrote: It's not the problem mentioned but I had to

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
On Thursday, 31 December 2020 at 07:07:04 UTC, RSY wrote: On Wednesday, 30 December 2020 at 21:03:36 UTC, Paulo Pinto wrote: On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: On Wednesday, 23 December 2020 at 18:03:56 UTC,

Re: C++ or D?

2020-12-30 Thread RSY via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 21:03:36 UTC, Paulo Pinto wrote: On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: On Wednesday, 23 December 2020 at 18:03:56 UTC, frame wrote: It's not the problem mentioned but I had to

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 21:17:25 UTC, sighoya wrote: On Wednesday, 30 December 2020 at 21:12:43 UTC, Ola Fosheim Grøstad wrote: (which does not work, but maybe there is some other way to express it?): See: https://forum.dlang.org/thread/ooxzbrmbrzpsefiro...@forum.dlang.org?page=1

Re: C++ or D?

2020-12-30 Thread sighoya via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 21:12:43 UTC, Ola Fosheim Grøstad wrote: (which does not work, but maybe there is some other way to express it?): See: https://forum.dlang.org/thread/ooxzbrmbrzpsefiro...@forum.dlang.org?page=1

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 20:42:49 UTC, jmh530 wrote: You mean like this struct Foo(T) { T x; } void foo(T : Foo!V, V)(T x) { Not quite, "Foo" would be a template parameter, so something like this (which does not work, but maybe there is some other way to express it?):

Re: C++ or D?

2020-12-30 Thread Paulo Pinto via Digitalmars-d-learn
On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: On Wednesday, 23 December 2020 at 18:03:56 UTC, frame wrote: It's not the problem mentioned but I had to struggle with DLLs and D's Variant-type. The problem is that

Re: C++ or D?

2020-12-30 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 19:51:07 UTC, Ola Fosheim Grøstad wrote: [snip] Sort of, in C++ it would be something like this template class OuterName> void myfunction(OuterName x){ stuff(); } [snip] You mean like this struct Foo(T) { T x; } void foo(T : Foo!V, V)(T x) {

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 19:24:19 UTC, sighoya wrote: In my eyes, adding proper support for opImplicitCoercion enables the reuse of interfaces as typeclasses, yielding more potential for idiomatic development than utilizing C++ concepts alone. Not sure what you mean? A D interface

Re: C++ or D?

2020-12-30 Thread sighoya via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 18:45:03 UTC, Ola Fosheim Grøstad wrote: Some people in the D community has for a long time wanted stack-less coroutines. This is now available in C++20, and maybe D can borrow the C++ implementation for LDC? That is an interesting possibility for sure.

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 18:24:41 UTC, sighoya wrote: On Wednesday, 30 December 2020 at 14:41:28 UTC, Ola Fosheim Grøstad wrote: Most of the statements are wrong too... "4732 features, but not a single one you actually want": wrong again, C++20 has features that people would like to

Re: C++ or D?

2020-12-30 Thread sighoya via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 14:41:28 UTC, Ola Fosheim Grøstad wrote: Most of the statements are wrong too... "4732 features, but not a single one you actually want": wrong again, C++20 has features that people would like to see in D Could you elaborate a bit more, please? I'm

Re: C++ or D?

2020-12-30 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Wednesday, 30 December 2020 at 14:17:38 UTC, Rekel wrote: On Tuesday, 29 December 2020 at 16:13:50 UTC, Imperatorn wrote: https://ibb.co/syQRs9v I hope I'm not the only one that thinks 'designers and std lib writers unable to name anything correctly' is kind of ironic. And don't get me

Re: C++ or D?

2020-12-30 Thread Rekel via Digitalmars-d-learn
On Tuesday, 29 December 2020 at 16:13:50 UTC, Imperatorn wrote: https://ibb.co/syQRs9v I hope I'm not the only one that thinks 'designers and std lib writers unable to name anything correctly' is kind of ironic. And don't get me started on documentation return values.

Re: C++ or D?

2020-12-29 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Hi all, my question would be about using D or not using D. Is the newest C++ iteration any good compared to D? [...] https://ibb.co/syQRs9v

Re: C++ or D?

2020-12-25 Thread sighoya via Digitalmars-d-learn
On Thursday, 24 December 2020 at 08:36:54 UTC, RSY wrote: You can use GC, you can disable it, you can use malloc, it suits all your need! Not to forget the availability of refcounted (shared) and unique ptr too in D.

Re: C++ or D?

2020-12-24 Thread RSY via Digitalmars-d-learn
On Wednesday, 23 December 2020 at 19:00:14 UTC, evilrat wrote: On Wednesday, 23 December 2020 at 18:03:56 UTC, frame wrote: It's not the problem mentioned but I had to struggle with DLLs and D's Variant-type. The problem is that Variant uses TypeInfo which does not pass DLL boundaries

Re: C++ or D?

2020-12-23 Thread evilrat via Digitalmars-d-learn
On Wednesday, 23 December 2020 at 18:03:56 UTC, frame wrote: It's not the problem mentioned but I had to struggle with DLLs and D's Variant-type. The problem is that Variant uses TypeInfo which does not pass DLL boundaries correctly so that int != int in runtime even it's in fact a simple

Re: C++ or D?

2020-12-23 Thread frame via Digitalmars-d-learn
On Saturday, 19 December 2020 at 09:06:33 UTC, Godnyx wrote: Hi! Can you be more specific about the problems someone is gonna face with D that can't be fixed? This is very important for me because I'm planning to use D for development in the near (I wish near) future and I want to know what's

Re: C++ or D?

2020-12-19 Thread Godnyx via Digitalmars-d-learn
On Thursday, 12 November 2020 at 09:35:10 UTC, hgriffin wrote: C++ is a really overloaded with features language. The burden of backward compatibility and source compatibility with C doesn't make it any better. But right now it's the only right choice for development. There are plenty of

Re: C++ or D?

2020-11-12 Thread hgriffin via Digitalmars-d-learn
C++ is a really overloaded with features language. The burden of backward compatibility and source compatibility with C doesn't make it any better. But right now it's the only right choice for development. There are plenty of libraries for many common tasks, a big community and the most

Re: C++ or D?

2020-11-11 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: I haven't looked into the newest C++. In theory, they might have added something helpful in the past years. I guess you could say that the latest version of C++ allows you to write code that is a little bit less verbose than before.

Re: C++ or D?

2020-11-09 Thread realhet via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Hi all, my question would be about using D or not using D. Here are some things you will NOT get in D: youtube -> Dconf 2014 Day 2 Keynote: The Last Thing D Needs -- Scott Meyers For example, you will not get neurosis from it, or

Re: C++ or D?

2020-11-09 Thread Guillaume Piolat via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Hi all, Anyone have any thoughts how C++ and D compare? C++ has a bit more mathematical feeling, everything has been sorted out in the spec, even if the rules are crazy difficult. D feels like it's up to _you_ to write the spec as

Re: C++ or D?

2020-11-09 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Nov 10, 2020 at 01:00:50AM +, Mark via Digitalmars-d-learn wrote: [...] > my question would be about using D or not using D. Is the newest C++ > iteration any good compared to D? [...] > I haven't looked into the newest C++. In theory, they might have added > something helpful in the

Re: C++ or D?

2020-11-09 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 10 November 2020 at 01:00:50 UTC, Mark wrote: Anyone have any thoughts how C++ and D compare? Broadly speaking: D has a better core language, and C++ has a much better library and tooling ecosystem.

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Jacob Carlborg via Digitalmars-d-learn
On 2019-09-06 11:14, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) {     a = _a;     b = _b;     c = _c;     d = _d; } float 

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Maximillian via Digitalmars-d-learn
On Saturday, 7 September 2019 at 11:22:09 UTC, Maximillian wrote: Please could you tell what "goto case;" do here? I see now "fall-through" [1]. To be honest I like this feature in C and I was sad it didn't work in D, at least now I know how to solve it. :) Max. [1]

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Maximillian via Digitalmars-d-learn
On Friday, 6 September 2019 at 18:31:29 UTC, Ali Çehreli wrote: ... void enforceMemberWiseEquality(Demo d, const(float)[] values) { switch (values.length) { case 4: assert(d.d == values[3]); goto case; case 3: assert(d.c == values[2]); goto case;

Re: C++ vs D: Default param values and struct to array casting

2019-09-07 Thread Andrew Edwards via Digitalmars-d-learn
On Friday, 6 September 2019 at 18:31:29 UTC, Ali Çehreli wrote: On 09/06/2019 02:14 AM, Andrew Edwards wrote: > I'm seeking some pointers on how to define these in D Here is my attempt: Ali, this is awesome. It solves all 4 problems in on shot. I definitely don't intend on using the

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 September 2019 at 18:39:47 UTC, Andrew Edwards wrote: also probably u can do https://run.dlang.io/is/WMQE93 Ended up using this since it provides for named access and solves the overloading requirement. Thanks, Andrew You can also use std.typecons.Tuple for this, since it

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Andrew Edwards via Digitalmars-d-learn
On Friday, 6 September 2019 at 11:35:59 UTC, a11e99z wrote: https://dlang.org/spec/simd.html This didn't work two well because I wont be able to access the members by name as C++ library expects. Will consider during refactoring. also probably u can do https://run.dlang.io/is/WMQE93

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Ali Çehreli via Digitalmars-d-learn
On 09/06/2019 02:14 AM, Andrew Edwards wrote: > I'm seeking some pointers on how to define these in D Here is my attempt: struct Demo { // NOTE: The types and number of elements can be templatized and mixed-in like // mixin (makeMembers!T(N)); float a = 0; float b = 0; float c =

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Paul Backus via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:28:57 UTC, Andrew Edwards wrote: This is my thought on how to accomplish op overloading: struct Test { float a, b, c, d; float opIndex(size_t i) in(i >= 0 && i <= 3) { final switch(i) { case 0: return a;

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread a11e99z via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) { a = _a; b = _b;

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Andrew Edwards via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:49:33 UTC, Johan Engelen wrote: On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Johan Engelen via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) { a = _a; b = _b;

Re: C++ vs D: Default param values and struct to array casting

2019-09-06 Thread Andrew Edwards via Digitalmars-d-learn
On Friday, 6 September 2019 at 09:14:31 UTC, Andrew Edwards wrote: C++ allows the for following: struct Demo { float a, b, c, d; Demo() { a = b = c = d = 0.0f; } Demo(float _a, float _b, float _c, float _d) { a = _a; b = _b;

Re: C++ to D - recursion with std.variant

2015-04-05 Thread thedeemon via Digitalmars-d-learn
On Friday, 3 April 2015 at 16:46:08 UTC, Dennis Ritchie wrote: Hi, Is it possible to write on D recursion using std.variant? Using Algebraic from std.variant and some additional templates: http://dpaste.dzfl.pl/65afd3a7ce52 (taken from this thread:

Re: C++ to D - recursion with std.variant

2015-04-05 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 5 April 2015 at 09:48:01 UTC, thedeemon wrote: On Friday, 3 April 2015 at 16:46:08 UTC, Dennis Ritchie wrote: Hi, Is it possible to write on D recursion using std.variant? Using Algebraic from std.variant and some additional templates: http://dpaste.dzfl.pl/65afd3a7ce52 (taken

Re: C++ to D

2015-04-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 17:51:40 UTC, John Colvin wrote: Don't really see the point. Here's a neat thing that's definitely cheating because although it stores the results in the type system, the arithmetic is done in constant-folding: struct Integer(int a){} template Value(T) {

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 13:59:10 UTC, Dennis Ritchie wrote: snip You can do this: import std.typetuple; //helper for staticReduce template Alias(alias a) { alias Alias = a; } // staticReduce should really be in std.typetuple, or // the soon to arrive std.meta package. template

Re: C++ to D

2015-04-01 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all that C++ style mess. Yes, CTFE in D really cool. Thanks. I need to implement arithmetic (addition / subtraction) only use the type

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 17:03:34 UTC, Dennis Ritchie wrote: On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all that C++ style mess. Yes, CTFE in D really cool. Thanks. I need

Re: C++ to D

2015-04-01 Thread John Colvin via Digitalmars-d-learn
On Wednesday, 1 April 2015 at 17:51:40 UTC, John Colvin wrote: On Wednesday, 1 April 2015 at 17:03:34 UTC, Dennis Ritchie wrote: On Wednesday, 1 April 2015 at 15:22:10 UTC, John Colvin wrote: Compile Time Function Evaluation (CTFE) is a very powerful tool to avoid having to enter in to all

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: int[] arr = { 7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8 }; Console.WriteLine(string.Join( , arr.OrderByDescending(x = arr.Count(y = y == x)).ThenBy(x = x))); // prints 1 1 1 1 1 3 3 3 3 3 5 5 5 5 8 8 8 2 2 7 7 0 One solution:

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
.schwartzSort!(x = tuple(-arr.count!(y = y == x), x)) But calling count for each item is not efficient (in both C# and D). If your array is largish, then you need a more efficient solution. Bye, bearophile

Re: C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 19:01:43 UTC, bearophile wrote: One solution: Thanks. On Wednesday, 25 March 2015 at 19:03:27 UTC, bearophile wrote: But calling count for each item is not efficient (in both C# and D). If your array is largish, then you need a more efficient solution. A

Re: C# to D

2015-03-25 Thread Ali Çehreli via Digitalmars-d-learn
On 03/25/2015 12:01 PM, bearophile wrote: bearophile Do you know the story about groupBy? I see it in the documentation but my git head does not have it: http://dlang.org/phobos/std_algorithm_iteration.html#.groupBy Ali

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ali Çehreli: Do you know the story about groupBy? It's a long messy story. Look for it with another name, like chunkBy or something like that. Bye, bearophile

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ivan Kazmenko: (1) For me, the name of the function is obscure. Something like sortBy would be a lot easier to find than schwartzSort. I've asked to change the name of that function for years. But Andrei Alexandrescu is a adamantly against changing that pet name he has chosen. This is

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:02:20 UTC, Ivan Kazmenko wrote: Will file an issue soon. Here it is: https://issues.dlang.org/show_bug.cgi?id=14340 And another one, a 2.067 regression: https://issues.dlang.org/show_bug.cgi?id=14341

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:09:53 UTC, bearophile wrote: Dennis Ritchie: A more effective solution for C ++: #include iostream #include vector #include range/v3/all.hpp int main() { using namespace ranges; auto rng = istreamint( std::cin ) | to_vector |

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:17:57 UTC, bearophile wrote: Ivan Kazmenko: (1) For me, the name of the function is obscure. Something like sortBy would be a lot easier to find than schwartzSort. I've asked to change the name of that function for years. But Andrei Alexandrescu is a

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 19:32:43 UTC, Dennis Ritchie wrote: On Wednesday, 25 March 2015 at 19:01:43 UTC, bearophile wrote: One solution: Thanks. On Wednesday, 25 March 2015 at 19:03:27 UTC, bearophile wrote: But calling count for each item is not efficient (in both C# and D). If your

Re: C# to D

2015-03-25 Thread Ivan Kazmenko via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:02:20 UTC, Ivan Kazmenko wrote: (2) The documentation says it is more efficient than the first version in the number of comparisons (verbose lambda with plain sort) [1], but I don't get how it is possible: unless we know than (not pred1(a,b)) and (not

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: A more effective solution for C ++: #include iostream #include vector #include range/v3/all.hpp int main() { using namespace ranges; auto rng = istreamint( std::cin ) | to_vector | action::sort | view::group_by( std::equal_toint() )

Re: C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 25 March 2015 at 20:09:53 UTC, bearophile wrote: This is still not very efficient (perhaps the last sorting has to be stable): void main() { import std.stdio, std.algorithm, std.typecons, std.array; [7, 5, 7, 3, 3, 5, 3, 3, 0, 3, 1, 1, 5, 1, 1, 1, 2, 2, 8, 5, 8, 8]

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Ivan Kazmenko: arr.map !(to !(string)) .join ( ) .writeln; I suggest to not put a space before the bang (!), because it's confusing for me. Also, arr.map !(to !(string)) is better written arr.map!text. But even better is to use the range formatting of writefln,

Re: C++ to D

2015-03-11 Thread Kagamin via Digitalmars-d-learn
A hash table? See http://dlang.org/hash-map.html

Re: C++ to D

2015-03-11 Thread Dennis Ritchie via Digitalmars-d-learn
On Wednesday, 11 March 2015 at 16:08:22 UTC, Kagamin wrote: A hash table? See http://dlang.org/hash-map.html That is, the input is a string and, depending on what word it contains, is called one of the three methods of the class that this line handles. And this happens in average

Re: C++ to D

2015-03-11 Thread FG via Digitalmars-d-learn
On 2015-03-11 at 18:27, Dennis Ritchie wrote: The same without classes in Lisp: [...] And your point was...? I take it, poor c++ is a hint. Don't compare apples to oranges.

Re: C++ to D

2015-03-11 Thread Dennis Ritchie via Digitalmars-d-learn
The same without classes in Lisp: (define (foo) (let ((foo1 (lambda (s) s)) (foo2 (lambda (s) (list-string (reverse (string-list s) (foo3 (lambda (s) (string-append s , s (lambda (in) (match in (first foo1) (second foo2) (third

  1   2   >