5

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.

  • Can you give a little more detail? Are you trying to avoid using `std::` everywhere? FWIW, IMHO, it's not worth it to avoid typing 5 extra characters. – NathanOliver Jun 24 '20 at 01:57
  • @NathanOliver The opposite. I'd like to use `std::` everywhere. –  Jun 24 '20 at 01:57
  • Oh, so you want to get rid of the names the headers might put into the global space. Not sure what you can do there – NathanOliver Jun 24 '20 at 01:59
  • I'm hoping someone knows a magic macro I can define to leave implementation details strictly in the implementation and not accessible to the end-user. –  Jun 24 '20 at 02:01
  • I guess there is no such macro. But you can take a look at the source code of headers you include to be sure. – Evg Jun 24 '20 at 05:43
  • Use a different STL implementation? As MSVCs STL is now on GitHub, you can adapt it and provide such a mode with some ifdefs. I would be happy to activate that mode on my code – JVApen Jun 24 '20 at 06:25
  • @JVApen I'd accept that as an answer if someone proposed that on the github or forked and modified it themselvevs. –  Jun 24 '20 at 18:37
  • @superdeveloper There's definitely no "magic macro" for this. You could try putting the entire STL in another namespace like this : ```namespace global {#include }``` It doesn't work, but you get what I mean, maybe there's a simple way to do this. – Lucas Charbonnier Jul 02 '20 at 09:32

1 Answers1

0

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.

Manuel
  • 2,526
  • 1
  • 13
  • 17