docasok733
docasok733

Reputation: 117

std::is_class is false on a reference class

How come std::is_class is false when I test it on a reference ?

int main() {
    struct foo_struct {
        int i1;
        int i2;
    };
    std::cout << std::boolalpha << std::is_class<foo_struct>::value << std::endl; // true
    std::cout << std::boolalpha << std::is_class<foo_struct&>::value << std::endl; // falae
}

Upvotes: 1

Views: 150

Answers (1)

songyuanyao
songyuanyao

Reputation: 172964

Reference types and class types are different types; reference types are not class types themselves.

As type classification:

The C++ type system consists of the following types:

I'm not sure about your intent, you might apply std::remove_reference on the type, it gives the type itself for non-reference type. So you can use it in templates for both reference or non-reference types.

std::cout << std::boolalpha << std::is_class<std::remove_reference_t<foo_struct>>::value << std::endl;  // true
std::cout << std::boolalpha << std::is_class<std::remove_reference_t<foo_struct&>>::value << std::endl; // true

LIVE

Upvotes: 5

Related Questions