lundi 24 avril 2017

Which should I prefer for a constant within a function: constexpr const or enum?

I'm used to definition my constants with enum { my_const = 123; }, since in classes, using static constexpr requires some code outside of the class definition (see this question). But - what about in function bodies? I've been seeing people just have constexpr variables in their functions - not even bothering to const them, and I was wondering whether I'm a fool who's behind of the times with my enums.

So, my question is: Is there any benefit to using enum's within function bodies rather than constexpr variables?

Aucun commentaire:

Enregistrer un commentaire