|
Boost Users : |
Subject: Re: [Boost-users] boost and std collisons in c++0x
From: Daniel Lidström (daniel.lidstrom_at_[hidden])
Date: 2009-02-05 02:22:51
Hello,
here is how I have solved this problem where I work: Create a header for
each class that you want to use, that exists in both boost and std::tr1. For
example, here's our local shared_ptr.h:
#if !defined(SHARED_PTR_H__20080527T1436)
#define SHARED_PTR_H__20080527T1436
#if defined(_MSC_VER) && _MSC_VER>=1500 && defined(_HAS_TR1)
// Visual Studio 2008 TR1 version
#include <memory>
namespace GFLUtils = std::tr1;
#else
// Boost version
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
namespace GFLUtils = boost;
#endif
#endif
If you also have to rely on VC6 (as we do) then you can't selectively import
parts from a namespace (using boost::shared_ptr doesn't work). But if you
only use more modern compiler, you can do this:
#if !defined(SHARED_PTR_H__20080527T1436)
#define SHARED_PTR_H__20080527T1436
#if defined(_MSC_VER) && _MSC_VER>=1500 && defined(_HAS_TR1)
// Visual Studio 2008 TR1 version
#include <memory>
namespace GFLUtils
{
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
}
#else
// Boost version
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
namespace GFLUtils
{
using boost::shared_ptr;
using boost::enable_shared_from_this;
}
#endif
#endif
Hope this helps!
Regards,
Daniel Lidström
Stockholm, Sweden
_____
From: Ein Held [mailto:held_ein_at_[hidden]]
Sent: Wednesday, February 04, 2009 1:23 PM
To: boost-users_at_[hidden]
Subject: [Boost-users] boost and std collisons in c++0x
Hello
I would like to know more about boost's general attitude towards c++0x and
the collisions of boost with std.
As of now, we move both, ::boost- and ::std-namesspace in the global
namespace via using xxx. This is exactly what we want - boost and the stl
are both such fundamental libraries that using an explicit namespace
specifier everytime we want to use content of these namespaces is not
accaptable. This would just blow the code and make it unreadable.
Once we move up to c++0x, we will not be able to keep this way of coding up.
::std::tr1 is merged into ::std and so the former tr1 classes will collide
with the boost ones if explicit namespace identifiers are missing.
I would like to stress the fact that code, perfectly fine to the boost
documentation, will fail to compiler most likely.
#include <iostream> //This one might include <array>
using namespace std;
#include <boost/array.hpp>
using namespace boost;
array<int,1> blub; //fail
Is there anything planned to prevent this happen?
Thank you
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net