Search code examples
c++visual-c++namespacesstlport

How to revert back to an original namespace once its name is modified?


I'm using a library called stlport, which redefines the std namespace like this:

# if defined (_STLP_REDEFINE_STD)
/*  We redefine "std" to "stlport", so that user code may use std:: transparently */
#   undef  std
#   define std STLPORT
# else

Because of this, where-ever in my code I try to use std::something, it gets substituted with _STLP::something.

If I comment out the #define std STLPORT line, my legacy project's code won't compile (it's stlport dependent).

If I don't comment out the line, the new library I'm trying to add won't compile because it uses std:: with a different set of allocators from what stlport uses. Type clashes.

I've tried #define STLPORT std in a line just before including the new library, but this #define just doesn't seem to work.

Is there a way to use the normal std once it gets redefined like this?


Solution

  • You have two different implementations of STL, one in the STLPORT and one in the standard library. Your old code needs STLPORT and your new code needs the standard library.

    Both new and old code use things like include <vector> but they need different include files named vector, and hence different -I compiler flags. You cannot compile them with the same compiler settings.

    If you don't need to exchange standard containers and other STL-related data between old and new code, you can compile old code with the STLPORT settings and the new code with the regular settings. Do not touch STLPORT includes, do not redefine std in your code. STLPORT is not meant to be used like that. It is intended as a drop-in replacement for the (parts of) the standard library. You select which one you use by choosing the right compiler flags, not by modifying your (or STLPORT) source.

    If you do need to exchange standard containers between old and new code, you are out of luck. Your only recourse is to modify the legacy code such that it conforms to the standard.