Determine the lifetime of compilation files in C ++

I am trying to write some portable C ++ library code that will initially rely on Boost.Regex, and then move to TR1 when compilers support it, and eventually to the C ++ 0x specification after everything has been ported from std :: tr1 namespace to std. Here is some kind of pseudo code for what I would like to do with the preprocessor:

if( exists(regex) )    // check if I can #include <regex>
{
    #include <regex>    // per TR1
    if( is_namespace(std::tr1) )   // are we on TR1 or C++0x?
    {
        using std::tr1::regex;
    } else
    {
        using std::regex;
    }
} else    // fall-back to boost
{
    #include <boost/regex.hpp>
    using boost::regex;
}

Of course, all this should be in the preprocessor directives, but if I knew how to do this, I would not ask here. :)

+5
source share
3 answers

, . , , autoconf.

, #define, /, .

+10

. ++ , ++ , #include.

, - #ifdef. - :

#ifdef BOOST_BUILD
  #include "somebooststuff.h"
  using namespace boost;
#else
  #include "somestdstuff.h"
  using namespace std;
#endif

BOOST_BUILD - , make - .

+6

You can use the macro __cplusplusto find out which version of C ++ you are working with; in the next standard (C ++ 1x, C ++ 0x should not be ) it will have a value greater than 199711L

#if __cplusplus > 199711
    using std::regex;
#else
    using std::tr1::regex;
#endif
+3
source

All Articles