vendredi 27 février 2015

how to force compile-time constants with namespaces

I am currently working on a microcontroller, which makes any memory usage very expensive and thus I want to reduce the footprint as much as I can. Since there are many configuration parameters defined as constants, I think there is some potential for optimization.


Basically, I need something like an enum for non-integral types. However the solution looks like, it must meet the following constraints:



  • compile-time constant, thus no memory footprint at all

  • can be hidden in namespaces (thus, #define is no option here)

  • no function-like access (thus, constexpr is no option here)

  • can be of any type (but type safe, thus reinterpret_cast is no option here)

  • no libraries other than C++11 used


Any ideas are welcome! :)


Aucun commentaire:

Enregistrer un commentaire