Work around VC11 which has broken rebind_traits

VC11 has only partial support for C++11 allocators. For example it has a
non-conforming rebind_alloc and rebind_traits in std::allocator_traits
because it does not support C++11 template aliases.
This commit is contained in:
Glen Fernandes
2014-02-04 23:36:04 -08:00
parent 540149f019
commit 6d73b4aa54
3 changed files with 167 additions and 53 deletions

View File

@ -12,7 +12,7 @@
#include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/as_pair.hpp>
#include <boost/type_traits/alignment_of.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <memory>
#endif
@ -45,20 +45,20 @@ namespace boost {
template<typename T_, typename A_, typename Y_>
friend class as_allocator;
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#if !defined(BOOST_NO_CXX11_ALLOCATOR) && \
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
typedef typename std::allocator_traits<A>::
template rebind_alloc<Y> YA;
typedef typename std::allocator_traits<A>::
template rebind_alloc<char> CA;
typedef typename std::allocator_traits<A>::
template rebind_traits<Y> YT;
typedef typename std::allocator_traits<A>::
template rebind_traits<char> CT;
#else
typedef typename A::
template rebind<Y>::other YA;
typedef typename A::
template rebind<char>::other CA;
typedef typename A::template rebind<Y>::other YA;
typedef typename A::template rebind<char>::other CA;
#endif
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<YA> YT;
typedef std::allocator_traits<CA> CT;
#endif
public:

View File

@ -74,16 +74,19 @@ namespace boost {
}
private:
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#if !defined(BOOST_NO_CXX11_ALLOCATOR) && \
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
typedef typename std::allocator_traits<A>::
template rebind_alloc<type> TA;
typedef typename std::allocator_traits<A>::
template rebind_traits<type> TT;
#else
typedef typename A::
template rebind<type>::other TA;
#endif
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
typedef std::allocator_traits<TA> TT;
#endif
void destroy(type*, std::size_t, boost::true_type) {
}

View File

@ -10,11 +10,42 @@
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <boost/smart_ptr/allocate_shared_array.hpp>
class type1 {
friend class std::allocator<type1>;
public:
static unsigned int instances;
static const type1 object;
protected:
explicit type1() {
instances++;
}
type1(const type1&) {
instances++;
}
~type1() {
instances--;
}
};
unsigned int type1::instances;
const type1 type1::object;
template<typename T>
class creator {
public:
typedef T value_type;
#if defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
template<typename U>
struct rebind {
typedef creator<U> other;
};
#endif
creator() {
}
@ -44,109 +75,189 @@ public:
}
};
class type {
friend class creator<type>;
class type2 {
friend class creator<type2>;
public:
static unsigned int instances;
static type object;
static const type2 object;
protected:
explicit type() {
explicit type2() {
instances++;
}
type(const type&) {
type2(const type2&) {
instances++;
}
~type() {
~type2() {
instances--;
}
};
unsigned int type::instances;
type type::object;
unsigned int type2::instances;
const type2 type2::object;
int main() {
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(creator<void>(), 3);
boost::shared_ptr<type1[]> a1 = boost::allocate_shared<type1[]>(std::allocator<void>(), 3);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(type::instances == 4);
BOOST_TEST(type1::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(creator<void>());
boost::shared_ptr<type1[3]> a1 = boost::allocate_shared<type1[3]>(std::allocator<void>());
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(type::instances == 4);
BOOST_TEST(type1::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(creator<void>(), 2);
boost::shared_ptr<type1[][2]> a1 = boost::allocate_shared<type1[][2]>(std::allocator<void>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 5);
BOOST_TEST(type1::instances == 5);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(creator<void>());
boost::shared_ptr<type1[2][2]> a1 = boost::allocate_shared<type1[2][2]>(std::allocator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 5);
BOOST_TEST(type1::instances == 5);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(creator<void>(), 3);
boost::shared_ptr<const type1[]> a1 = boost::allocate_shared<const type1[]>(std::allocator<void>(), 3);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
BOOST_TEST(type1::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(creator<void>());
boost::shared_ptr<const type1[3]> a1 = boost::allocate_shared<const type1[3]>(std::allocator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
BOOST_TEST(type1::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(creator<void>(), 2);
boost::shared_ptr<const type1[][2]> a1 = boost::allocate_shared<const type1[][2]>(std::allocator<void>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 5);
BOOST_TEST(type1::instances == 5);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
{
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(creator<void>());
boost::shared_ptr<const type1[2][2]> a1 = boost::allocate_shared<const type1[2][2]>(std::allocator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 5);
BOOST_TEST(type1::instances == 5);
a1.reset();
BOOST_TEST(type::instances == 1);
BOOST_TEST(type1::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<type2[]> a1 = boost::allocate_shared<type2[]>(creator<void>(), 3);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(type2::instances == 4);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<type2[3]> a1 = boost::allocate_shared<type2[3]>(creator<void>());
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(type2::instances == 4);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<type2[][2]> a1 = boost::allocate_shared<type2[][2]>(creator<void>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 5);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<type2[2][2]> a1 = boost::allocate_shared<type2[2][2]>(creator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 5);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<const type2[]> a1 = boost::allocate_shared<const type2[]>(creator<void>(), 3);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 4);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<const type2[3]> a1 = boost::allocate_shared<const type2[3]>(creator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 4);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<const type2[][2]> a1 = boost::allocate_shared<const type2[][2]>(creator<void>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 5);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
BOOST_TEST(type2::instances == 1);
{
boost::shared_ptr<const type2[2][2]> a1 = boost::allocate_shared<const type2[2][2]>(creator<void>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type2::instances == 5);
a1.reset();
BOOST_TEST(type2::instances == 1);
}
return boost::report_errors();