Subject: Re: [boost] question about C++11 guidelines
Date: 2012-05-03 05:15:22
---- Message d'origine ----
>De : "Robert Ramey" <ramey_at_[hidden]>
>Ã : boost_at_[hidden]
>Objet : Re: [boost] question about C++11 guidelines
>Date : 03/05/2012 08:30:06 CEST
>Eric Niebler wrote:
> > Say I'm rewriting an existing Boost library and targeting C++11
> > users. I plan to ship C++03 and C++11 versions of my library
> > side-by-side, so back-compat isn't an issue for the new code. Is
> > there a reason to prefer using Boost's versions of utilities like
> > enable_if, type traits, integral constant wrappers (e.g. mpl::int_),
> > tuples, etc., over the now-standard ones?
> > I'm leaning toward using std:: where I can, and falling back on
> > Boost's versions only when there is a compelling reason.
> Isn't easier to just use the boost versions knowing that they
> will be implemented in the most efficient/appropriate way
> for the compiler in question?
From what I understood, std::make_shared is more efficiently implemented on
some platforms that boost::make_shared, so I would not assume that boost
version is better than the version provided by the compiler.
From a boost user point of view, I have another issue with boost
compatibility with C++11, that is not used by either proposal:
- If types such as boost::shared_ptr and boost::tuple are used in the
library boost.sampleLib, whenever I want to interface boost.sampleLib with
other code that was written without boost, and makes use of std::shared_ptr
or std::tuple, I have troubles, and need to convert/copy objects
- If types such as std::shared_ptr and std::tuple are used in the library
boost.sampleLib, whenever I want to interface boost.sampleLib with other
code that was written with boost, and makes use of boost::shared_ptr or
boost::tuple, I have troubles, and need to convert/copy objects
The more I think of it, the more I believe the right solution is not to have
two different types, but making sure that on a platform where
std::shared_ptr exists, boost::shared_ptr is defined as an alias to
std::shared_ptr, and just the same for all C++11 types that were first
developped with boost.
Frankly, I have been using boost on VC10 that contains std::shared_ptr for
quite some time now, and I can say it is quite a pain, there are many subtle
compilation problems that all come down to the fact that there are
duplicated types with the same name in the same program.
A(std::vector<int> const &v);
boost::shared_ptr<A> p1 = make_shared<A> (3); // Works
boost::shared_ptr<A> p1 = make_shared<A> (v); // Does not work, there is no
conversion from std::shared_ptr to boost::shared_ptr