why not to use specialization?
#include <iostream>
template <bool is_constant>
struct A {};
template <>
struct A<true> {
constexpr operator int() const {
return 10;
}
};
int main()
{
A<true> a;
int i = 2 + a;
std::cout << i << "\n";
A<false> b;
// int ii = 2 + b; // compilation error
}
this is quite straight forward and cross-compiler approach...