How to avoid shared_ptr ambiguity? (stl vs boost)

Possible duplicate:
Why is' namespace std; considered bad practice in C ++?

I used stl shared_ptr many places in my code, and I used the following using statement somewhere that used shared_ptr :

 using namespace std::tr1; 

Now I need to use boost::bimap . Therefore, I must include the following header file in my code:

 #include <boost/bimap.hpp> 

As soon as I include the bimap header file, the shared_ptr type becomes ambiguous, and I have to change all uses of shared_ptr to std::tr1::shared_ptr . Since this makes my code ugly, I am looking for a way to avoid this ambiguity by not requiring a shared_ptr declaration everywhere with a full name. I thought to use typedef for std::tr1::shared_ptr , but maybe there are better ways. Any advice would be appreciated!

+4
source share
2 answers

just doesn't introduce it. avoid generic using namespace ...

+5
source

How about the following:

 using shared_ptr = std::tr1::shared_ptr; 

However, the correct answer would be to not use the using namespace ... operator or use it only to create namespace aliases.

By the way, do you know that std::tr1 is obselete, since C ++ 11 became standardized last year?

+4
source

All Articles