无论如何要弄清楚没有直接包含哪些STL头文件? [英] Is there anyway to figure out what STL header file has not been included directly?
问题描述
我们的产品使用 C++ 作为编程语言.使用 C++ STL 的一个恼人的问题是我们忘记包含必要的头文件,因为该文件可能已经包含在其他一些 STL 头文件中,构建通过.例如,
Our product uses C++ as the programming language. One annoying issue of using C++ STL is that we forget to include the necessary header files, because the file may have been included in some other STL header, the build passes. For example,
在使用 Xcode 的 Mac 平台中,如果我使用 std::auto_ptr
不包含 memory.h
但包含 iostream.h
,构建会通过,但在Android平台上会失败.
In Mac platform using Xcode, if I use std::auto_ptr
without include memory.h
but include iostream.h
, the build will pass, but it will fail in Android platform.
但我不想将代码移动到 Android 以对每个代码更改提交进行构建检查.那么,有没有办法避免这个问题?
But I don't want move the code to Android for an build check for each code change commit. So, is there anyway to avoid that problem?
我知道最好的解决方案是不要忘记包含标题.但是开发人员会犯错.那么有没有什么工具可以帮助检查呢?
Edit 1: I know the best solution is to not forget the include the header. But developers make mistakes. So is there any tool to help check it?
接缝没有理想的解决方案,所以我将使用 vim 脚本在我的编辑器中检查它,解决方案类似于 https://github.com/vim-scripts/vim-cpp-auto-include/blob/master/ftplugin/cpp_auto_include.vim
Edit 2: Seams no ideal solution, so I will use vim script to check it in my editor,the solution is similar to https://github.com/vim-scripts/vim-cpp-auto-include/blob/master/ftplugin/cpp_auto_include.vim
推荐答案
我所知道的唯一工具......就是编译器本身.
The only tool I know of... is the compiler itself.
每当问题是可移植性时,我见过的最佳解决方案就是简单地为所有必需的环境安装自动构建/测试套件.然后,无论何时发出拉取请求,它都会在您的所有构建机器人上进行验证,如果您忘记了某些内容,您将收到警告.
Whenever the issue is portability, the best solution I have seen was to simply put on automated build/test suites for all required environments. Then, whenever a pull request is made it will be validated on all your build bots, and you will be warned if you forgot something.
这篇关于无论如何要弄清楚没有直接包含哪些STL头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!