4 ms·
This sounds like the standard under which C is safe because I, personally, don’t make mistakes. If foo<string> is fine but foo<string_view> compiles successful
by amluto 3y ago
This sounds like the standard under which C is safe because I, personally, don’t make mistakes.
If foo<string> is fine but foo<string_view> compiles successfully, generates no warnings, but is nonetheless UB and accesses a dangling pointer that merely usually still contains the expected value, then the overall programming environment is not safe.
C++, as it exists today, makes it very very difficult to build a safe system while still using most of the features that make C++ worth using. Every other language I have as an example has an ecosystem in which one can pass values around such that the semantics are actually defined for any remotely reasonable program that can be executed. The GC and automated-reference-counted languages keep values alive (although Python does struggle to make it clear whether one has captured an immutable value or a remotely mutable reference). The languages that don’t really have references (e.g. bash) copy values as needed. Rust says “you have full control as to how you instantiate things, but you must prove to the compiler that you did it right, and I will steer you toward patterns that make this relatively painless.” C++ has none of this.
- kazinator 3y agoI have absolutely no idea what point you're trying to make. I clearly wrote "C++ is safe if you ignore most of its libraries and write everything from scratch [...] and [...] stick to using nothing but the safe primitives you have created". If you're using foo<string_view>, where string_view is the std::string_view one, then you're not ignoring an unsafe library feature. Regarding templates, you could at least bring up argument deduction. It's possible to end up with a string_view template parameter implicitly, without using foo<string_view> syntax.