Including STL without littering global scope

Viewed 193

Is there a way to include STL without having things defined in the global scope like ::size_t? Implementation items like _security_init_cookie are fine with me, as their identifiers are reserved.

vcruntime.h is always included and this bothers me.

1 Answers

I think to do that it is not safe at all.

There are backwards compatibility needs to have things in global space. And if you change the signature of those global things there will be link time problems. The way to go is to leave the global space to language and library implementation and put your things into namespaces.

If you fork STL you'll have to maintain and synchronize with each release.

And vcruntime.h isn't from STL but something related to Windows.

You can use std::size_t however:

#include <cstddef>
std::size_t i = 0;

But ::size_t will be there anyway.

Related