I can imagine the following code:
template class X
{
public:
T container;
void foo()
{
if(is_vector(T))
contain
If you use constexpr if, you were doing it right. This C++17 code compiles:
#include
#include
#include
#include
template struct is_vector : public std::false_type {};
template
struct is_vector> : public std::true_type {};
template
class X
{
public:
T container;
void foo()
{
if constexpr(is_vector::value){
std::cout << "I am manipulating a vector" << std::endl;
// Can access container.push_back here without compilation error
}
else {
std::cout << "I am manipulating something else" << std::endl;
}
}
};
int main() {
X> abc;
abc.foo(); // outputs "I am manipulating a vector"
X> def;
def.foo(); // outputs "I am manipulating something else"
}