Replace boost::aligned_storage with alignas std::array
This commit is contained in:
parent
5aaec05429
commit
32ff87f7f6
@ -106,12 +106,24 @@ public:
|
||||
#if defined(_MSC_VER) /* && (_MSC_VER < 1900)
|
||||
* Regarding the note (below) it was initially
|
||||
* thought that this got fixed in VS2015 - but
|
||||
* in fact it's still faulty (JE - Feb 2021) */
|
||||
* in fact it's still faulty (JE - Feb 2021).
|
||||
* 2024-09-03 update: Faulty compile up to
|
||||
* VS2022 17.4. From there it compiles but does
|
||||
* not link with the exception of the arm64
|
||||
* platform. This quirk is actually a bug that
|
||||
* Microsoft seems to have failed to
|
||||
* acknowledge as such for years judging from
|
||||
* web search results about MSVC's std::map,
|
||||
* and have not even fixed correctly when they
|
||||
* tried.
|
||||
*/
|
||||
/* Use the older (heap based) mapping for early versions of MSVC.
|
||||
* In fact it might be safer to use this for all MSVC builds - as
|
||||
* our StackAllocator class depends on 'boost::aligned_storage'
|
||||
* which is known to be troublesome with Visual C++ :-
|
||||
* https://www.boost.org/doc/libs/1_65_0/libs/type_traits/doc/html/boost_typetraits/reference/aligned_storage.html
|
||||
* In fact it might be safer to use this for all MSVC builds. It
|
||||
* was thought that this was related to issues with
|
||||
* boost::aligned_storage, but actually it seems to be that there
|
||||
* are bugs in the std::map implementation of MSVC that are being
|
||||
* triggered, messing with the copy constructor of
|
||||
* PBD::StackAllocator.
|
||||
*/
|
||||
typedef std::map<uint32_t, uint32_t> TypeMapping;
|
||||
typedef std::map<DataType, TypeMapping> Mappings;
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef PBD_STACK_ALLOCATOR_H
|
||||
#define PBD_STACK_ALLOCATOR_H
|
||||
|
||||
#include <boost/type_traits/aligned_storage.hpp>
|
||||
#include <limits>
|
||||
|
||||
#include "pbd/libpbd_visibility.h"
|
||||
@ -61,22 +60,22 @@ public:
|
||||
};
|
||||
|
||||
StackAllocator ()
|
||||
: _ptr ((pointer)&_buf)
|
||||
: _ptr (_buf.data())
|
||||
{ }
|
||||
|
||||
StackAllocator (const StackAllocator&)
|
||||
: _ptr ((pointer)&_buf)
|
||||
: StackAllocator ()
|
||||
{ }
|
||||
|
||||
template <typename U, size_t other_capacity>
|
||||
StackAllocator (const StackAllocator<U, other_capacity>&)
|
||||
: _ptr ((pointer)&_buf)
|
||||
: StackAllocator ()
|
||||
{ }
|
||||
|
||||
/* inspired by http://howardhinnant.github.io/stack_alloc.h */
|
||||
pointer allocate (size_type n, void* hint = 0)
|
||||
{
|
||||
if ((pointer)&_buf + stack_capacity >= _ptr + n) {
|
||||
if (_buf.data() + stack_capacity >= _ptr + n) {
|
||||
DEBUG_STACK_ALLOC ("Allocate %ld item(s) of size %zu on the stack\n", n, sizeof (T));
|
||||
pointer rv = _ptr;
|
||||
_ptr += n;
|
||||
@ -108,12 +107,12 @@ public:
|
||||
|
||||
bool operator== (StackAllocator const& a) const
|
||||
{
|
||||
return &_buf == &a._buf;
|
||||
return _buf.data() == a._buf.data();
|
||||
}
|
||||
|
||||
bool operator!= (StackAllocator const& a) const
|
||||
{
|
||||
return &_buf != &a._buf;
|
||||
return _buf.data() != a._buf.data();
|
||||
}
|
||||
|
||||
template <class U>
|
||||
@ -147,12 +146,10 @@ private:
|
||||
|
||||
bool pointer_in_buffer (pointer const p)
|
||||
{
|
||||
return ((pointer const)&_buf <= p && p < (pointer const)&_buf + stack_capacity);
|
||||
return (_buf.data() <= p && p < _buf.data() + stack_capacity);
|
||||
}
|
||||
|
||||
typedef typename boost::aligned_storage<sizeof (T) * stack_capacity, 16>::type align_t;
|
||||
|
||||
align_t _buf;
|
||||
alignas(16) std::array<value_type, stack_capacity> _buf;
|
||||
pointer _ptr;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user