Consider the following two pieces of code:
template <int X>
struct Foo
{
enum
{
x = X
};
};
vs
template <int X>
struct Foo
{
static constexpr int x = X;
};
(The former is a frequent pattern in a library I want to modernize to C++17.)
I have looked through many questions/answers on here covering the differences between the enum
vs static constexpr
variants, but with C++17 having changed the behavior of static constexpr
(by making such variables implicitly inline) many of them are outdated (example). It's not perfectly clear to me what the remaining differences are and if I am missing something important.
Is going from the first snippet above to the second a safe transformation? Or are there any potential breakages or changes in behavior affecting user code that I should be aware of?