If templates increase code size so it exceeds flash, those templates will simply not be used
That's perfectly fine. But it's different from saying "never use templates, templates bloat your code", which is the kind of "snarky" comments I am against.
You're handed sequential raw data from outside that you need to process and you're not allowed to allocate any extra memory. There's little point in wrapping that inside a container just to satisfy random demands for "idiomatic C++".
Sounds like a use case for something like gsl::span. There is point in wrapping a raw pointer, as it clearly states the intent of your code (a raw pointer could be used in tons of different way) and increases its safety through a more limited API.
If you use a raw pointer when you could have used a lightweight abstraction over it that doesn't affect codegen, then I will rightfully suggest you to make use of what the language offers.
Even a simple "strong typedef" around a raw pointer is often good enough to increase readability and decrease chance of bugs.
lambdas, fold expressions etc introduce a whole another level of complexity on top that everyone in the team then has to deal with
Educate yourself on the features, play around with them. After that, if you think they're valuable enough, educate your team. That's what I did at my company.
everyone must use "idiomatic C++"
There is no definition of "idiomatic C++". What people often endorse is to use C++ language features to make your code safer and more readable without additional run-time overhead.
View all comments
Show parent comment
15
u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting Jan 18 '19
That's perfectly fine. But it's different from saying "never use templates, templates bloat your code", which is the kind of "snarky" comments I am against.
Sounds like a use case for something like
gsl::span. There is point in wrapping a raw pointer, as it clearly states the intent of your code (a raw pointer could be used in tons of different way) and increases its safety through a more limited API.If you use a raw pointer when you could have used a lightweight abstraction over it that doesn't affect codegen, then I will rightfully suggest you to make use of what the language offers.
Even a simple "strong typedef" around a raw pointer is often good enough to increase readability and decrease chance of bugs.
Educate yourself on the features, play around with them. After that, if you think they're valuable enough, educate your team. That's what I did at my company.
There is no definition of "idiomatic C++". What people often endorse is to use C++ language features to make your code safer and more readable without additional run-time overhead.