The problem that took him 5 years to fix in C++, I solved in a minute with D
    matheus 
    matheus at gmail.com
       
    Thu Mar 10 02:01:01 UTC 2022
    
    
  
Hi,
Today someone sent me this video: 
https://www.youtube.com/embed/ABg4_EV5L3w
(C++ Weekly - Ep 313 - The `constexpr` Problem That Took Me 5 
Years To Fix!).
It's a 26 minute long video of a guy trying to generate a 
concatenated string during CT in C++.
I was flabbergasted by the problems this poor guy had in front of 
him for a thing that shouldn't seem so complex (In my opinion of 
course). And more yet that he has being struggling with this for 
5 years.
So I decided to try the same with D, it was 14 lines[1] of code 
written in less than a minute and it just worked on the first 
try. Then I looked the Assembly code:
.L.str:
         .asciz  "hello world, hello world, hello world, "
After that I even asked over the D IRC channel if it was just 
this? And a user confirmed that my string was being generated 
through CT as the Assembly indicated.
Again incredible. My first programming language was C, then in 
2000-ish I had my first contact with C++ and I just hated and 
went back to C and then while looking for alternatives I stumbled 
on D which I use till this day as a "super C".
But now after so many years I couldn't believe the C++ is still 
struggling even to this day with this type of thing.
I'd like to quote this comment from the video:
> meowsqueak:
> "Well done solving this puzzle, but I’m left in shock. The need 
> to employ a template, static constexpr variables, a lambda 
> function, and four utility functions just to compile-time 
> generate a static string in C++ is an embarrassment."[2]
And indeed it is an embarrassment. Well D may have it flaws but I 
always found it lot time better or less restrictive language 
compared to others, especially C++.
Finally I'd like to take this moment and thank for all the effort.
Matheus.
[1] - Here is the snippet I wrote: https://godbolt.org/z/MsT36Prx4
[2] - Youtube comment: 
https://www.youtube.com/watch?v=ABg4_EV5L3w&lc=Ugzb7kTLS8GNS9bK07F4AaABAg
PS: I'm a ESL, sorry for any English mistakes.
    
    
More information about the Digitalmars-d
mailing list