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? Lately I've been noticing people just having constexpr
variables in their functions (not even bothering to const
them actually), and I was wondering whether I'm a fool who's behind the times with my
int foo(int x)
{
enum : int { bar = 456 };
return x + bar;
}
So, my question is: Is there any benefit to using enum's within function bodies rather than constexpr variables?