Remix.run Logo
embeng4096 2 hours ago

Is there an example of the generic programming that you've found useful?

The extent of my experience has been being able to replace functions like convert_uint32_to_float and convert_uint32_to_int32 by using templates to something like convert_uint32<float>(input_value), and I didn't feel like I really got much value out of that.

My team has also been using CRTP for static polymorphism, but I also feel like I haven't gotten much more value out of having e.g. a Thread base class and a derived class from that that implements a task function versus just writing a task function and passing it xTaskCreate (FreeRTOS) or tx_thread_create (ThreadX).

Typed compile-time computation is nice, though, good point. constexpr and such versus untyped #define macros.

csb6 18 minutes ago | parent | next [-]

The generic algorithms that come with the C++ standard library are useful. Once you get used to using them you start to see that surprisingly often ad-hoc implementations of many of them get written repeatedly in most code. Since most of the algorithms work on plain arrays as well as more complex containers they are still useful in embedded environments.

slaymaker1907 an hour ago | parent | prev [-]

std::array can sometimes give you the best of both worlds for stack allocation in that you statically constrain the stack allocation size (no alloca) while guaranteeing that your buffers are large enough for your data. You can also do a lot of powerful things with constexpr that are just not possible with arrays. It is very convenient for maintaining static mappings from enums to some other values.