Hacker News new | past | comments | ask | show | jobs | submit login

RAII strictly for preventing leaks of resources is the lone thing I miss in C.

Constant folding via constexpr in C++ is much much better than C.

Templates help write generic code that results in specialized machine code; it may be hyper optimized at the cost of binary size. They make it harder to write code that at runtime is a little more type generic (if that makes sense). You can't always afford those additional copies generated. Not that it's a bad thing; just an observation as I write both strictly C and C++ at my day job.

Stealing the below; string handling is significantly safer with std::string. I'm not sold on std::string_view.




You can control code generation for templates by putting only the generic data structures in the header, and all function bodies in an implementation file. Then you explicitly instantiate the template for the types you want it for in that implementation file, and declare those instantiations as forward references in the header.

It's not pretty, but it's not hard either, and gives you full control over how many instances there are around. When C++ is used in a heavily constrained environment, that can come in handy.


string_view is about expressiveness and design flexibility (vector<char> and char* can trivially convert) that safety.

That being said, string_view is arguably safer than passing around a char* and a length.


https://bugs.llvm.org/show_bug.cgi?id=34729

Literally had to write a psuedo borrow checker to stop it: https://youtu.be/80BZxujhY38?t=1095

So much work rather than admit the interface is bad and you should feel bad.

C++: "shoot yourself in the ~~foot~~ face."


Sooner or later, C++ is going to get a borrow checker anyways. I guess it's all going to be ok? :)

I'm not entirely sold on string_view or span yet. But I wasn't sold on tuples either and I use them a lot now.


The bug there is implicitly converting an r-value to a non owning reference. We wouldn't call the same semantics a bug with a 'char const*' to be fair. We would complain that string implicitly converts or reject the application code as buggy.

That being said, yes, string semantics are hard. Passing around copies of a string buffer (std::string) or calling to_string_view everywhere don't seem better.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: