The following code fails to compile with the error no member named 'foo' in 'B'
despite that only being an issue within a context that should be discarded at compile time.
#include <type_traits>
struct A {
int foo() {
return 1;
}
};
struct B {
int bar() {
return 2;
}
};
static constexpr bool TEST = false;
using T = std::conditional_t<TEST, A, B>;
int main() {
T t{};
if constexpr (TEST) {
return t.foo();
} else {
return t.bar();
}
}
What can I do to enable code like this? If I were to replace the constexpr with preprocessor macros this would likely work just fine, no?