diff --git a/libvisual/libvisual/lv_intrusive_ptr.hpp b/libvisual/libvisual/lv_intrusive_ptr.hpp index 9f3543638..688013f5b 100644 --- a/libvisual/libvisual/lv_intrusive_ptr.hpp +++ b/libvisual/libvisual/lv_intrusive_ptr.hpp @@ -3,6 +3,24 @@ namespace LV { + namespace Impl + { + // Checks that the required overloads for LV::IntrusivePtr<> are met. + // NOTE: Only used for concept checking. + template + void check_intrusive_ref_countable (T* a) + { + intrusive_ptr_add_ref (a); + intrusive_ptr_release (a); + } + } + + //! Concept for reference countable types that can be used with LV::IntrusivePtr. + template + concept IntrusiveRefCountable = requires (T* a) + { + Impl::check_intrusive_ref_countable (a); + }; //! Intrusive smart pointer class template. //! @@ -15,7 +33,7 @@ namespace LV //! * void intrusive_ptr_add_ref(T* object) -- _Called to add a reference_ //! * void intrusive_ptr_release(T* object) -- _Called to remove a reference and destroy the object when not longer used_ //! - template + template class IntrusivePtr { public: diff --git a/libvisual/libvisual/private/lv_audio_convert.cpp b/libvisual/libvisual/private/lv_audio_convert.cpp index cf8d6e3a3..afc38be25 100644 --- a/libvisual/libvisual/private/lv_audio_convert.cpp +++ b/libvisual/libvisual/private/lv_audio_convert.cpp @@ -24,6 +24,7 @@ #include "lv_audio.h" #include "lv_mem.h" #include +#include #include #include @@ -36,30 +37,26 @@ namespace { (std::is_signed_v && std::is_signed_v) || (std::is_unsigned_v && std::is_unsigned_v); - template - constexpr std::enable_if_t, T> - half_range () + template + constexpr T half_range () { return std::numeric_limits::max (); } - template - constexpr std::enable_if_t, T> - half_range () + template + constexpr T half_range () { return std::numeric_limits::max () / 2 + 1; } - template - constexpr std::enable_if_t, T> - zero () + template + constexpr T zero () { return 0; } - template - constexpr std::enable_if_t, T> - zero () + template + constexpr T zero () { return std::numeric_limits::max () / 2 + 1; } @@ -81,9 +78,9 @@ namespace { } // signed->unsigned int conversion (same width) - template - inline std::enable_if_t && std::is_signed_v && sizeof(D) == sizeof(S)> - convert_sample_array (D* dst, S const* src, std::size_t count) + template + requires (sizeof (D) == sizeof (S)) + inline void convert_sample_array (D* dst, S const* src, std::size_t count) { constexpr auto a {zero ()}; @@ -97,9 +94,9 @@ namespace { } // unsigned->signed int conversion (same width) - template - inline std::enable_if_t && std::is_unsigned_v && sizeof(D) == sizeof(S)> - convert_sample_array (D* dst, S const* src, std::size_t count) + template + requires (sizeof (D) == sizeof (S)) + inline void convert_sample_array (D* dst, S const* src, std::size_t count) { constexpr auto a {zero ()}; @@ -113,9 +110,8 @@ namespace { } // int->float conversions - template - inline std::enable_if_t> - convert_sample_array (float* dst, S const* src, std::size_t count) + template + inline void convert_sample_array (float* dst, S const* src, std::size_t count) { constexpr float a {1.0 / float (half_range ())}; constexpr float b {-zero() * a}; @@ -130,9 +126,8 @@ namespace { } // float->int conversions - template - std::enable_if_t> - inline convert_sample_array (D* dst, float const* src, std::size_t count) + template + inline void convert_sample_array (D* dst, float const* src, std::size_t count) { constexpr auto a {float (half_range ())}; constexpr auto b {zero ()}; @@ -147,15 +142,15 @@ namespace { } // narrowing/widening int conversion (same signedness) - template - inline std::enable_if_t && sizeof(D) != sizeof(S)> - convert_sample_array (D* dst, S const* src, std::size_t count) + template + requires (is_same_signedness_v && sizeof (D) != sizeof (S)) + inline void convert_sample_array (D* dst, S const* src, std::size_t count) { constexpr auto shift {shifter ()}; auto src_end {src + count}; - if constexpr (sizeof(S) > sizeof(D)) { + if constexpr (sizeof (S) > sizeof (D)) { // narrowing while (src != src_end) { *dst = *src >> shift; @@ -173,16 +168,16 @@ namespace { } // narrowing/widening unsigned->signed int conversion - template - inline std::enable_if_t && std::is_unsigned_v && sizeof(D) != sizeof(S)> - convert_sample_array (D* dst, S const* src, std::size_t count) + template + requires (sizeof (D) != sizeof (S)) + inline void convert_sample_array (D* dst, S const* src, std::size_t count) { constexpr auto a {zero()}; constexpr auto shift {shifter ()}; auto src_end {src + count}; - if constexpr (sizeof(D) < sizeof(S)) { + if constexpr (sizeof (D) < sizeof (S)) { // narrowing while (src != src_end) { *dst = D(*src >> shift) - a; @@ -200,16 +195,16 @@ namespace { } // narrowing/widening signed->unsigned int conversion - template - inline std::enable_if_t && std::is_signed_v && sizeof(D) != sizeof(S)> - convert_sample_array (D* dst, S const* src, std::size_t count) + template + requires (sizeof (D) != sizeof (S)) + inline void convert_sample_array (D* dst, S const* src, std::size_t count) { constexpr auto a {zero()}; constexpr auto shift {shifter ()}; auto src_end {src + count}; - if constexpr (sizeof(D) < sizeof(S)) { + if constexpr (sizeof (D) < sizeof (S)) { // narrowing while (src != src_end) { *dst = D(*src >> shift) + a; @@ -324,7 +319,7 @@ namespace { template void deinterleave_stereo (void* dest1, void* dest2, void const* src, std::size_t size) { - deinterleave_stereo_sample_array (static_cast (dest1), static_cast (dest2), static_cast (src), size / sizeof(T)); + deinterleave_stereo_sample_array (static_cast (dest1), static_cast (dest2), static_cast (src), size / sizeof (T)); } constexpr std::array deinterleave_stereo_func_table {