YesBox 1 day ago

I use C++ every day and this feels like an entirely different language and philosophy. I know this is the reality of C++, but I never go searching for it so when it pops up randomly my jaw drops a little.

  • UltraSane 5 hours ago

    I last used C++ in 1999 and modern C++ seems like a different language.

Leherenn 1 day ago

What's compilation time like when using it?

I see there's an issue in the tracker to get more accurate data, and since it's using an under dev feature in compilers, it's not going to be definitive, but any rough numbers?

  • RyanJK5 1 day ago

    I don't have any numbers, but it is pretty slow. You can try making some edits in Compiler Explorer to see for yourself (though that of course has some impact from network requests).

    One reason is that, like you said, the feature is still new. Additionally I made pretty liberal use of the std::ranges library in my implementation which has notoriously bad compile times. That could be an area to improve upon.

    Another may be a bit more structural. If you want to call myObj.foo() via reflection, you have to linearly search members_of(myObj) for the one named "foo", and then call that. Actual compilers I assume use some kind of hash table.

    The hand-waving solution is "put it in a PCH", but I am hoping to put some more effort into optimizing build time here in the future.

    • pjmlp 14 hours ago

      Or a module.

      Compiler Explorer is not good for measuring anything in general, because there is also the issue of containers being allocated for specific languages, and compiler toolchains, and how many people are using it on a given moment.

feverzsj 1 day ago

Reflections, especially static ones, are horrible for debugging.

  • RyanJK5 1 day ago

    This library tries its best to mitigate that, catching common errors and whatnot, but it can definitely still happen. C++ doesn't have full token injection yet, so it avoids some of the more common pitfalls, if incidentally.

    As an aside, you may want to check out Jai's approach. I believe everything you generate statically gets turned into a file by the compiler for debugging purposes, which it provides references to in the output.

  • pjmlp 1 day ago

    Depends pretty much on the language and IDE tooling being used.

    Those against IDEs, well they already voted against good tooling in first place.

  • limaoscarjuliet 1 day ago

    I get a heart attack whenever I have to view core file from a decently complicated C++ program. The amount of template-in-a-template-in-a-template...(and this continues for some time) is not so readable to me. Maybe it is just me.

rob74 1 day ago

The things people describe as "beautiful" never cease to amaze me...

...but, as they say, beauty is in the eye of the beholder!

  • RyanJK5 1 day ago

    Beauty in C++ may be most similar to lipstick on a pig, but we try our best.

    • flossly 1 day ago

      I admire you guy keep trying.

      I'm also glad I do not write C++ on the daily anymore: luckily my software does not need that kind of performance characteristics.

      • germandiago 1 day ago

        I still reach for C++ on the backend. Honestly, with all its warts, I like it overall.

        You can write pretty fast and reasonable code nowadays.

      • pjmlp 1 day ago

        Yet I imagine your software depends on C++.

        Either directly on top of a runtime/compiler written in C++, or as indirect dependency on a C++ compiler toolchain.

    • ahartmetz 1 day ago

      It's more like arranging pigs in beautiful patterns. If you don't look very closely, you don't see the pigs.

  • bunderbunder 1 day ago

    I don’t really like much about C++ anymore, but I still enjoy reading C++ articles and listening to C++ podcasts, and I would consider it beautiful. Oftentimes the things I dislike about it are also the beautiful things. The term “beautiful mess” seems appropriate.

    It’s a bit like a well-kept Victorian home. The amount of work, money, and dealing with discomfort that goes into maintaining one isn’t something I really want to experience for myself. But the amount of skill and craftsmanship that it takes to preserve one is still impressive, and I have to appreciate the respect for history and the care that goes into balancing it with modern concerns.

    And talking to people who do live the life is always a great learning experience.

    • tw1984 1 day ago

      > I would consider it beautiful

      I had the same misunderstanding before I get to know CS. that was 30 years ago.

    • abcd_f 1 day ago

      > I would consider it beautiful.

      If there's something that C++ actually lacks, that's the elegance, grace and beauty. The rest, it's all already there or will be there shortly :)

      • rob74 1 day ago

        The problem with that is best described by Antoine de Sain-Exupery's saying "perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." I guess the same goes for elegance and grace...

        • HelloNurse 1 day ago

          C++ is in the transitional phase where major bad things are being taken away very satisfactorily, usually by providing a simpler and more general replacement (for example, auto instead of long and pointless type declarations or modern initialization protecting against implicit conversions and surprise constructor overloads), but most progress of elegance and grace come from new features that enable something traditionally terrible or impossible (for example the gradual generalization of templates, culminating with concepts, the gradual extension of constexpr, consteval etc, and the new reflection).

          • krior 1 day ago

            Oh, have they finally started to remove features?

            • pjmlp 14 hours ago

              Yes, several even, C++98 or C++11 code will not compile in C++26 mode, depending if some of those feature were being used.

              Exception specifications, auto_ptr, C++11 GC, the way volatile works, uninitialised variables,...

      • connicpu 1 day ago

        I find C++ beautiful only when I come across simple, powerful things that use the minimal amount of advanced language features possible

      • bunderbunder 1 day ago

        Think of it like a rainforest ecosystem. Very complex and tangled, even fragile. But it’s the tangled fragile complexity that makes it interesting.

  • WhitneyLand 1 day ago

    I find it hard to see a language as beautiful that’s grown too complex for a single person to hold a complete mental model of.

    I used to think that was a personal limitation, until I saw an interview with Bjarne explaining that he used to understand all of it but at this point it’s too big, no one can anymore.

    • topspin 1 day ago

      C++ is certainly a leader among the least feasible, but it's far from alone.

    • pjmlp 14 hours ago

      Very few languages are like that, not even something like Scheme, Go or C, unless that person never used anything beyond version 1.0, and a single implementation.

  • torginus 13 hours ago

    Yes unfortunately, C++ has a long history of features that were supposed to be much more limited than how they ended up being used - but engineers ended up finding holes in these fences, and that's how we ended up with things like SFINAE and weird compile time code execution methods.

    People ended up getting celebrated for their cleverness and not horrified by the abuse of good taste, and many of these tricks appeared in core C++ libraries like Boost.

    So doing stuff like this is unfortunately just part of C++ culture, and allows you to emulate proper features that using a C++ standard that's at least a decade older.

semiinfinitely 23 hours ago

looks like the kind of thing that will compile for 60 seconds only to spew 10k lines of error message to your terminal because you got 1 character wrong

  • captainbland 22 hours ago

    And the error will inexplicably be for a different line

schaefer 1 day ago

in the first example:

```

10: rjk::duck<Container> c{std::vector<int>{1, 2, 3}};

11: c.size(); // 3

12:

13: c = std::string{"hello"};

```

Does the assignment on line 13 call the destrucor for the vector of ints created on line 10?

  • RyanJK5 1 day ago

    Yes. duck takes ownership of the vector by moving it into its internal storage.

    As a bonus, if you tried passing in an lvalue, it will reject the input unless you add the "copyable" trait, so it ends up mitigating some hidden copies.

    • schaefer 1 day ago

      Well, you’ve certainly convinced me to read your library.

      Thanks for the blog post.

      • RyanJK5 1 day ago

        No problem! Hope you enjoy :)

  • rycomb 1 day ago

    Is there another option? Or were you asking if it leaks memory?

    Maybe you were asking if it implements custom destructors? GC?

    • schaefer 1 day ago

      > Or were you asking if it leaks memory?

      yeah,

      If variable c where of type void* instead of duck<Container>, the assignment on line 13 would leak the memory used by the vector<int>.

gmueckl 1 day ago

An include with a HTTP URL is a scary abomination straight put of hell. Please tell me that this is a compiler explorer specialty (which would still be cursed, but in a cool way) and not a GCC feature (which would be an absolute nightmare).

semiinfinitely 21 hours ago

People writing incomprehensible slop like this is the reason why some other people felt they had to invent AI coding agents

semiinfinitely 21 hours ago

glad to see that in the yaer of our lord 2026 c++ is still slaying, wasting gigawatts of 18yo supple brain energy on useless shit like this

  • gumby 19 hours ago

    Why is type erasure useless?

  • jazzprogramming 13 hours ago

    4 comments to heap your scorn on someone's work and what you don't understand. And you say their work is useless.

    • semiinfinitely 5 hours ago

      my scorn is not for this person's work but for the abomination of a programming language that made it possible

nokeya 14 hours ago

This is awesome and horrendous at the same time.

usrnm 1 day ago

> If you’ve ever tried using type erasure for something more complicated than std::any or std::function, you’ve either written 100+ lines of easy-to-mess-up code or reached for a boilerplate-heavy library like Boost.TypeErasure or Folly.Poly

Or you just used void* and went on with your life

  • lionkor 1 day ago

    You mean "used void* and wrote lots and lots of linter suppression comments" because it's fundamentally amateurish to write C++ without at least clang-tidy, cppcheck, and a couple others.

semiinfinitely 1 day ago

this is the most disgusting programming language ever invented!

  • krater23 1 day ago

    I think that is perl, but I share what you mean, as more features they add, as uglyer it gets.

briandilley 1 day ago

are we still hand writing code?

  • waynecochran 1 day ago

    That is exactly what I was thinking. I was a seasoned C++ programmer and always loved reading articles like this. I can't imagine I will every write my own C++ code again -- or in any language. I now program with English specifications now and I am 10000% times more productive.

    • mkhalil 1 day ago

      Good for you!

      Some of us are professionals and like to understand our systems and how they work. I don't write assembly instructions by hand either, nor do I design CPUs much, but I want to - and likely need to - know how they work to make the best judgements.

      • waynecochran 1 day ago

        I think you misunderstand -- I am still reading the article.

    • krater23 1 day ago

      I could imagine that in near future when token prices are as high as they really are, programmers that can't imagine or remember how to write code anymore will clean our streets, drive our taxis and water our plants.

      • waynecochran 23 hours ago

        It will be easier than trying to learn to the new features of C++34.