I'm developing a C++ library, there are two functions: func1
and func2
.
I want to generate an compile-time error if developer forgets to call func1
before calling func2
:
This will be OK:
func1();
func2(); // OK
But this would fail:
func2(); // ERROR, you forget to call func1()
Of course, it's very easy to generate a runtime error but I would like to generate a compile-time error.
I've tried as below but it's not working because I can't modify a constexpr
variable:
static constexpr bool b {false};
void func1() {
b = true; // ERROR!
}
typename<std::enable_if_t<b == true>* = nullptr>
void func2() {}
I'm not very good at metaprogramming. I want to know if it's possible to generate a compile-time error in this case.