We, software developers, are usually excited with the groundbreaking features that become available with new versions of our favourite programming language. I remember well, how crucial the ISO/IEC 14882:2011 standard was for C++ and how much attention it gained. Lambdas, auto type deduction, variadic templates, concurrency support, memory management and many more features, that greately improved the language and gave a lot of new toys for developers.
The funny thing is that by focusing on the big news, we tend to miss the little ones that can efficiently improve our work. That is why I coax you to take a deeper look, to familiarize yourself with the less popular functionalities that usually escape our attention. For encouragement, below are some interesting and not necessarily trendy features of the C++ language introduced in recent years.
How often did you see such a class forward?
namespace shape {
namespace rectangle {
namespace utils {
class Some_util;
}
}
}
Isn’t it better to just use simplified, nested namespaces introduced by C++17 standard?
namespace shape::rectangle::utils {
class Some_util;
}
Recently I implemented few simple structs, which required comparison. How boring would it be to define trivial comparison operators and repeat it few times for different structures? Fortunately, we don’t need to do it by hand anymore! Using C++20 three-way comparison operator and default comparisons serves well for such a purposes:
struct Point
{
unsigned int m_x;
unsigned int m_y;
friend auto operator<=>(const Point&, const Point&) = default;
};
Not only a programming language features, but also standard library enhancements are interesting. Let’s take an example of std::source_location
feature, which nicely replaces an old approach with __LINE__
and __FUNCTION__
preprocessor macros. We can use it since C++20.
I know very well, that most of us are not allowed use the latest standards/versions of programming languages in our daily work – this is especially valid for automotive development, where only mature programming languages and toolchains are used. Nevertheless, the time for upgrade will come sooner or later.
So – get interested in the new features of your favorite programming languages! Use them wisely to make life easier for yourself and others. At the same time, remember to keep common sense – good code doesn’t ned to use all the latest goodies 😉 It should, above all, work reliably and in accordance with the requirements.