I\'m trying to get the following C++ code running:
#include
template class ConditionalData {
};
template
This is a common pattern, so there's actually a paper to add constexpr_if to C++. If that makes it in to future versions, it would allow you to keep your code pretty much as-is.
template class A {
public:
A() {
ConditionalData data;
constexpr_if (hasdata) {
//^^^^^^^^^^ instead of plain if
data.setData(3);
}
}
};
For now, you'll need to make do with one of the other answers.
Edit: This was added to C++17 and called if constexpr