On 11-06-2015 15:47, Anton Bachin wrote:
[snip]
B. make size a constexpr function
+1
I think you should look to the future and give pay-off to people using more modern C++. However you can macro-ize the constexpr keyword so that it is constexpr is supported or nothing if not.
BOOST_NO_CXX11_CONSTEXPR will do the check for you.
I’ve already done this, and I use it throughout enum.h. It’s not a problem to make a size() function constexpr only when supported, I am just not so comfortable throwing away size as an integral constant for non-C++11 users. Perhaps I can make size() a function and provide an alternative constant with an ugly name for those who might need it? Do people still use C++03? And, again, what is the rationale for size being a function?
It's more generic if you want to view the class as a container with size() and begin()/end(). Yes, people still used C++03, but I'm sure they can live with a non-constexpr size() that is every bit as fast at runtime as a constexpr one. -Thorsten