codekiddy
codekiddy

Reputation: 6137

Is there a preprocessor or something to control what headers visual studio includes?

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;
}

Upvotes: 0

Views: 141

Answers (3)

deebee
deebee

Reputation: 1747

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.

Upvotes: 1

Fraser
Fraser

Reputation: 78300

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>.

Upvotes: 4

David Heffernan
David Heffernan

Reputation: 612954

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.

Upvotes: 3

Related Questions