Check out the source code: https://github.com/RyanJK5/rjk-duck
Check out the source code: https://github.com/RyanJK5/rjk-duck
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.
Those against IDEs, well they already voted against good tooling in first place.
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?
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.
```
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?
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.
Thanks for the blog post.
Maybe you were asking if it implements custom destructors? GC?
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>.
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.
[0]: https://github.com/compiler-explorer/compiler-explorer/pull/...
[1]: https://github.com/compiler-explorer/compiler-explorer/blob/...
Or you just used void* and went on with your life
rob74•8h ago
...but, as they say, beauty is in the eye of the beholder!
RyanJK5•8h ago
flossly•8h ago
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•8h ago
You can write pretty fast and reasonable code nowadays.
pjmlp•7h ago
Either directly on top of a runtime/compiler written in C++, or as indirect dependency on a C++ compiler toolchain.
ahartmetz•5h ago
bunderbunder•7h ago
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•7h ago
I had the same misunderstanding before I get to know CS. that was 30 years ago.
abcd_f•6h ago
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•6h ago
HelloNurse•5h ago
WhitneyLand•6h ago
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•3h ago