Re: [Boost-users] shared_ptr and Visual Studio 2008 Express SP1
Hello, John. Wednesday, November 5, 2008 at 7:37:00 PM you wrote: JM> Nothing unusual about that: you have two different shared_ptr's visible in JM> scope: boost::shared_ptr and std::tr1::shared_ptr. You need to decide which JM> you intend to use and either prefix all shared_ptr usages with the JM> appropriate qualifiers, or else just take care to only import the one JM> shared_ptr in the first place. I understand what I have two visible versions of shared_ptr. And in my code I exclude all "boost/shared_ptr.hpp" inclusions. But what I have to do with boost headers such as "date_time/gregorian/greg_month.hpp" which also include shared_ptrs? I understand, what 'using' is quite dangerous directive, but I use it only in implementation files and never in headers. It makes source code more shortly and readable. Just compare: std::tr1::bind(&std::tr1::shared_ptr<SomeType>::get, std::tr1::placeholders::_1, /* ... */); with bind(&shared_ptr<SomeType>::get, _1); :) In the first case code semantic hidden under fully-qualified names. -- Best Regards, Sergey mailto:ssadovnikov@egopolis.com
Sergey Sadovnikov
I understand, what 'using' is quite dangerous directive, but I use it only in implementation files and never in headers. It makes source code more shortly and readable.
...and ambiguous. [snip] If you really don't want to qualify the names each place they're used then try just adding "using std::tr1::shared_ptr;" after all these locations where you already do "using namespace *". If I recall correctly, the using declaration will override the names from the using directives thus disambiguating it. -Ryan
2008/11/6 Ryan Gallagher
If you really don't want to qualify the names each place they're used then try just adding "using std::tr1::shared_ptr;" after all these locations where you already do "using namespace *". If I recall correctly, the using declaration will override the names from the using directives thus disambiguating it.
Unfortunately using declaration won't override using directive. Roman Perepelitsa.
Roman Perepelitsa
2008/11/6 Ryan Gallagher
If you really don't want to qualify the names each place they're used then try just adding "using std::tr1::shared_ptr;" after all these locations where you already do "using namespace *". If I recall correctly, the using declaration will override the names from the using directives thus disambiguating it.
Unfortunately using declaration won't override using directive.
Actually, they do, but only when used at local scope. (At least according to MSVC 9.0 express.) My post was still wrong, but moving "using std::tr1::shared_ptr" to top of the offending functions would resolve it. Still not the approach I'd go with myself. -Ryan
Hello, Ryan.
Thursday, November 6, 2008 at 6:26:24 AM you wrote:
RG> Sergey Sadovnikov
I understand, what 'using' is quite dangerous directive, but I use it only in implementation files and never in headers. It makes source code more shortly and readable.
RG> ...and ambiguous. In some rarely cases like this. RG> [snip] RG> If you really don't want to qualify the names each place they're used then try RG> just adding "using std::tr1::shared_ptr;" after all these locations where you RG> already do "using namespace *". If I recall correctly, the using declaration RG> will override the names from the using directives thus disambiguating it. Unfortunately it doesn't help. I think it would be good idea to avoid such ambiguous on the library level. For example, in the boost/shared_ptr.hpp make following corrections: //... #ifdef _HAS_TR1 #include <memory> namespace boost { using std::tr1::shared_ptr; //... other usings } #else // rest of the shared_ptr.hpp #endif Because of, for example, boost::shared_ptr_cast does not work with std::tr1::shared_ptr. And I think there is not necessary to have two different implementations of 'shared_ptr', 'bind', 'function' and other in case when such implementation already shipped with compiler (such as VS 2008 SP1 and gcc 4.3.x and newer). -- Best Regards, Sergey mailto:ssadovnikov@egopolis.com
participants (3)
-
Roman Perepelitsa
-
Ryan Gallagher
-
Sergey Sadovnikov