For example Visual studio includes <utility>
even if you didn't explicitly type #include <utility>
Is there a preprocessor directive or some option to include only what is explicitly told by programer?.
Just an hypothetical example:
#include <vector>
int main()
{
std::vector<int> x;
std::move(x); // Did I ask for <utility> ? No I didn't
return 0;
}
Visual studio doesn't include <utility>
unless it's required by other included std headers.
In VS10, including only <vector>
pulls in another 74 headers directly and indirectly. The trail to <utility>
is:
<vector>
includes <memory>
which includes <xmemory>
which includes <xutility>
which includes <utility>
.
Clearly, for your compiler, when you include vector
, that header also includes something that includes utility
.
Visual Studio does not automatically include anything and so this is the only explanation for what you describe.
When you include <map>
, it internally uses std::pair
and so includes <utility>
. I'm guessing <vector>
too uses something in <utility>
if that was the only #include
you had.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.