Live data from Hacker News

Show HN: Beautiful Type Erasure with C++26 Reflection

ryanjk5.github.io

21–30 of 64 posts

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#21
post #17

in the first example: ``` 10: rjk::duck c{std::vector {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?

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.

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

Thanks for the blog post.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#23
post #17

Earlier quoted context omitted.

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.

Well, you’ve certainly convinced me to read your library. Thanks for the blog post.

No problem! Hope you enjoy :)

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#24

are we still hand writing code?

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.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#25
post #18

Earlier quoted context omitted.

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…

> 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 :)

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

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#26
post #5
post #4

The things people describe as "beautiful" never cease to amaze me... ...but, as they say, beauty is in the eye of the beholder!

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

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

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#27
post #20
post #18

Earlier quoted context omitted.

> 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 :)

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

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

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#28

are we still hand writing code?

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.

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.

Re: Show HN: Beautiful Type Erasure with C++26 Reflection

#29

in the first example: ``` 10: rjk::duck c{std::vector {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?

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

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

Post reply on HN