У меня есть 4 int-константы:
const int a1 = 1024;
const int a2 = 768;
const int b1 = 640;
const int b2 = 480;
, и я хочу статически проверить, что они имеют одинаковое соотношение.Для статической проверки я использую BOOST_STATIC_ASSERT
, но он не поддерживает выражения.
Я пробовал это:
BOOST_STATIC_ASSERT( 1e-5 > std::abs( (double)a1 / (double)a2 - (double)b1 / (double)b2 ) );
, но это приводит к следующим ошибкам компиляции:
error: floating-point literal cannot appear in a constant-expression
error: 'std::abs' cannot appear in a constant-expression
error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
error: a cast to a type other than an integral or enumeration type cannot appear in a constant-expression
error: a function call cannot appear in a constant-expression
error: template argument 1 is invalid
Как исправить вышеприведенную строку, чтобы компиляция прошла?
PS У меня нет доступа к функциям c ++ 0x и std :: static_assert, поэтому я использую static для boostутверждать.