C++17 is definitely going in the right direction for most applications. But I have the feeling, that the compiler implementations cannot catch up with the modernization speed. We are using C++ for embedded devices and recognize a steady code bloat with every release since C++11 (especially with C++17) without using any of the new features (with gcc/clang). This is a trust-killer and actually the reason we stay on C++…
Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.
How to Adopt Modern C++17 into Your C++ Code [video]
21–30 of 124 posts
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#22Earlier quoted context omitted.
> 3. The std::optional example looked really clunky, relying on checking an exception. I see there are a bunch of nice operators and utility functions on std::optional that cover some use cases, like coalescing, but will we get something that allows for optional chaining? Nope. It must be understood that std::optional is not an Option type, its purpose is not to have a way to express "missing" items in a type-safe ma…
The purpose is exactly to express possibly missing return values, which is exactly why it is called "optional", rather than "pointer_type_semantics ". I also don't see why you would ever use it in the way you're describing. Even if you had template code, either you manipulate objects/references, or pointers. And worst case, you usually try to handle references, rather than trying to risk UB.
Operative word: type-safe. std::optional is not that.
> I also don't see why you would ever use it in the way you're describing.
I'm literally just describing the semantics of std::optional.
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#23Earlier quoted context omitted.
> 3. The std::optional example looked really clunky, relying on checking an exception. I see there are a bunch of nice operators and utility functions on std::optional that cover some use cases, like coalescing, but will we get something that allows for optional chaining? Nope. It must be understood that std::optional is not an Option type, its purpose is not to have a way to express "missing" items in a type-safe ma…
> ...its purpose is not to have a way to express "missing" items in a type-safe manner... Except that's exactly why you would take an `optional ` as a parameter. To avoid the ambiguity and possible bugs of taking an `int*`.
Except for the type-safe part which is the important bit (hence the emphasis on it), and which std::optional does not provide.
> To avoid the ambiguity and possible bugs of taking an `int*`.
The only ambiguity and possible bug (singular) you're avoiding using std::optional is the question of ownership. Because as emphasised in the original comment std::optional is no more type-safe than a raw pointer.
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#24C++17 is definitely going in the right direction for most applications. But I have the feeling, that the compiler implementations cannot catch up with the modernization speed. We are using C++ for embedded devices and recognize a steady code bloat with every release since C++11 (especially with C++17) without using any of the new features (with gcc/clang). This is a trust-killer and actually the reason we stay on C++…
Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.
Avoiding bloat and performance hits are trivial in comparison to structural and architectural benefits in the modern language.
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#25Re: How to Adopt Modern C++17 into Your C++ Code [video]
#26C++17 is definitely going in the right direction for most applications. But I have the feeling, that the compiler implementations cannot catch up with the modernization speed. We are using C++ for embedded devices and recognize a steady code bloat with every release since C++11 (especially with C++17) without using any of the new features (with gcc/clang). This is a trust-killer and actually the reason we stay on C++…
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#27Earlier quoted context omitted.
std::string_view is, as the name implies, a view into a std::string. If you own the actual string, use std::string — there is no other string for you to view. If somebody else owns it and you're working on the whole string `const std::string&` is probably your best bet — you're holding a reference to the string as a whole — but std::string_view also works and might make more sense in context. If you're working with a…
> If somebody else owns it and you're working on the whole string `const std::string&` is probably your best bet Actually string_view is more general. You can build one out of a string literal, a vector , some memory from a memmap call, and an unbounded list of other things. If an interface uses a `const std::string&` and you don't have one, you have to, implicitly or explicitly, copy the data into a `std::string` to…
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#28Great talk, but I still have a couple questions that I'm sure someone here can answer: 1. I didn't see what the smart pointer stuff had to do with C++17. Aren't these all available from C++11? Are these something new that I missed, or are they just comments on how to avoid bugs, based on Herb Sutter's personal experience? 2. Should I std::string_view everywhere I used to use std::string now? The examples given seemed…
Regarding 2., in general, if you have a function that takes a `const std::string&` as parameter, you can replace it by a `std::string_view`. If you have stuff like `constexpr const char* whatever = "blah blah blah";` you can also replace it by a `std::string_view`. If you have a `std::string` member in a class, then you must not replace it by a `std::string_view`.
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#29(also has download links)
Re: How to Adopt Modern C++17 into Your C++ Code [video]
#30Earlier quoted context omitted.
Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.
Probably because it is much safer, faster to develop and easier to maintain.
Now, I'm aware that you can restrict yourself to "almost C" in C++, but no one ever seems to be doing that. A litte str::string here, a tiny std::vector there, so exceptions are already in, so why not go all the way.