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 [here](https://

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))) ``` I'

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 reordering

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 [here](https://

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 b

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 [here](https://

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 [here](https://

C to D: please help translate this weird macro

2023-09-20 Thread Ki Rill via Digitalmars-d-learn
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 [here](https://github.com/rillki/nuklear-d/tree/nuklear-d-translation).

Re: ELIZA Chatbot Implementation From C to D Lang

2023-03-01 Thread ron77 via Digitalmars-d-learn
On Friday, 17 February 2023 at 17:03:34 UTC, ron77 wrote: Hello, I succeeded in converting an ELIZA code from C to D, and here are the results. although I'm sure there are better ways to code it or to convert it... ```d /* eliza.c * ys * original code by Weizenbaum, 1966 * this rend

Re: ELIZA Chatbot Implementation From C to D Lang

2023-02-18 Thread thebluepandabear via Digitalmars-d-learn
On Friday, 17 February 2023 at 17:03:34 UTC, ron77 wrote: Hello, I succeeded in converting an ELIZA code from C to D, and here are the results. although I'm sure there are better ways to code it or to convert it... this is nothing compared to chatgpt ;)

Re: ELIZA Chatbot Implementation From C to D Lang

2023-02-18 Thread user1234 via Digitalmars-d-learn
On Friday, 17 February 2023 at 17:03:34 UTC, ron77 wrote: Hello, I succeeded in converting an ELIZA code from C to D, and here are the results. although I'm sure there are better ways to code it or to convert it... [...] Among the things to do the first is to drop C-style strings, so

ELIZA Chatbot Implementation From C to D Lang

2023-02-17 Thread ron77 via Digitalmars-d-learn
Hello, I succeeded in converting an ELIZA code from C to D, and here are the results. although I'm sure there are better ways to code it or to convert it... ```d /* eliza.c * ys * original code by Weizenbaum, 1966 * this rendition based on Charles Hayden's Java implementation

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 https://code.dlang.org/pac

C to D convertor

2021-08-21 Thread Виталий Фадеев via Digitalmars-d-learn
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 ? Examples of what the wanted: // C typedef struct { uint32_t version; /* 0x5000 */ uin

Re: Why can't we transpile C++ to D?

2021-06-10 Thread evilrat via Digitalmars-d-learn
On Thursday, 10 June 2021 at 19:06:42 UTC, Tejas wrote: But how scalable will this be? We have to get real D code to enrich our ambiguously-defined-small ecosystem. It says bindings generator, but it has to convert the code keeping the semantic as close as possible. It does direct translat

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
em applies with translating C++ to D: https://scottmeyers.blogspot.com/2015/11/the-brick-wall-of-c-source-code.html Damn that preprocessor! :@

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
7;t need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right? I leave this here, it does converts C++ to D to some extent https://github

Re: Why can't we transpile C++ to D?

2021-06-10 Thread sighoya via Digitalmars-d-learn
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote: Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? See https://stackoverflow.com/questions/14589346/is-c-context-free-or-context-sensitive

Re: Why can't we transpile C++ to D?

2021-06-10 Thread evilrat via Digitalmars-d-learn
hings could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right? I leave this here, it does converts C++ to D to some extent https://github.com/Superbelko/ohmygentool

Re: Why can't we transpile C++ to D?

2021-06-10 Thread evilrat via Digitalmars-d-learn
On Thursday, 10 June 2021 at 15:57:44 UTC, Imperatorn wrote: On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote: Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc c

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Dukc via Digitalmars-d-learn
hings could get easier, like getting legacy code to use Dlang. It might not be worth it for C+17 and beyond, but older codebases could benefit significantly, right? This is article is about transpiling old C++ to newer C++, but the same problem applies with translating C++ to D: https://scottmeye

Re: Why can't we transpile C++ to D?

2021-06-10 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 10 June 2021 at 15:09:02 UTC, Tejas wrote: Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easie

Why can't we transpile C++ to D?

2021-06-10 Thread Tejas via Digitalmars-d-learn
Sorry, I'm rather ignorant when it comes to this, but why can't we use [pegged](https://github.com/PhilippeSigaud/Pegged) to transpile C++ code to D? Then we won't need a nogc compatible std library and so many other things could get easier, like getting legacy code to use Dlang. It might not b

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-26 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 21, 2018 at 11:16:44PM -0500, Nick Sabalausky (Abscissa) via Digitalmars-d-learn wrote: > Are there any tutorials or articles out there for "getting started > with converting a C++ codebase to D one module at a time?" Or at the > very least: tips, tricks, lessions learned, from those w

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-23 Thread Kagamin via Digitalmars-d-learn
ome before. AFAIK, visuald has a tool that just translated C++ to D https://github.com/dlang/visuald/tree/master/c2d

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-23 Thread biocyberman via Digitalmars-d-learn
our favorite regexp search-and-replace tool) alot. basically, before HDD crash i almost had a set of scripts that does 80-90 percents of work translating C to D with sed. ;-) then use editor with "jump to error line" support, and simply compile your code, fixing errors one by one. tip:

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 22, 2018 at 10:43:24AM +0200, ketmar via Digitalmars-d-learn wrote: > Nick Sabalausky (Abscissa) wrote: > > > Are there any tutorials or articles out there for "getting started > > with converting a C++ codebase to D one module at a time?" Or at the > > very least: tips, tricks, lessio

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread Timothee Cour via Digitalmars-d-learn
ode, up to the whole codebase. it is not > fun when compler spits 100500 errors, but when it finally stops... oh, joy! > > trick: use 'sed' (or your favorite regexp search-and-replace tool) alot. > basically, before HDD crash i almost had a set of scripts that does 80-90 &g

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-22 Thread ketmar via Digitalmars-d-learn
code, up to the whole codebase. it is not fun when compler spits 100500 errors, but when it finally stops... oh, joy! trick: use 'sed' (or your favorite regexp search-and-replace tool) alot. basically, before HDD crash i almost had a set of scripts that does 80-90 percents of work t

Re: Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-21 Thread Mike Franklin via Digitalmars-d-learn
On Thursday, 22 February 2018 at 04:16:44 UTC, Nick Sabalausky (Abscissa) wrote: Are there any tutorials or articles out there for "getting started with converting a C++ codebase to D one module at a time?" Or at the very least: tips, tricks, lessions learned, from those who have come before.

Tuts/Aritcles: Incrementasl C++-to-D conversion?

2018-02-21 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn
Are there any tutorials or articles out there for "getting started with converting a C++ codebase to D one module at a time?" Or at the very least: tips, tricks, lessions learned, from those who have come before.

Re: Tried C++ to D. Wrong result.

2017-11-28 Thread Dmitry via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 09:01:47 UTC, Temtaime wrote: https://pastebin.com/xJXPBh0n Converted it and it works as expected. What did you use for it? In future I'll be needed to convert some more C++ code. P.S. /And it works wrong, because uses unsafe pointer (ubyte *image). So, it takes

Re: Tried C++ to D. Wrong result.

2017-11-28 Thread Temtaime via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 06:46:18 UTC, Dmitry wrote: On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote: P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements: Fixed, thank you. https://pastebin.com/xJXPBh0n Converted

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote: P.S. I think you have an unnecessary 'ref' on the D version because a slice is already a reference to elements: Fixed, thank you.

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Ali Çehreli via Digitalmars-d-learn
On 11/27/2017 10:47 AM, Dmitry wrote: > On Monday, 27 November 2017 at 18:40:41 UTC, Ali Çehreli wrote: > >> So, it looks like the original code was accessing out of bounds and >> probably that's why you inserted the ((index + 3) < N) check in the D >> version because D was catching that error at

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 18:40:41 UTC, Ali Çehreli wrote: So, it looks like the original code was accessing out of bounds and probably that's why you inserted the ((index + 3) < N) check in the D version because D was catching that error at runtime. Yes, it is. Which of course would sk

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Ali Çehreli via Digitalmars-d-learn
On 11/27/2017 10:25 AM, Dmitry wrote: > On Monday, 27 November 2017 at 17:21:05 UTC, Dmitry wrote: >> It fixed a delay (you can see it on video I posted before), but result >> is same. > > It seems I found the problem. > > C++ version (line 93): > if (image[index + 3] != 0) > > I changed to > if (

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 17:21:05 UTC, Dmitry wrote: It fixed a delay (you can see it on video I posted before), but result is same. It seems I found the problem. C++ version (line 93): if (image[index + 3] != 0) I changed to if (image[index] != 0) and it works. I don't understand why

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 17:01:29 UTC, Adam D. Ruppe wrote: In the C++ version they are declared std::vector pending; std::vector pendingNext; Ah, indeed. I thought that pending.reserve(N); pendingNext.reserve(N); initializes them (last time I used C++ about 17 years ago...) I suspect

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:35:39 UTC, Stefan Koch wrote: First I'd make sure that what you get out of dlib load is the same as the c++ version gets. Just use standard debugging techniques. Yes, it's same. As you can see, the top-middle area of the result is same. I wrote a video of p

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:08:27 UTC, Dmitry wrote: https://pastebin.com/GzZQ7WHt The first thing that jumped out to me is this: size_t[] pending = new size_t[N]; size_t[] pendingNext = new size_t[N]; That's giving it N elements of zero, then you append to it later with

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:08:27 UTC, Dmitry wrote: I tried translate C++ programm to D, but result is different. original: https://github.com/urraka/alpha-bleeding/blob/master/src/alpha-bleeding.cpp result (with removed alpha): https://github.com/urraka/alpha-bleeding/blob/master/media/a

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
On Monday, 27 November 2017 at 14:14:12 UTC, rikki cattermole wrote: Did you confirm that the image was loaded originally correctly? Yes. This image was used: https://github.com/urraka/alpha-bleeding/blob/master/media/original.png

Re: Tried C++ to D. Wrong result.

2017-11-27 Thread rikki cattermole via Digitalmars-d-learn
Did you confirm that the image was loaded originally correctly?

Tried C++ to D. Wrong result.

2017-11-27 Thread Dmitry via Digitalmars-d-learn
I tried translate C++ programm to D, but result is different. original: https://github.com/urraka/alpha-bleeding/blob/master/src/alpha-bleeding.cpp result (with removed alpha): https://github.com/urraka/alpha-bleeding/blob/master/media/alpha-bleeding-opaque.png my: https://pastebin.com/GzZQ7WHt

Re: Interfacing C++ to D

2017-04-03 Thread ANtlord via Digitalmars-d-learn
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote: Funny thing: If I replace interface with abstract class, it works as it should. Also I noticed that removing inheritance in library and in application makes unexpected results. When I try to output field `field` I get incorrect rando

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 16:03:51 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: [...] Now I see. 'Using C++ Classes From D' crashes for me too. It also returns the wrong value from 'field' method. Sho

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 16:02:06 UTC, FreeSlave wrote: On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've

Re: Interfacing C++ to D

2017-04-02 Thread FreeSlave via Digitalmars-d-learn
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I

Re: Interfacing C++ to D

2017-04-02 Thread ANtlord via Digitalmars-d-learn
On Sunday, 2 April 2017 at 09:58:19 UTC, ANtlord wrote: On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I

Re: Interfacing C++ to D

2017-04-02 Thread ANtlord via Digitalmars-d-learn
On Saturday, 1 April 2017 at 16:39:28 UTC, FreeSlave wrote: This page has many examples. Which exactly do you try to run and how do you build it? Which compilers, OS? My bad. I've tested example under caption Using C++ Classes From D. I used several combinations of compilers, and no one works

Re: Interfacing C++ to D

2017-04-01 Thread FreeSlave via Digitalmars-d-learn
On Saturday, 1 April 2017 at 07:37:25 UTC, ANtlord wrote: Hello! Can somebody give a relevant example shows how to use C++ classes in D? I've used the exmaple from https://dlang.org/spec/cpp_interface.html but I get a segmentation fault as result of D application. My application shows "Progr

Interfacing C++ to D

2017-04-01 Thread ANtlord via Digitalmars-d-learn
Hello! Can somebody give a relevant example shows how to use C++ classes in D? I've used the exmaple from https://dlang.org/spec/cpp_interface.html but I get a segmentation fault as result of D application. My application shows "Program exited with code -11" Thanks.

Re: Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:46:54 UTC, Meta wrote: This is not really doable right now in D. You can forward the function calls to a and b easily enough, but you can't inherit from more than one class. Once the multiple alias this patch gets merged you will be able to do this in D. On Sunday,

Re: Classes. C++ to D

2015-05-03 Thread QAston via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote: Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string(

Re: Classes. C++ to D

2015-05-03 Thread Adam D. Ruppe via Digitalmars-d-learn
I'd make class A and class B into mixin templates instead. mixin template A { string a() { return "foo"; } } mixin template B { string b() { return "bar"; } } class C { mixin A; mixin B; } If you still need class A and class B, just make a class that mixes in the template for them

Re: Classes. C++ to D

2015-05-03 Thread Meta via Digitalmars-d-learn
On Sunday, 3 May 2015 at 17:35:42 UTC, Dennis Ritchie wrote: Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string(

Classes. C++ to D

2015-05-03 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, How can I rewrite this code to the D? - #include #include class A { public: std::string a() { return std::string("foo"); } }; class B { public: std::string b(){ return std::string("bar"); } }; class C : public A, public B {}; int main

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 from

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: http://forum.dlang.org/thread/yidovyrczgdiveq

C++ to D - recursion with std.variant

2015-04-03 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Is it possible to write on D recursion using std.variant? - #include #include struct Nil {}; auto nil = Nil{}; template struct Cons; template using List = boost::variant>>; template struct Cons { Cons(T val, List list) : head(val), tail(list) {} T head; L

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) { stati

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 tha

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 t

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 13:59:10 UTC, Dennis Ritchie wrote: 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 static

C++ to D

2015-04-01 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Please help rewrite this code to D: #include // Peano Arithmetic struct zero; template struct succ { }; template struct increment { using result = succ; }; template struct decrement; template struct decrement> { using result = T; }; template struct addition; temp

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, a

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 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 adaman

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 #include #include int main() { using namespace ranges; auto rng = istream( std::cin ) | to_vector | action::sort | view::group_by( st

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 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 irrat

Re: C# to D

2015-03-25 Thread bearophile via Digitalmars-d-learn
Dennis Ritchie: A more effective solution for C ++: #include #include #include int main() { using namespace ranges; auto rng = istream( std::cin ) | to_vector | action::sort | view::group_by( std::equal_to() ) | copy | action::stab

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 you

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 !pred1(a,

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 mo

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 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
.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 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 solutio

C# to D

2015-03-25 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Can you please tell how to rewrite this code to D? using System; using System.Linq; class Sort { static void Main() { 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.C

Re: moving from c++ to D is easy?

2015-03-12 Thread Namespace via Digitalmars-d-learn
On Thursday, 12 March 2015 at 21:41:07 UTC, Ali Çehreli wrote: On 03/12/2015 01:19 PM, Namespace wrote: > On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: >> On 03/12/2015 06:01 AM, ayush wrote: >> >> > Is D a lot like c++ ? >> >> I came to D from C++. I remember the following bein

Re: moving from c++ to D is easy?

2015-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 03/12/2015 01:19 PM, Namespace wrote: > On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: >> On 03/12/2015 06:01 AM, ayush wrote: >> >> > Is D a lot like c++ ? >> >> I came to D from C++. I remember the following being notable differences: >> >> - In D, classes have reference se

Re: moving from c++ to D is easy?

2015-03-12 Thread Namespace via Digitalmars-d-learn
On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: On 03/12/2015 06:01 AM, ayush wrote: > Is D a lot like c++ ? I came to D from C++. I remember the following being notable differences: - In D, classes have reference semantics. I quickly realized that this is not an issue becaus

Re: moving from c++ to D is easy?

2015-03-12 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 12 March 2015 at 18:57:51 UTC, Ali Çehreli wrote: If you are a mortal like myself, you may find out years later that you are still at the midway point. Happened to me several times when I was learning C++. :) О, yeah.

Re: moving from c++ to D is easy?

2015-03-12 Thread Ali Çehreli via Digitalmars-d-learn
On 03/12/2015 06:01 AM, ayush wrote: > Is D a lot like c++ ? I came to D from C++. I remember the following being notable differences: - In D, classes have reference semantics. I quickly realized that this is not an issue because so many of my C++ types were hand-reference-typified :p by this

Re: moving from c++ to D is easy?

2015-03-12 Thread Dennis Ritchie via Digitalmars-d-learn
On Thursday, 12 March 2015 at 14:47:22 UTC, ketmar wrote: there are alot of books on C++ 'cause C++ is insanely complicated and inconsistend. D design is *MUCH* better, so D doesn't need so many books teaching arcane art of programming. Well, in principle, can be started with a D, but persona

Re: moving from c++ to D is easy?

2015-03-12 Thread ketmar via Digitalmars-d-learn
On Thu, 12 Mar 2015 13:56:28 +, Dennis Ritchie wrote: > On Thursday, 12 March 2015 at 13:44:50 UTC, Daniel Kozák wrote: >> D is much easier to learn so I will start with it. And then you can try >> learn C++ if you still want and need it. > > Yes, but in D for beginners little literature, so

Re: moving from c++ to D is easy?

2015-03-12 Thread via Digitalmars-d-learn
On Thursday, 12 March 2015 at 13:56:29 UTC, Dennis Ritchie wrote: On Thursday, 12 March 2015 at 13:44:50 UTC, Daniel Kozák wrote: D is much easier to learn so I will start with it. And then you can try learn C++ if you still want and need it. Yes, but in D for beginners little literature, so

Re: moving from c++ to D is easy?

2015-03-12 Thread Daniel Kozák via Digitalmars-d-learn
On Thu, 12 Mar 2015 13:35:18 + ayush via Digitalmars-d-learn wrote: > On Thursday, 12 March 2015 at 13:13:40 UTC, Dennis Ritchie wrote: > > On Thursday, 12 March 2015 at 13:01:31 UTC, ayush wrote: > >> Is D a lot like c++? > > > > Enough. > > > >> So should i focus on one or learn both toget

  1   2   3   >