Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 817371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:58:58+00:00 2026-05-15T01:58:58+00:00

What are the best practices for using autoconf in conjunction with shared_ptr and other

  • 0

What are the best practices for using autoconf in conjunction
with shared_ptr and other TR1/BOOST C++0x templates so as to maximize
portability and maintainability?

With autoconf I can determine whether shared_ptr is
available as std::tr1::shared_ptr and/or boost::shared_ptr. Given
that the same feature has two different names, I have the following
questions:

  1. In the code, how should shared_ptr be referenced?
  2. Should std::tr1::shared_ptr be preferred over boost::shared_ptr?

For the first, the code is currently using preprocessor conditionals
allowing non-qualified 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

Second, the code uses std::tr1:: over boost:: to minimize
dependencies on external libraries (even if the the libraries are
widely used).

Are these two solutions common? Are there better ones?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:58:59+00:00Added an answer on May 15, 2026 at 1:58 am

    One improvement to your example code, and an answer to your first question, is to use the “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));
    

    The main problem with this is the need to use the ::Type notation. It is purely because C++ currently has no way to have a typedef for a template. You can have a typedef for a template type instance, but it’s important here that we retain genericity.

    As for whether you should prefer TR1 to Boost, I’d say yes. Now that compilers are shipping with partial C++0x support, I’d say you should also test for std::shared_ptr and prefer that to either of the others.

    You might need a fourth typedef if there are compilers that have a shared_ptr that’s somewhere else. I don’t know of such a compiler, but some C++ code I maintain does something similar to what you’re asking about with the common slist extension to the Standard C++ Library, for singly-linked lists. Old g++ versions put it at global namespace, modern g++ puts it in the compiler-specific __gnu_cxx namespace, and we even found one that erroneously put it in std!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.