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 3600486
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:30:04+00:00 2026-05-18T20:30:04+00:00

I am currently writing a C++ library which will be required to compile with

  • 0

I am currently writing a C++ library which will be required to compile with both GCC for linux and Sun CC for Solaris. In the interest of performance I am creating some classes which select different headers based on compiler; GCC with c++0x or TR1 or with niether and Sun CC RogueWave or STLPort. I’m sturggling to work out the best means of #ifdef’ing the typedefs, for example:

namespace project {

    #if defined(__GNUG__)
        #if defined(HAVE_CXXOX)
            #include <unorderd_map>
            typedef srd::unordered_map map;
        #elif defined(HAVE_TR1)
            #include <tr1/unordered_map>
            typedef std::tr1::unordered_map map;
        #else
            #include <map>
            typedef std::map map;
        #endif
    #elif defined(__SUNPROC_CC)
        #include <map>
        typedef std::map map;
    #endif

} //namespaces
  • 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-18T20:30:05+00:00Added an answer on May 18, 2026 at 8:30 pm

    This won’t work for two reasons:

    1. Headers must be included outside of the scope of namespace project { ... }. (If the header contains nothing but templates and inline functions, it might work anyway, but I wouldn’t count on it.)
    2. typedef doesn’t work on templates. There’s a workaround where you define an empty derived class.

    So perhaps something like this:

    #if defined(__GNUG__)
        #if defined(HAVE_CXXOX)
            #include <unordered_map>
            #define MAP std::unordered_map
        #elif defined(HAVE_TR1)
            #include <tr1/unordered_map>
            #define MAP std::tr1::unordered_map
        #else
            #include <map>
            #define MAP std::map
        #endif
    #elif defined(__SUNPROC_CC)
        #include <map>
        #define MAP std::map
    #endif
    
    namespace myproject {
        template <class K, class V>
        class map : public MAP<K, V> {};
    }
    
    #undef MAP
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a library where I wish to allow the user to be
First, sorry for my bad English. I'm writing a python script, which compares the
I am writing a Webkit app that imports data from an RSS feed and
I'm writing an add-in for Media Center (the version that comes with Windows 7)
I'm writing a kernel module that checks to see if the time is between
I'm writing a functional test for a legacy Python script so that I can
I use FlashDevelop as my code editor and the Flash CS4 IDE for publishing
I am fighting with CoreData again and i need your help :P I am
I am trying to create a 2D platformer (Mario-type) game and I am some
Operating system is MacOS X, specifically 10.5 (Leopard) on a PowerPC G4, but I

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.