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