assume we have const array:
const int g_Values[] = { ... };
how check that members grow monotonically at compile time, i.e. g_Values[i] < g_Values[i + 1]
in runtime this possible to check like this:
bool IsMonotonously()
{
int i = _countof(g_Values);
int m = MAXINT;
do
{
int v = g_Values[--i];
if (v >= m) return false;
m = v;
} while (i);
return true;
}
but how rewrite this with constexpr and if IsMonotonously() return false - generate compile time error.



This is impossible for an array that is just
const. You need to make itconstexprto be able to use it in a constexpr context.All you need to do in addition to this is to implement the function for checking the array as
constexpr: