diff options
Diffstat (limited to 'common/almalloc.h')
-rw-r--r-- | common/almalloc.h | 75 |
1 files changed, 6 insertions, 69 deletions
diff --git a/common/almalloc.h b/common/almalloc.h index a795fc3b..873473ca 100644 --- a/common/almalloc.h +++ b/common/almalloc.h @@ -117,7 +117,9 @@ constexpr T *to_address(T *p) noexcept template<typename T> constexpr auto to_address(const T &p) noexcept -{ return to_address(p.operator->()); } +{ + return ::al::to_address(p.operator->()); +} template<typename T, typename ...Args> @@ -125,71 +127,6 @@ constexpr T* construct_at(T *ptr, Args&& ...args) noexcept(std::is_nothrow_constructible<T, Args...>::value) { return ::new(static_cast<void*>(ptr)) T{std::forward<Args>(args)...}; } -/* At least VS 2015 complains that 'ptr' is unused when the given type's - * destructor is trivial (a no-op). So disable that warning for this call. - */ -DIAGNOSTIC_PUSH -msc_pragma(warning(disable : 4100)) -template<typename T> -constexpr std::enable_if_t<!std::is_array<T>::value> -destroy_at(T *ptr) noexcept(std::is_nothrow_destructible<T>::value) -{ ptr->~T(); } -DIAGNOSTIC_POP -template<typename T> -constexpr std::enable_if_t<std::is_array<T>::value> -destroy_at(T *ptr) noexcept(std::is_nothrow_destructible<std::remove_all_extents_t<T>>::value) -{ - for(auto &elem : *ptr) - al::destroy_at(std::addressof(elem)); -} - -template<typename T> -constexpr void destroy(T first, T end) noexcept(noexcept(al::destroy_at(std::addressof(*first)))) -{ - while(first != end) - { - al::destroy_at(std::addressof(*first)); - ++first; - } -} - -template<typename T, typename N> -constexpr std::enable_if_t<std::is_integral<N>::value,T> -destroy_n(T first, N count) noexcept(noexcept(al::destroy_at(std::addressof(*first)))) -{ - if(count != 0) - { - do { - al::destroy_at(std::addressof(*first)); - ++first; - } while(--count); - } - return first; -} - - -template<typename T, typename N> -inline std::enable_if_t<std::is_integral<N>::value, -T> uninitialized_default_construct_n(T first, N count) -{ - using ValueT = typename std::iterator_traits<T>::value_type; - T current{first}; - if(count != 0) - { - try { - do { - ::new(static_cast<void*>(std::addressof(*current))) ValueT; - ++current; - } while(--count); - } - catch(...) { - al::destroy(first, current); - throw; - } - } - return current; -} - /* Storage for flexible array data. This is trivially destructible if type T is * trivially destructible. @@ -209,7 +146,7 @@ struct FlexArrayStorage { } FlexArrayStorage(size_t size) : mSize{size} - { al::uninitialized_default_construct_n(mArray, mSize); } + { std::uninitialized_default_construct_n(mArray, mSize); } ~FlexArrayStorage() = default; FlexArrayStorage(const FlexArrayStorage&) = delete; @@ -231,8 +168,8 @@ struct FlexArrayStorage<T,alignment,false> { } FlexArrayStorage(size_t size) : mSize{size} - { al::uninitialized_default_construct_n(mArray, mSize); } - ~FlexArrayStorage() { al::destroy_n(mArray, mSize); } + { std::uninitialized_default_construct_n(mArray, mSize); } + ~FlexArrayStorage() { std::destroy_n(mArray, mSize); } FlexArrayStorage(const FlexArrayStorage&) = delete; FlexArrayStorage& operator=(const FlexArrayStorage&) = delete; |