Skip to content

Commit

Permalink
Simplify allocator use via core/allocator_access
Browse files Browse the repository at this point in the history
  • Loading branch information
glenfe committed May 26, 2020
1 parent c8028c9 commit 5cd3f92
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions include/boost/wave/util/flex_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class StoragePolicy
#include <boost/assert.hpp>
#include <boost/throw_exception.hpp>

#include <boost/core/allocator_access.hpp>
#include <boost/iterator/reverse_iterator.hpp>

#include <boost/wave/wave_config.hpp>
Expand Down Expand Up @@ -287,32 +288,6 @@ inline bool operator!=(const mallocator<T>&,
return false;
}

#if defined(BOOST_NO_CXX11_ALLOCATOR)
template<class A>
struct allocator_traits {
typedef typename A::value_type value_type;
typedef typename A::pointer pointer;
typedef typename A::const_pointer const_pointer;
typedef typename A::size_type size_type;
typedef typename A::reference reference;
typedef typename A::const_reference const_reference;

static pointer allocate( A& a, size_type n, const_pointer hint )
{
return a.allocate(n, hint);
}

static void deallocate( A& a, pointer p, size_type n )
{
a.deallocate(p, n);
}

static size_type max_size( A const& a ) { return a.max_size(); }
};
#else
using std::allocator_traits;
#endif

////////////////////////////////////////////////////////////////////////////////
// class template SimpleStringStorage
// Allocates memory with malloc
Expand All @@ -333,7 +308,7 @@ class SimpleStringStorage
};
static const Data emptyString_;

typedef typename allocator_traits<A>::size_type size_type;
typedef typename boost::allocator_size_type<A>::type size_type;

private:
Data* pData_;
Expand Down Expand Up @@ -546,12 +521,12 @@ SimpleStringStorage<E, A>::emptyString_ =
template <typename E, class A = std::allocator<E> >
class AllocatorStringStorage : public A
{
typedef typename allocator_traits<A>::size_type size_type;
typedef typename boost::allocator_size_type<A>::type size_type;
typedef typename SimpleStringStorage<E, A>::Data Data;

void* Alloc(size_type sz, const void* p = 0)
{
return allocator_traits<A>::allocate(*this, 1 + (sz - 1) / sizeof(E),
return boost::allocator_allocate(static_cast<A&>(*this), 1 + (sz - 1) / sizeof(E),
static_cast<const char*>(p));
}

Expand All @@ -565,7 +540,7 @@ class AllocatorStringStorage : public A

void Free(void* p, size_type sz)
{
allocator_traits<A>::deallocate(*this, static_cast<E*>(p), sz);
boost::allocator_deallocate(static_cast<A&>(*this), static_cast<E*>(p), sz);
}

Data* pData_;
Expand Down Expand Up @@ -668,7 +643,7 @@ class AllocatorStringStorage : public A
{ return size_type(end() - begin()); }

size_type max_size() const
{ return allocator_traits<A>::max_size(*this); }
{ return boost::allocator_max_size(static_cast<const A&>(*this)); }

size_type capacity() const
{ return size_type(pData_->pEndOfMem_ - pData_->buffer_); }
Expand Down Expand Up @@ -759,7 +734,7 @@ class VectorStringStorage : protected std::vector<E, A>
typedef typename base::iterator iterator;
typedef typename base::const_iterator const_iterator;
typedef A allocator_type;
typedef typename allocator_traits<A>::size_type size_type;
typedef typename boost::allocator_size_type<A>::type size_type;

VectorStringStorage(const VectorStringStorage& s) : base(s)
{ }
Expand Down Expand Up @@ -876,7 +851,7 @@ class SmallStringOpt
typedef value_type* iterator;
typedef const value_type* const_iterator;
typedef typename Storage::allocator_type allocator_type;
typedef typename allocator_traits<allocator_type>::size_type size_type;
typedef typename boost::allocator_size_type<allocator_type>::type size_type;

private:
enum { temp1 = threshold * sizeof(value_type) > sizeof(Storage)
Expand Down Expand Up @@ -1203,7 +1178,7 @@ class CowString
typedef typename Storage::iterator iterator;
typedef typename Storage::const_iterator const_iterator;
typedef typename Storage::allocator_type allocator_type;
typedef typename allocator_traits<allocator_type>::size_type size_type;
typedef typename boost::allocator_size_type<allocator_type>::type size_type;
typedef typename Storage::value_type& reference;

private:
Expand Down Expand Up @@ -1464,11 +1439,11 @@ class flex_string : private Storage
typedef typename traits_type::char_type value_type;
typedef A allocator_type;

typedef typename allocator_traits<A>::value_type& reference;
typedef typename allocator_traits<A>::value_type const& const_reference;
typedef typename allocator_traits<A>::pointer pointer;
typedef typename allocator_traits<A>::const_pointer const_pointer;
typedef typename allocator_traits<A>::size_type size_type;
typedef typename boost::allocator_value_type<A>::type& reference;
typedef typename boost::allocator_value_type<A>::type const& const_reference;
typedef typename boost::allocator_pointer<A>::type pointer;
typedef typename boost::allocator_const_pointer<A>::type const_pointer;
typedef typename boost::allocator_size_type<A>::type size_type;

typedef typename Storage::iterator iterator;
typedef typename Storage::const_iterator const_iterator;
Expand Down

0 comments on commit 5cd3f92

Please sign in to comment.