3 ms·
very true. there is almost nothing in the c++ standard library that you cannot rewrite in standard c++. actually, i think nothing.
by zabzonk 4y ago
very true. there is almost nothing in the c++ standard library that you cannot rewrite in standard c++. actually, i think nothing.
- dxuh 4y agoAfaik it is just some (quite a few) type traits, like std::is_class and such that you could not write yourself without compiler intrinsics.
- tialaramex 4y agoIt's not nothing, there are numerous intrinsics needed, and also "hacks" where the standard library does something that's labelled UB if you did it in your code but is magically blessed OK when the stdlib does it. That preference to solve things in "the" library leads to other horrible problems though, where C++ ought to have a first class language feature, but instead WG21 has enshrined a workaround in the library which is probably better than if you'd made your own, but rather poor compared to a first class feature. Take the array. Rather than provide a good array type in the actual language, C++ offers std::array, a library class in the standard library. But this standard library class isn't available in "freestanding" C++ while the builtin C-style array is available. So you end up with awkward syntax and the core language loses flexibility. Likewise strings, in Rust the type of an arbitrary literal "Hacker News" is &'static str, a reference to an immutable view of this text which lives as long as necessary. In C++ the type of "Hacker News" is char*, a pointer to bytes. C++ 17 at last provided std::string_view which is the thing you actually wanted for about two decades, but the type of "Hacker News" isn't string_view it's still char*.
- zabzonk 4y agoi have no idea why you think the standard lib is less blessed than the language. > In C++ the type of "Hacker News" is char * Nope it is at least const char , and if you want to assign it to a variable it is: const char * const hn = "Hacker News"; jesus, the hn formatting with this is driving me mad
- tialaramex 4y agoHN thinks asterisks mean you want to emphasise text (these days using italics) so you should in most cases escape them with a backslash. Much of the C++ standard library (including for example std::array) is not available in freestanding C++. Should it be? Perhaps. But it isn't. In contrast to Rust's conscious decision to provide core, alloc and std as separate layers, in the C++ there's a rather ad hoc process to decide what's freestanding.
- lenkite 4y ago> C++ 17 at last provided std::string_view which is the thing you actually wanted for about two decades Err..string_view was available in Boost for quite a while actually - at-least for a decade as far as I remember, possibly more. There are so many missing features in Rust that are only available in crates even today: sane error handling for one/custom allocators for another, but god forbid if you criticise Rust on that basis. You will get downvoted to oblivion.
- tialaramex 4y agoI don't see how string literals end up in the same category as custom allocators. Maybe you write some very special code which rarely uses strings for anything but needs a lot of custom allocators, the vast majority of programmers, even C++ programmers are very much the opposite.
- IshKebab 4y agoIndeed but the hassle of using Boost and the hassle of using a Rust crate are a little different to put it mildly.