Intriguing C ++ 20 Features for Embedded Developers

C is still the favorite programming language among embedded system developers, but there are enough of them among them who use C ++ in their practice.





Using the appropriate C ++ capabilities, you can write code that will not be inferior in its efficiency to the code of a similar application written in C, and in some cases it will be even more efficient, since it can be quite tedious for an ordinary programmer to implement some functionality in C, which is much easier to implement with additional C ++ features.





C ++ 20 is the seventh iteration of C ++, preceded by, for example, C ++ 17, C ++ 14, and C ++ 11. Each iteration added new functionality while also affecting a couple of features previously added. For example, the auto keyword in C ++ 14.





Approx. transl .:





C ++ 14 introduced new rules for the auto keyword . Previously, expressions auto a{1, 2, 3}, b{1};



were allowed and both variables were of type initializer_list<int>



. In C ++ 14 auto a{1, 2, 3};



results in a compilation error and auto b{1};



compiles successfully, but the type of the variable will be int



and not initializer_list<int>



. These rules do not apply to expressions auto a = {1, 2, 3}, b = {1};



in which the variables are still of type initializer_list<int>



.









C ++ 11 has undergone significant changes and is the most widely used version of the standard used in embedded systems, as embedded system developers do not always use the most up-to-date toolkit. Proven and reliable solutions are critical when developing a platform that can last for decades.





, ++20 . . , « ». , , , x < 20



, x.operator<=>(20) < 0



. , , <, <=, >= >, , . x == y



operator<=>(x, y) == 0



.





. .:





« » @Viistomin « spaceship ( ) C++20»









++20 , :





  • ;





  • ;





  • ;





  • .





- , . ++11 constexpr , . ++20 , . , try/catch. .





consteval constexpr , , , , #define, ++.





. , . (. .: ) .





. .:





, @PkXwmpgN «C++20. Coroutines» , stackoverflow.









++20 coroutine_traits coroutine_handle. «».   , .





++17, . , . Ada SPARK, , C++20 .





, . , . – (. .: ), . . , cppreference.com, :





#include <string>
#include <cstddef>
#include <concepts>
using namespace std::literals; 

//   "Hashable",  
//   'T' ,    'a'  'T',
//   std::hash{}(a)      std::size_t
template <typename T>
concept Hashable = requires(T a) {
    { std::hash{}(a) } -> std::convertible_to<std::size_t>;
};
 
struct meow {};
 
template <Hashable T>
void f(T); //    ++20
 
//       :
// template<typename T>
//    requires Hashable<T>
// void f(T); 
// 
// template <typename T>
// void f(T) requires Hashable<T>; 
 
int main() {
  f("abc"s); // OK, std::string  Hashable
  f(meow{}); // : meow   Hashable
}

      
      



++20, , , , .





#include . import export , - #include.





#include . , . , . , . , , , ++.





, , Java Ada . , , . . , , #include.





, #include . .









- Ada SPARK, C++20 C++ . C++20, , . , . , .





, C++20, , , ++20.








All Articles