Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 619
alfC Avatar asked Oct 25 '17 21:10

alfC


1 Answers

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.

like image 82
Angew is no longer proud of SO Avatar answered Jan 01 '23 09:01

Angew is no longer proud of SO