Beautiful Type Erasure with C++26 Reflection

(ryanjk5.github.io)

38 points | by RyanJK5 1 hour ago

5 comments

  • Leherenn 7 minutes 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 hour ago
    Try it on Compiler Explorer: https://godbolt.org/z/91dj5jeGW

    Check out the source code: https://github.com/RyanJK5/rjk-duck

  • feverzsj 1 hour ago
    Reflections, especially static ones, are horrible for debugging.
    • pjmlp 11 minutes 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.

    • RyanJK5 1 hour 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.

  • rob74 1 hour ago
    The things people describe as "beautiful" never cease to amaze me...

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

    • bunderbunder 35 minutes 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 25 minutes ago
        > I would consider it beautiful

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

    • RyanJK5 1 hour ago
      Beauty in C++ may be most similar to lipstick on a pig, but we try our best.
      • flossly 1 hour 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.

        • pjmlp 10 minutes 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.

        • germandiago 1 hour 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.