alfC
alfC

Reputation: 16272

How is is_standard_layout implemented?

In general one can implement typical type_traits using template techniques.

However I didn't imagine how std::is_standard_layout could be implemented in these terms. http://en.cppreference.com/w/cpp/types/is_standard_layout

When I checked the gcc standard library, I found that it is implemented in terms of __is_standard_layout(T) which I could not find defined anywhere else. Is this a compiler magic function?

Would it be possible to implement std::is_standard_layout explicitly?

For example one of the conditions is that it inherits from a single class. That seems to be impossible to determine at compile time.

Upvotes: 8

Views: 474

Answers (1)

No, std::is_standard_layout is not something you can implement without compiler intrinsics. As you've correctly pointed out, it needs more information than the C++ type system can express.

Upvotes: 7

Related Questions