How to use autoconf with C ++ 0x functions

What are the best practices autoconfin combination with shared_ptrand other TR1 / BOOST C ++ 0x templates to maximize mobility and maintainability?

With autoconfI can determine if shared_ptr available as std::tr1::shared_ptrand / or boost::shared_ptr. Given that the same function has two different names, I have the following questions:

  • In the code, how should I refer to shared_ptr?
  • If std::tr1::shared_ptrpreferable boost::shared_ptr?

For the first code, preprocessor conventions are currently used allowing unqualified references to shared_ptr, a la

#if HAVE_STD_TR1_SHARED_PTR
using std::tr1::shared_ptr;
#elif HAVE_BOOST_SHARED_PTR
using boost::shared_ptr;
#else
#error "No definition for shared_ptr found"
#endif

-, std::tr1:: boost::, ( ).

? ?

+5
1

template typedef" idiom:

#if HAVE_STD_TR1_SHARED_PTR
    template <class T>
    struct SharedPtr {
        typedef std::tr1::shared_ptr<T> Type;
    };
#elif HAVE_BOOST_SHARED_PTR
    template <class T>
    struct SharedPtr {
        typedef boost::shared_ptr<T> Type;
    };
#else
#   error "No definition for shared_ptr found"
#endif

// Declare a shared_ptr using our wrapper classes, saving us from having to care
// where shared_ptr comes from:
SharedPtr<int>::Type my_shared_int(new int(42));

:: Type. , ++ typedef . typedef instance, .

TR1 Boost, "". , ++ 0x, , std:: shared_ptr .

typedef, shared_ptr, - . , ++, , - , , slist ++ . g++ , g++ __gnu_cxx , , std!

+3

All Articles