forked from boostorg/beast
Fixes and tidying for flat_buffer:
* Fix reserve() size calculation * Improved test coverage
This commit is contained in:
1 parent
477e5a6f98
commit
b367776c37
5 files changed
+225
-67
No files matched your search
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace boost {
|
||||
@@ -26,6 +27,8 @@ struct test_allocator_info
|
||||
std::size_t nmassign = 0;
|
||||
std::size_t ncpassign = 0;
|
||||
std::size_t nselect = 0;
|
||||
std::size_t max_size = (
|
||||
std::numeric_limits<std::size_t>::max)();
|
||||
|
||||
test_allocator_info()
|
||||
: id([]
|
||||
@@ -37,28 +40,55 @@ struct test_allocator_info
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
template<
|
||||
class T,
|
||||
bool Equal,
|
||||
bool Assign,
|
||||
bool Move,
|
||||
bool Swap,
|
||||
bool Select>
|
||||
class test_allocator;
|
||||
|
||||
template<class T, bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
template<
|
||||
class T,
|
||||
bool Equal,
|
||||
bool Assign,
|
||||
bool Move,
|
||||
bool Swap,
|
||||
bool Select>
|
||||
struct test_allocator_base
|
||||
{
|
||||
};
|
||||
|
||||
template<class T, bool Equal, bool Assign, bool Move, bool Swap>
|
||||
struct test_allocator_base<T, Equal, Assign, Move, Swap, true>
|
||||
// Select == true
|
||||
template<
|
||||
class T,
|
||||
bool Equal,
|
||||
bool Assign,
|
||||
bool Move,
|
||||
bool Swap>
|
||||
struct test_allocator_base<
|
||||
T, Equal, Assign, Move, Swap, true>
|
||||
{
|
||||
static
|
||||
test_allocator<T, Equal, Assign, Move, Swap, true>
|
||||
select_on_container_copy_construction(test_allocator<
|
||||
T, Equal, Assign, Move, Swap, true> const&)
|
||||
{
|
||||
return test_allocator<T, Equal, Assign, Move, Swap, true>{};
|
||||
return test_allocator<T,
|
||||
Equal, Assign, Move, Swap, true>{};
|
||||
}
|
||||
};
|
||||
|
||||
template<class T, bool Equal, bool Assign, bool Move, bool Swap, bool Select>
|
||||
class test_allocator : public test_allocator_base<
|
||||
template<
|
||||
class T,
|
||||
bool Equal,
|
||||
bool Assign,
|
||||
bool Move,
|
||||
bool Swap,
|
||||
bool Select>
|
||||
class test_allocator
|
||||
: public test_allocator_base<
|
||||
T, Equal, Assign, Move, Swap, Select>
|
||||
{
|
||||
std::shared_ptr<test_allocator_info> info_;
|
||||
@@ -85,7 +115,8 @@ public:
|
||||
};
|
||||
|
||||
test_allocator()
|
||||
: info_(std::make_shared<test_allocator_info>())
|
||||
: info_(std::make_shared<
|
||||
test_allocator_info>())
|
||||
{
|
||||
}
|
||||
|
||||
@@ -138,6 +169,18 @@ public:
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
max_size() const
|
||||
{
|
||||
return info_->max_size;
|
||||
}
|
||||
|
||||
void
|
||||
max_size(std::size_t n)
|
||||
{
|
||||
info_->max_size = n;
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(test_allocator const& other) const
|
||||
{
|
||||
@@ -156,13 +199,110 @@ public:
|
||||
return info_->id;
|
||||
}
|
||||
|
||||
test_allocator_info const*
|
||||
test_allocator_info*
|
||||
operator->() const
|
||||
{
|
||||
return info_.get();
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#if 0
|
||||
struct allocator_info
|
||||
{
|
||||
std::size_t const id;
|
||||
|
||||
allocator_info()
|
||||
: id([]
|
||||
{
|
||||
static std::atomic<std::size_t> sid(0);
|
||||
return ++sid;
|
||||
}())
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct allocator_defaults
|
||||
{
|
||||
static std::size_t constexpr max_size =
|
||||
(std::numeric_limits<std::size_t>::max)();
|
||||
};
|
||||
|
||||
template<
|
||||
class T,
|
||||
class Traits = allocator_defaults>
|
||||
struct allocator
|
||||
{
|
||||
public:
|
||||
using value_type = T;
|
||||
|
||||
#if 0
|
||||
template<class U>
|
||||
struct rebind
|
||||
{
|
||||
using other =
|
||||
test_allocator<U, Traits>;
|
||||
};
|
||||
#endif
|
||||
|
||||
allocator() = default;
|
||||
allocator(allocator&& t) = default;
|
||||
allocator(allocator const& u) = default;
|
||||
|
||||
template<
|
||||
class U,
|
||||
class = typename std::enable_if<
|
||||
! std::is_same<U, T>::value>::type>
|
||||
allocator(
|
||||
allocator<U, Traits> const& u) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
allocator&
|
||||
operator=(allocator&& u) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
allocator&
|
||||
operator=(allocator const& u) noexcept
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
value_type*
|
||||
allocate(std::size_t n)
|
||||
{
|
||||
return static_cast<value_type*>(
|
||||
::operator new(n * sizeof(value_type)));
|
||||
}
|
||||
|
||||
void
|
||||
deallocate(value_type* p, std::size_t) noexcept
|
||||
{
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
max_size() const
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
operator==(test_allocator const& other) const
|
||||
{
|
||||
return id() == other.id() || Equal;
|
||||
}
|
||||
|
||||
bool
|
||||
operator!=(test_allocator const& other) const
|
||||
{
|
||||
return ! this->operator==(other);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // test
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
Reference in new issue
Block a user