<algorithm> includes <limits> or why is it compiled?

 #include <algorithm> int main() { std::numeric_limits<__int64>::min(); } 
  • 2
    Standard, I believe, does not prescribe, but does not prohibit. - D-side

1 answer 1

I will try to answer in more detail what has already been said in the commentary on the question.

Indeed, the Language Standard does not specify which header files may include others. At the same time, due to the vastness of the library, the presence of interconnections between the individual components, of course, cannot be avoided.

However, it is worth bearing in mind that every function, variable, etc. (in general, to any name) some header file (or even several) is associated. It is this header file that should be connected via #include in order to avoid the appearance of compilation errors when porting code to another compiler, or even a different version of the same compiler.

For example, the following code:

 #include <iostream> //#include <functional> int main() { std::function<void(void)> f; } 

compiled to clang , but not compiled to gcc . If you include <functional> explicitly, the code should be compiled in any compiler. In particular, it begins to gather in gcc .

  • This is especially the case with MSVC - hooked one header, got a whole heap, and then the fun begins, when you need to collect code under Linux / OS X ... - ixSci
  • @ixSci connect the necessary headers is not so difficult then. But more correctly, of course, do it immediately. More difficult, if suddenly it turns out important order of their connection. - αλεχολυτ