diff options
Diffstat (limited to 'src/lib/netlist/plib/parray.h')
-rw-r--r-- | src/lib/netlist/plib/parray.h | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/netlist/plib/parray.h b/src/lib/netlist/plib/parray.h index 0d89a56195c..2c2b0fc4270 100644 --- a/src/lib/netlist/plib/parray.h +++ b/src/lib/netlist/plib/parray.h @@ -21,19 +21,20 @@ namespace plib { - template <typename FT, int SIZE> + template <typename FT, int SIZE, typename ARENA> struct sizeabs { - static constexpr std::size_t ABS() noexcept { return (SIZE < 0) ? static_cast<std::size_t>(0 - SIZE) : static_cast<std::size_t>(SIZE); } + static constexpr std::size_t ABS() noexcept { return (SIZE < 0) ? narrow_cast<std::size_t>(0 - SIZE) : narrow_cast<std::size_t>(SIZE); } using container = typename std::array<FT, ABS()> ; }; - template <typename FT> - struct sizeabs<FT, 0> + template <typename FT, typename ARENA> + struct sizeabs<FT, 0, ARENA> { static constexpr std::size_t ABS() noexcept { return 0; } + using allocator_type = typename ARENA::template allocator_type<FT, PALIGN_VECTOROPT>; //using container = typename std::vector<FT, arena_allocator<mempool, FT, 64>>; - using container = typename std::vector<FT, aligned_allocator<FT, PALIGN_VECTOROPT>>; + using container = typename std::vector<FT, allocator_type>; }; /// \brief Array with preallocated or dynamic allocation. @@ -51,17 +52,20 @@ namespace plib { /// I consider > 10% performance difference to be a use case. /// - template <typename FT, int SIZE> + template <typename FT, int SIZE, typename ARENA = aligned_arena> struct parray { public: - static constexpr std::size_t SIZEABS() noexcept { return sizeabs<FT, SIZE>::ABS(); } + static constexpr std::size_t SIZEABS() noexcept { return sizeabs<FT, SIZE, ARENA>::ABS(); } - using base_type = typename sizeabs<FT, SIZE>::container; + using base_type = typename sizeabs<FT, SIZE, ARENA>::container; using size_type = typename base_type::size_type; - using reference = typename base_type::reference; - using const_reference = typename base_type::const_reference; - using value_type = typename base_type::value_type; + using value_type = FT; + using reference = FT &; + using const_reference = const FT &; + + using pointer = FT *; + using const_pointer = const FT *; template <int X = SIZE > parray(size_type size, std::enable_if_t<(X==0), int> = 0) @@ -70,7 +74,7 @@ namespace plib { } template <int X = SIZE > - parray(size_type size, FT val, std::enable_if_t<(X==0), int> = 0) + parray(size_type size, const FT &val, std::enable_if_t<(X==0), int> = 0) : m_a(size, val), m_size(size) { } @@ -85,7 +89,7 @@ namespace plib { } template <int X = SIZE > - parray(size_type size, FT val, std::enable_if_t<(X != 0), int> = 0) noexcept(false) + parray(size_type size, const FT &val, std::enable_if_t<(X != 0), int> = 0) noexcept(false) : m_size(size) { if ((SIZE < 0 && size > SIZEABS()) @@ -131,20 +135,19 @@ namespace plib { constexpr reference operator[](size_type i) noexcept { - return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i]; + return data()[i]; } constexpr const_reference operator[](size_type i) const noexcept { - return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(&m_a[0])[i]; + return data()[i]; } - FT * data() noexcept { return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(m_a.data()); } - const FT * data() const noexcept { return assume_aligned_ptr<FT, PALIGN_VECTOROPT>(m_a.data()); } + pointer data() noexcept { return m_a.data(); } + const_pointer data() const noexcept { return m_a.data(); } private: PALIGNAS_VECTOROPT() base_type m_a; - PALIGNAS_CACHELINE() size_type m_size; }; |