I want to implement my_static_assert
that slightly differs from c++17 single-parametric static_assert
: if condition inside my_static_assert
is not known at compile time, it should pass.
The second my_static_assert
in the following example should pass but if I would use static_assert
it will fail.
#include <iostream>
int x, y;
constexpr int f1() { return 0; }
constexpr int f2() { return 0; }
int f3() { return x; }
int f4() { return y; }
constexpr int sum(int a, int b) { return a + b; }
int main() {
std::cin >> x >> y;
// it should fail
my_static_assert(sum(sum(f1(), f2()), sum(f1(), f1())) != 0);
// it should pass
my_static_assert(sum(sum(f1(), f2()), sum(f4(), sum(f3(), f1()))) != 0);
}
If you want to know why this question arised:
I am building expressions using leaf functions f1,f2,f3,f4 and operations on the expression nodes: sum,mul,div,sub. Leafs that are known at compile time contain value that is always 0.
I am trying to check that my expressions contain at least one element that is not known at compile time.