Don't use allocator::rebind as it is not present on recent c++ standards

This commit is contained in:
Ion Gaztañaga
2021-04-21 00:39:43 +02:00
parent a5cc4f1eef
commit c0bfb40f55
3 changed files with 64 additions and 61 deletions

View File

@ -23,31 +23,11 @@
#include <cassert> //assert
#include <boost/move/detail/nsec_clock.hpp>
using boost::move_detail::cpu_timer;
using boost::move_detail::cpu_times;
using boost::move_detail::nanosecond_type;
namespace bc = boost::container;
typedef std::allocator<int> StdAllocator;
typedef bc::allocator<int, 2, bc::expand_bwd | bc::expand_fwd> AllocatorPlusV2Mask;
typedef bc::allocator<int, 2, bc::expand_fwd> AllocatorPlusV2;
typedef bc::allocator<int, 1> AllocatorPlusV1;
template<class Allocator> struct get_allocator_name;
template<> struct get_allocator_name<StdAllocator>
{ static const char *get() { return "StdAllocator"; } };
template<> struct get_allocator_name<AllocatorPlusV2Mask>
{ static const char *get() { return "AllocatorPlusV2Mask"; } };
template<> struct get_allocator_name<AllocatorPlusV2>
{ static const char *get() { return "AllocatorPlusV2"; } };
template<> struct get_allocator_name<AllocatorPlusV1>
{ static const char *get() { return "AllocatorPlusV1"; } };
//typedef int MyInt;
class MyInt
@ -89,6 +69,30 @@ struct has_trivial_destructor_after_move<MyInt>
} //namespace boost{
namespace bc = boost::container;
typedef std::allocator<MyInt> StdAllocator;
typedef bc::allocator<MyInt, 2, bc::expand_bwd | bc::expand_fwd> AllocatorPlusV2Mask;
typedef bc::allocator<MyInt, 2, bc::expand_fwd> AllocatorPlusV2;
typedef bc::allocator<MyInt, 1> AllocatorPlusV1;
template<class Allocator> struct get_allocator_name;
template<> struct get_allocator_name<StdAllocator>
{ static const char *get() { return "StdAllocator"; } };
template<> struct get_allocator_name<AllocatorPlusV2Mask>
{ static const char *get() { return "AllocatorPlusV2Mask"; } };
template<> struct get_allocator_name<AllocatorPlusV2>
{ static const char *get() { return "AllocatorPlusV2"; } };
template<> struct get_allocator_name<AllocatorPlusV1>
{ static const char *get() { return "AllocatorPlusV1"; } };
void print_header()
{
std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
@ -99,7 +103,7 @@ void print_header()
template<class Allocator>
void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
{
typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
typedef Allocator IntAllocator;
unsigned int numalloc = 0, numexpand = 0;
cpu_timer timer;

View File

@ -31,21 +31,6 @@ using boost::move_detail::nanosecond_type;
namespace bc = boost::container;
typedef std::allocator<int> StdAllocator;
typedef bc::allocator<int, 2> AllocatorPlusV2;
typedef bc::allocator<int, 1> AllocatorPlusV1;
template<class Allocator> struct get_allocator_name;
template<> struct get_allocator_name<StdAllocator>
{ static const char *get() { return "StdAllocator"; } };
template<> struct get_allocator_name<AllocatorPlusV2>
{ static const char *get() { return "AllocatorPlusV2"; } };
template<> struct get_allocator_name<AllocatorPlusV1>
{ static const char *get() { return "AllocatorPlusV1"; } };
class MyInt
{
std::size_t int_; //Use a type that will grow on 64 bit machines
@ -64,6 +49,21 @@ class MyInt
}
};
typedef std::allocator<MyInt> StdAllocator;
typedef bc::allocator<MyInt, 2> AllocatorPlusV2;
typedef bc::allocator<MyInt, 1> AllocatorPlusV1;
template<class Allocator> struct get_allocator_name;
template<> struct get_allocator_name<StdAllocator>
{ static const char *get() { return "StdAllocator"; } };
template<> struct get_allocator_name<AllocatorPlusV2>
{ static const char *get() { return "AllocatorPlusV2"; } };
template<> struct get_allocator_name<AllocatorPlusV1>
{ static const char *get() { return "AllocatorPlusV1"; } };
void print_header()
{
std::cout << "Allocator" << ";" << "Iterations" << ";" << "Size" << ";"
@ -73,7 +73,7 @@ void print_header()
template<class Allocator>
void vector_test_template(unsigned int num_iterations, unsigned int num_elements, bool csv_output)
{
typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
typedef Allocator IntAllocator;
unsigned int capacity = 0;
const std::size_t Step = 5;

View File

@ -34,11 +34,27 @@ using boost::move_detail::nanosecond_type;
namespace bc = boost::container;
typedef std::allocator<int> StdAllocator;
typedef bc::allocator<int, 1> AllocatorPlusV1;
typedef bc::allocator<int, 2> AllocatorPlusV2;
class MyInt
{
int int_;
public:
MyInt(int i = 0) : int_(i){}
MyInt(const MyInt &other)
: int_(other.int_)
{}
MyInt & operator=(const MyInt &other)
{
int_ = other.int_;
return *this;
}
};
typedef std::allocator<MyInt> StdAllocator;
typedef bc::allocator<MyInt, 1> AllocatorPlusV1;
typedef bc::allocator<MyInt, 2> AllocatorPlusV2;
typedef bc::adaptive_pool
< int
< MyInt
, bc::ADP_nodes_per_block
, 0//bc::ADP_max_free_blocks
, 2
@ -58,27 +74,10 @@ template<> struct get_allocator_name<AllocatorPlusV2>
template<> struct get_allocator_name<AdPool2PercentV2>
{ static const char *get() { return "AdPool2PercentV2"; } };
class MyInt
{
int int_;
public:
MyInt(int i = 0) : int_(i){}
MyInt(const MyInt &other)
: int_(other.int_)
{}
MyInt & operator=(const MyInt &other)
{
int_ = other.int_;
return *this;
}
};
template<class Allocator>
struct get_vector
{
typedef bc::vector
<MyInt, typename Allocator::template rebind<MyInt>::other> type;
typedef bc::vector<MyInt, Allocator> type;
static const char *vector_name()
{
return "vector<MyInt>";
@ -89,7 +88,7 @@ template<class Allocator>
struct get_stable_vector
{
typedef bc::stable_vector
<MyInt, typename Allocator::template rebind<MyInt>::other> type;
<MyInt, Allocator> type;
static const char *vector_name()
{
return "stable_vector<MyInt>";