From 7c14c1fcd7eaad74dfb2a3fa17eea5929c5bc6de Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 8 Sep 2022 12:41:54 +0100 Subject: [PATCH] Use more concise stdlib type aliases --- examples/Plugins/SamplerPluginDemo.h | 2 +- extras/Build/juceaide/Main.cpp | 2 +- .../buffers/juce_AudioSampleBuffer.h | 2 +- .../midi/ump/juce_UMP_test.cpp | 2 +- .../midi/ump/juce_UMPacket.h | 10 +- .../utilities/juce_SmoothedValue.h | 64 +++-- .../format_types/juce_LV2PluginFormat.cpp | 9 +- .../ARA/juce_ARADocumentController.h | 2 +- modules/juce_core/containers/juce_Array.h | 2 +- .../juce_core/containers/juce_ArrayBase.cpp | 4 +- modules/juce_core/containers/juce_ArrayBase.h | 251 ++++++++---------- modules/juce_core/containers/juce_Optional.h | 4 +- modules/juce_core/maths/juce_MathsFunctions.h | 7 +- modules/juce_core/maths/juce_Range.h | 2 +- modules/juce_core/memory/juce_HeapBlock.h | 12 +- modules/juce_core/memory/juce_Memory.h | 6 +- modules/juce_core/misc/juce_Functional.h | 36 ++- modules/juce_core/native/juce_mac_CFHelpers.h | 2 +- .../juce_core/text/juce_CharacterFunctions.h | 4 +- .../juce_core/threads/juce_CriticalSection.h | 4 +- modules/juce_dsp/containers/juce_AudioBlock.h | 22 +- .../containers/juce_AudioBlock_test.cpp | 188 +++++++------ .../containers/juce_FixedSizeFunction.h | 20 +- .../juce_dsp/containers/juce_SIMDRegister.h | 2 +- .../containers/juce_SIMDRegister_test.cpp | 34 ++- modules/juce_dsp/frequency/juce_Convolution.h | 2 +- .../native/juce_fallback_SIMDNativeOps.h | 8 +- modules/juce_dsp/processors/juce_DelayLine.h | 182 ++++++------- modules/juce_dsp/processors/juce_FIRFilter.h | 2 +- .../juce_dsp/processors/juce_IIRFilter_Impl.h | 2 +- .../juce_dsp/processors/juce_ProcessorChain.h | 29 +- .../processors/juce_StateVariableFilter.h | 2 +- modules/juce_graphics/fonts/juce_TextLayout.h | 2 +- modules/juce_graphics/geometry/juce_Point.h | 6 +- .../juce_graphics/geometry/juce_Rectangle.h | 2 +- .../native/juce_win32_Windowing.cpp | 2 +- 36 files changed, 438 insertions(+), 494 deletions(-) diff --git a/examples/Plugins/SamplerPluginDemo.h b/examples/Plugins/SamplerPluginDemo.h index 2d2882ff14..289e9ff352 100644 --- a/examples/Plugins/SamplerPluginDemo.h +++ b/examples/Plugins/SamplerPluginDemo.h @@ -159,7 +159,7 @@ private: template static std::unique_ptr> makeCommand (Func&& func) { - using Decayed = typename std::decay::type; + using Decayed = std::decay_t; return std::make_unique> (std::forward (func)); } diff --git a/extras/Build/juceaide/Main.cpp b/extras/Build/juceaide/Main.cpp index 0892dcad02..d36380a908 100644 --- a/extras/Build/juceaide/Main.cpp +++ b/extras/Build/juceaide/Main.cpp @@ -530,7 +530,7 @@ int main (int argc, char** argv) juce::ArgumentList argumentList { arguments.front(), juce::StringArray (arguments.data() + 1, (int) arguments.size() - 1) }; - using Fn = std::add_lvalue_reference::type; + using Fn = int (*) (juce::ArgumentList&&); const std::unordered_map commands { diff --git a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h index c1f81e2677..251a4a04c4 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h +++ b/modules/juce_audio_basics/buffers/juce_AudioSampleBuffer.h @@ -1177,7 +1177,7 @@ private: jassert (size >= 0); auto channelListSize = (size_t) (numChannels + 1) * sizeof (Type*); - auto requiredSampleAlignment = std::alignment_of::value; + auto requiredSampleAlignment = std::alignment_of_v; size_t alignmentOverflow = channelListSize % requiredSampleAlignment; if (alignmentOverflow != 0) diff --git a/modules/juce_audio_basics/midi/ump/juce_UMP_test.cpp b/modules/juce_audio_basics/midi/ump/juce_UMP_test.cpp index 0706b13bae..fd52554bbe 100644 --- a/modules/juce_audio_basics/midi/ump/juce_UMP_test.cpp +++ b/modules/juce_audio_basics/midi/ump/juce_UMP_test.cpp @@ -992,7 +992,7 @@ private: #if JUCE_WINDOWS && ! JUCE_MINGW #define JUCE_CHECKED_ITERATOR(msg, size) \ - stdext::checked_array_iterator::type> ((msg), (size_t) (size)) + stdext::checked_array_iterator> ((msg), (size_t) (size)) #else #define JUCE_CHECKED_ITERATOR(msg, size) (msg) #endif diff --git a/modules/juce_audio_basics/midi/ump/juce_UMPacket.h b/modules/juce_audio_basics/midi/ump/juce_UMPacket.h index c0e855d3c8..ef811510a1 100644 --- a/modules/juce_audio_basics/midi/ump/juce_UMPacket.h +++ b/modules/juce_audio_basics/midi/ump/juce_UMPacket.h @@ -38,35 +38,35 @@ class Packet public: Packet() = default; - template ::type = 0> + template = 0> Packet (uint32_t a) : contents { { a } } { jassert (Utils::getNumWordsForMessageType (a) == 1); } - template ::type = 0> + template = 0> Packet (uint32_t a, uint32_t b) : contents { { a, b } } { jassert (Utils::getNumWordsForMessageType (a) == 2); } - template ::type = 0> + template = 0> Packet (uint32_t a, uint32_t b, uint32_t c) : contents { { a, b, c } } { jassert (Utils::getNumWordsForMessageType (a) == 3); } - template ::type = 0> + template = 0> Packet (uint32_t a, uint32_t b, uint32_t c, uint32_t d) : contents { { a, b, c, d } } { jassert (Utils::getNumWordsForMessageType (a) == 4); } - template ::type = 0> + template = 0> explicit Packet (const std::array& fullPacket) : contents (fullPacket) { diff --git a/modules/juce_audio_basics/utilities/juce_SmoothedValue.h b/modules/juce_audio_basics/utilities/juce_SmoothedValue.h index 21888b8509..e210705ebd 100644 --- a/modules/juce_audio_basics/utilities/juce_SmoothedValue.h +++ b/modules/juce_audio_basics/utilities/juce_SmoothedValue.h @@ -229,7 +229,7 @@ public: //============================================================================== /** Constructor. */ SmoothedValue() noexcept - : SmoothedValue ((FloatType) (std::is_same::value ? 0 : 1)) + : SmoothedValue ((FloatType) (std::is_same_v ? 0 : 1)) { } @@ -237,7 +237,7 @@ public: SmoothedValue (FloatType initialValue) noexcept { // Multiplicative smoothed values cannot ever reach 0! - jassert (! (std::is_same::value && initialValue == 0)); + jassert (! (std::is_same_v && initialValue == 0)); // Visual Studio can't handle base class initialisation with CRTP this->currentValue = initialValue; @@ -280,7 +280,7 @@ public: } // Multiplicative smoothed values cannot ever reach 0! - jassert (! (std::is_same::value && newValue == 0)); + jassert (! (std::is_same_v && newValue == 0)); this->target = newValue; this->countdown = stepsToTarget; @@ -351,50 +351,46 @@ public: #endif private: - //============================================================================== - template - using LinearVoid = typename std::enable_if ::value, void>::type; - - template - using MultiplicativeVoid = typename std::enable_if ::value, void>::type; - //============================================================================== template - LinearVoid setStepSize() noexcept + void setStepSize() noexcept { - step = (this->target - this->currentValue) / (FloatType) this->countdown; - } - - template - MultiplicativeVoid setStepSize() - { - step = std::exp ((std::log (std::abs (this->target)) - std::log (std::abs (this->currentValue))) / (FloatType) this->countdown); + if constexpr (std::is_same_v) + { + step = (this->target - this->currentValue) / (FloatType) this->countdown; + } + else if constexpr (std::is_same_v) + { + step = std::exp ((std::log (std::abs (this->target)) - std::log (std::abs (this->currentValue))) / (FloatType) this->countdown); + } } //============================================================================== template - LinearVoid setNextValue() noexcept + void setNextValue() noexcept { - this->currentValue += step; - } - - template - MultiplicativeVoid setNextValue() noexcept - { - this->currentValue *= step; + if constexpr (std::is_same_v) + { + this->currentValue += step; + } + else if constexpr (std::is_same_v) + { + this->currentValue *= step; + } } //============================================================================== template - LinearVoid skipCurrentValue (int numSamples) noexcept + void skipCurrentValue (int numSamples) noexcept { - this->currentValue += step * (FloatType) numSamples; - } - - template - MultiplicativeVoid skipCurrentValue (int numSamples) - { - this->currentValue *= (FloatType) std::pow (step, numSamples); + if constexpr (std::is_same_v) + { + this->currentValue += step * (FloatType) numSamples; + } + else if constexpr (std::is_same_v) + { + this->currentValue *= (FloatType) std::pow (step, numSamples); + } } //============================================================================== diff --git a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp index cc27e250a9..374c5bc141 100644 --- a/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp +++ b/modules/juce_audio_processors/format_types/juce_LV2PluginFormat.cpp @@ -944,9 +944,10 @@ struct WorkSubmitter CriticalSection* workMutex; }; -template ::value, int> = 0> +template static auto toChars (Trivial value) { + static_assert (std::is_trivial_v); std::array result; writeUnaligned (result.data(), value); return result; @@ -956,7 +957,7 @@ template class WorkQueue { public: - static_assert (std::is_trivial::value, "Context must be copyable as bytes"); + static_assert (std::is_trivial_v, "Context must be copyable as bytes"); explicit WorkQueue (int size) : fifo (size), data (static_cast (size)) {} @@ -3657,8 +3658,8 @@ private: union Data { - static_assert (std::is_trivial::value, "PortBacking must be trivial"); - static_assert (std::is_trivial::value, "PatchBacking must be trivial"); + static_assert (std::is_trivial_v, "PortBacking must be trivial"); + static_assert (std::is_trivial_v, "PatchBacking must be trivial"); explicit Data (PortBacking p) : port (p) {} explicit Data (PatchBacking p) : patch (p) {} diff --git a/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.h b/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.h index b06a83122f..8b04fbb0ca 100644 --- a/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.h +++ b/modules/juce_audio_processors/utilities/ARA/juce_ARADocumentController.h @@ -123,7 +123,7 @@ public: template static const ARA::ARAFactory* createARAFactory() { - static_assert (std::is_base_of::value, + static_assert (std::is_base_of_v, "DocumentController specialization types must inherit from ARADocumentControllerSpecialisation"); return ARA::PlugIn::PlugInEntry::getPlugInEntry>()->getFactory(); } diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index 05f9579974..d80046b0c1 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -649,7 +649,7 @@ public: @see add */ template - typename std::enable_if::value, void>::type + std::enable_if_t, void> addArray (const OtherArrayType& arrayToAddFrom, int startIndex, int numElementsToAdd = -1) diff --git a/modules/juce_core/containers/juce_ArrayBase.cpp b/modules/juce_core/containers/juce_ArrayBase.cpp index 1553e05b16..9d2657c391 100644 --- a/modules/juce_core/containers/juce_ArrayBase.cpp +++ b/modules/juce_core/containers/juce_ArrayBase.cpp @@ -105,9 +105,9 @@ class ArrayBaseTests : public UnitTest using NoncopyableType = ArrayBaseTestsHelpers::NonTriviallyCopyableType; #if ! (defined(__GNUC__) && __GNUC__ < 5 && ! defined(__clang__)) - static_assert (std::is_trivially_copyable::value, + static_assert (std::is_trivially_copyable_v, "Test TriviallyCopyableType is not trivially copyable"); - static_assert (! std::is_trivially_copyable::value, + static_assert (! std::is_trivially_copyable_v, "Test NonTriviallyCopyableType is trivially copyable"); #endif diff --git a/modules/juce_core/containers/juce_ArrayBase.h b/modules/juce_core/containers/juce_ArrayBase.h index 515bf0f240..af0d1be364 100644 --- a/modules/juce_core/containers/juce_ArrayBase.h +++ b/modules/juce_core/containers/juce_ArrayBase.h @@ -43,8 +43,8 @@ private: using ParameterType = typename TypeHelpers::ParameterType::type; template - using AllowConversion = typename std::enable_if, - std::tuple>::value>::type; + using AllowConversion = std::enable_if_t, + std::tuple>>; public: //============================================================================== @@ -304,7 +304,7 @@ public: } template - typename std::enable_if::value, int>::type + std::enable_if_t, int> addArray (const OtherArrayType& arrayToAddFrom, int startIndex, int numElementsToAdd = -1) { @@ -385,64 +385,49 @@ public: private: //============================================================================== - template #if defined(__GNUC__) && __GNUC__ < 5 && ! defined(__clang__) - using IsTriviallyCopyable = std::is_scalar; + static constexpr auto isTriviallyCopyable = std::is_scalar_v; #else - using IsTriviallyCopyable = std::is_trivially_copyable; + static constexpr auto isTriviallyCopyable = std::is_trivially_copyable_v; #endif - template - using TriviallyCopyableVoid = typename std::enable_if::value, void>::type; - - template - using NonTriviallyCopyableVoid = typename std::enable_if::value, void>::type; - //============================================================================== - template - TriviallyCopyableVoid addArrayInternal (const ElementType* otherElements, int numElements) + template + void addArrayInternal (const Type* otherElements, int numElements) { - if (numElements > 0) - memcpy (elements + numUsed, otherElements, (size_t) numElements * sizeof (ElementType)); - } - - template - TriviallyCopyableVoid addArrayInternal (const Type* otherElements, int numElements) - { - auto* start = elements + numUsed; - - while (--numElements >= 0) - new (start++) ElementType (*(otherElements++)); - } - - template - NonTriviallyCopyableVoid addArrayInternal (const Type* otherElements, int numElements) - { - auto* start = elements + numUsed; - - while (--numElements >= 0) - new (start++) ElementType (*(otherElements++)); - } - - //============================================================================== - template - TriviallyCopyableVoid setAllocatedSizeInternal (int numElements) - { - elements.realloc ((size_t) numElements); - } - - template - NonTriviallyCopyableVoid setAllocatedSizeInternal (int numElements) - { - HeapBlock newElements (numElements); - - for (int i = 0; i < numUsed; ++i) + if constexpr (isTriviallyCopyable && std::is_same_v) { - new (newElements + i) ElementType (std::move (elements[i])); - elements[i].~ElementType(); + if (numElements > 0) + memcpy (elements + numUsed, otherElements, (size_t) numElements * sizeof (ElementType)); } + else + { + auto* start = elements + numUsed; - elements = std::move (newElements); + while (--numElements >= 0) + new (start++) ElementType (*(otherElements++)); + } + } + + //============================================================================== + void setAllocatedSizeInternal (int numElements) + { + if constexpr (isTriviallyCopyable) + { + elements.realloc ((size_t) numElements); + } + else + { + HeapBlock newElements (numElements); + + for (int i = 0; i < numUsed; ++i) + { + new (newElements + i) ElementType (std::move (elements[i])); + elements[i].~ElementType(); + } + + elements = std::move (newElements); + } } //============================================================================== @@ -458,99 +443,99 @@ private: return elements + indexToInsertAt; } - template - TriviallyCopyableVoid createInsertSpaceInternal (int indexToInsertAt, int numElements) + void createInsertSpaceInternal (int indexToInsertAt, int numElements) { - auto* start = elements + indexToInsertAt; - auto numElementsToShift = numUsed - indexToInsertAt; - memmove (start + numElements, start, (size_t) numElementsToShift * sizeof (ElementType)); - } - - template - NonTriviallyCopyableVoid createInsertSpaceInternal (int indexToInsertAt, int numElements) - { - auto* end = elements + numUsed; - auto* newEnd = end + numElements; - auto numElementsToShift = numUsed - indexToInsertAt; - - for (int i = 0; i < numElementsToShift; ++i) + if constexpr (isTriviallyCopyable) { - new (--newEnd) ElementType (std::move (*(--end))); - end->~ElementType(); + auto* start = elements + indexToInsertAt; + auto numElementsToShift = numUsed - indexToInsertAt; + memmove (start + numElements, start, (size_t) numElementsToShift * sizeof (ElementType)); + } + else + { + auto* end = elements + numUsed; + auto* newEnd = end + numElements; + auto numElementsToShift = numUsed - indexToInsertAt; + + for (int i = 0; i < numElementsToShift; ++i) + { + new (--newEnd) ElementType (std::move (*(--end))); + end->~ElementType(); + } } } //============================================================================== - template - TriviallyCopyableVoid removeElementsInternal (int indexToRemoveAt, int numElementsToRemove) + void removeElementsInternal (int indexToRemoveAt, int numElementsToRemove) { - auto* start = elements + indexToRemoveAt; - auto numElementsToShift = numUsed - (indexToRemoveAt + numElementsToRemove); - memmove (start, start + numElementsToRemove, (size_t) numElementsToShift * sizeof (ElementType)); - } + if constexpr (isTriviallyCopyable) + { + auto* start = elements + indexToRemoveAt; + auto numElementsToShift = numUsed - (indexToRemoveAt + numElementsToRemove); + memmove (start, start + numElementsToRemove, (size_t) numElementsToShift * sizeof (ElementType)); + } + else + { + auto numElementsToShift = numUsed - (indexToRemoveAt + numElementsToRemove); + auto* destination = elements + indexToRemoveAt; + auto* source = destination + numElementsToRemove; - template - NonTriviallyCopyableVoid removeElementsInternal (int indexToRemoveAt, int numElementsToRemove) - { - auto numElementsToShift = numUsed - (indexToRemoveAt + numElementsToRemove); - auto* destination = elements + indexToRemoveAt; - auto* source = destination + numElementsToRemove; + for (int i = 0; i < numElementsToShift; ++i) + moveAssignElement (destination++, std::move (*(source++))); - for (int i = 0; i < numElementsToShift; ++i) - moveAssignElement (destination++, std::move (*(source++))); - - for (int i = 0; i < numElementsToRemove; ++i) - (destination++)->~ElementType(); + for (int i = 0; i < numElementsToRemove; ++i) + (destination++)->~ElementType(); + } } //============================================================================== - template - TriviallyCopyableVoid moveInternal (int currentIndex, int newIndex) noexcept + void moveInternal (int currentIndex, int newIndex) noexcept { - char tempCopy[sizeof (ElementType)]; - memcpy (tempCopy, elements + currentIndex, sizeof (ElementType)); - - if (newIndex > currentIndex) + if constexpr (isTriviallyCopyable) { - memmove (elements + currentIndex, - elements + currentIndex + 1, - (size_t) (newIndex - currentIndex) * sizeof (ElementType)); + char tempCopy[sizeof (ElementType)]; + memcpy (tempCopy, elements + currentIndex, sizeof (ElementType)); + + if (newIndex > currentIndex) + { + memmove (elements + currentIndex, + elements + currentIndex + 1, + (size_t) (newIndex - currentIndex) * sizeof (ElementType)); + } + else + { + memmove (elements + newIndex + 1, + elements + newIndex, + (size_t) (currentIndex - newIndex) * sizeof (ElementType)); + } + + memcpy (elements + newIndex, tempCopy, sizeof (ElementType)); } else { - memmove (elements + newIndex + 1, - elements + newIndex, - (size_t) (currentIndex - newIndex) * sizeof (ElementType)); - } + auto* e = elements + currentIndex; + ElementType tempCopy (std::move (*e)); + auto delta = newIndex - currentIndex; - memcpy (elements + newIndex, tempCopy, sizeof (ElementType)); - } - - template - NonTriviallyCopyableVoid moveInternal (int currentIndex, int newIndex) noexcept - { - auto* e = elements + currentIndex; - ElementType tempCopy (std::move (*e)); - auto delta = newIndex - currentIndex; - - if (delta > 0) - { - for (int i = 0; i < delta; ++i) + if (delta > 0) { - moveAssignElement (e, std::move (*(e + 1))); - ++e; + for (int i = 0; i < delta; ++i) + { + moveAssignElement (e, std::move (*(e + 1))); + ++e; + } } - } - else - { - for (int i = 0; i < -delta; ++i) + else { - moveAssignElement (e, std::move (*(e - 1))); - --e; + for (int i = 0; i < -delta; ++i) + { + moveAssignElement (e, std::move (*(e - 1))); + --e; + } } - } - moveAssignElement (e, std::move (tempCopy)); + moveAssignElement (e, std::move (tempCopy)); + } } //============================================================================== @@ -569,19 +554,17 @@ private: } //============================================================================== - template - typename std::enable_if::value, void>::type - moveAssignElement (ElementType* destination, ElementType&& source) + void moveAssignElement (ElementType* destination, ElementType&& source) { - *destination = std::move (source); - } - - template - typename std::enable_if::value, void>::type - moveAssignElement (ElementType* destination, ElementType&& source) - { - destination->~ElementType(); - new (destination) ElementType (std::move (source)); + if constexpr (std::is_move_assignable_v) + { + *destination = std::move (source); + } + else + { + destination->~ElementType(); + new (destination) ElementType (std::move (source)); + } } void checkSourceIsNotAMember (const ElementType& element) diff --git a/modules/juce_core/containers/juce_Optional.h b/modules/juce_core/containers/juce_Optional.h index 7fcd584b64..63bcbd9ffa 100644 --- a/modules/juce_core/containers/juce_Optional.h +++ b/modules/juce_core/containers/juce_Optional.h @@ -53,8 +53,8 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4702) template class Optional { - template struct IsOptional : std::false_type {}; - template struct IsOptional> : std::true_type {}; + template struct IsOptional : std::false_type {}; + template struct IsOptional> : std::true_type {}; public: Optional() = default; diff --git a/modules/juce_core/maths/juce_MathsFunctions.h b/modules/juce_core/maths/juce_MathsFunctions.h index 5b7779d431..cc61820ec7 100644 --- a/modules/juce_core/maths/juce_MathsFunctions.h +++ b/modules/juce_core/maths/juce_MathsFunctions.h @@ -654,11 +654,8 @@ namespace TypeHelpers @tags{Core} */ - template struct SmallestFloatType { using type = float; }; - - #ifndef DOXYGEN - template <> struct SmallestFloatType { using type = double; }; - #endif + template + using SmallestFloatType = std::conditional_t, double, float>; /** These templates are designed to take an integer type, and return an unsigned int version with the same size. diff --git a/modules/juce_core/maths/juce_Range.h b/modules/juce_core/maths/juce_Range.h index 92423dfd7a..9a71195999 100644 --- a/modules/juce_core/maths/juce_Range.h +++ b/modules/juce_core/maths/juce_Range.h @@ -270,7 +270,7 @@ public: } /** Scans an array of values for its min and max, and returns these as a Range. */ - template ::value, int> = 0> + template , int> = 0> static Range findMinAndMax (const ValueType* values, Integral numValues) noexcept { if (numValues <= 0) diff --git a/modules/juce_core/memory/juce_HeapBlock.h b/modules/juce_core/memory/juce_HeapBlock.h index 66a669ec05..1d114cc42d 100644 --- a/modules/juce_core/memory/juce_HeapBlock.h +++ b/modules/juce_core/memory/juce_HeapBlock.h @@ -87,8 +87,8 @@ class HeapBlock { private: template - using AllowConversion = typename std::enable_if::type, - typename std::remove_pointer::type>::value>::type; + using AllowConversion = std::enable_if_t, + std::remove_pointer_t>>; public: //============================================================================== @@ -107,7 +107,7 @@ public: If you want an array of zero values, you can use the calloc() method or the other constructor that takes an InitialisationState parameter. */ - template ::value, int> = 0> + template , int> = 0> explicit HeapBlock (SizeType numElements) : data (static_cast (std::malloc (static_cast (numElements) * sizeof (ElementType)))) { @@ -119,7 +119,7 @@ public: The initialiseToZero parameter determines whether the new memory should be cleared, or left uninitialised. */ - template ::value, int> = 0> + template , int> = 0> HeapBlock (SizeType numElements, bool initialiseToZero) : data (static_cast (initialiseToZero ? std::calloc (static_cast (numElements), sizeof (ElementType)) @@ -152,7 +152,7 @@ public: /** Converting move constructor. Only enabled if this is a HeapBlock and the other object is a HeapBlock, - where std::is_base_of::value == true. + where std::is_base_of_v == true. */ template > HeapBlock (HeapBlock&& other) noexcept @@ -163,7 +163,7 @@ public: /** Converting move assignment operator. Only enabled if this is a HeapBlock and the other object is a HeapBlock, - where std::is_base_of::value == true. + where std::is_base_of_v == true. */ template > HeapBlock& operator= (HeapBlock&& other) noexcept diff --git a/modules/juce_core/memory/juce_Memory.h b/modules/juce_core/memory/juce_Memory.h index eeac405ae4..3110ad17a0 100644 --- a/modules/juce_core/memory/juce_Memory.h +++ b/modules/juce_core/memory/juce_Memory.h @@ -84,9 +84,10 @@ inline void writeUnaligned (void* dstPtr, Type value) noexcept to a region that has suitable alignment for `Type`, e.g. regions returned from malloc/calloc that should be suitable for any non-over-aligned type. */ -template ::value, int>::type = 0> +template inline Type unalignedPointerCast (void* ptr) noexcept { + static_assert (std::is_pointer_v); return reinterpret_cast (ptr); } @@ -97,9 +98,10 @@ inline Type unalignedPointerCast (void* ptr) noexcept to a region that has suitable alignment for `Type`, e.g. regions returned from malloc/calloc that should be suitable for any non-over-aligned type. */ -template ::value, int>::type = 0> +template inline Type unalignedPointerCast (const void* ptr) noexcept { + static_assert (std::is_pointer_v); return reinterpret_cast (ptr); } diff --git a/modules/juce_core/misc/juce_Functional.h b/modules/juce_core/misc/juce_Functional.h index 6ed1729a6a..858c478af8 100644 --- a/modules/juce_core/misc/juce_Functional.h +++ b/modules/juce_core/misc/juce_Functional.h @@ -30,15 +30,10 @@ namespace detail using Void = void; template - struct EqualityComparableToNullptr - : std::false_type {}; + constexpr auto equalityComparableToNullptr = false; template - struct EqualityComparableToNullptr() != nullptr)>> - : std::true_type {}; - - template - constexpr bool shouldCheckAgainstNullptr = EqualityComparableToNullptr::value; + constexpr auto equalityComparableToNullptr() != nullptr)>> = true; } // namespace detail #endif @@ -53,23 +48,22 @@ namespace detail */ struct NullCheckedInvocation { - template , int> = 0> + template static void invoke (Callable&& fn, Args&&... args) { - JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Waddress") + if constexpr (detail::equalityComparableToNullptr) + { + JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Waddress") - if (fn != nullptr) + if (fn != nullptr) + fn (std::forward (args)...); + + JUCE_END_IGNORE_WARNINGS_GCC_LIKE + } + else + { fn (std::forward (args)...); - - JUCE_END_IGNORE_WARNINGS_GCC_LIKE - } - - template , int> = 0> - static void invoke (Callable&& fn, Args&&... args) - { - fn (std::forward (args)...); + } } template @@ -82,7 +76,7 @@ struct NullCheckedInvocation Adapted from https://ericniebler.com/2013/08/07/universal-references-and-the-copy-constructo/ */ template -using DisableIfSameOrDerived = typename std::enable_if_t>::value>; +using DisableIfSameOrDerived = std::enable_if_t>>; /** Copies an object, sets one of the copy's members to the specified value, and then returns the copy. */ template diff --git a/modules/juce_core/native/juce_mac_CFHelpers.h b/modules/juce_core/native/juce_mac_CFHelpers.h index edeca6df5f..57a17db18d 100644 --- a/modules/juce_core/native/juce_mac_CFHelpers.h +++ b/modules/juce_core/native/juce_mac_CFHelpers.h @@ -37,7 +37,7 @@ struct CFObjectDeleter }; template -using CFUniquePtr = std::unique_ptr::type, CFObjectDeleter>; +using CFUniquePtr = std::unique_ptr, CFObjectDeleter>; template struct CFObjectHolder diff --git a/modules/juce_core/text/juce_CharacterFunctions.h b/modules/juce_core/text/juce_CharacterFunctions.h index 7ab9fb03b9..d53695ebfd 100644 --- a/modules/juce_core/text/juce_CharacterFunctions.h +++ b/modules/juce_core/text/juce_CharacterFunctions.h @@ -490,8 +490,8 @@ public: template struct HexParser { - static_assert (std::is_unsigned::value, "ResultType must be unsigned because " - "left-shifting a negative value is UB"); + static_assert (std::is_unsigned_v, "ResultType must be unsigned because " + "left-shifting a negative value is UB"); template static ResultType parse (CharPointerType t) noexcept diff --git a/modules/juce_core/threads/juce_CriticalSection.h b/modules/juce_core/threads/juce_CriticalSection.h index 9d5e12deea..92362bced2 100644 --- a/modules/juce_core/threads/juce_CriticalSection.h +++ b/modules/juce_core/threads/juce_CriticalSection.h @@ -106,9 +106,9 @@ private: // a block of memory here that's big enough to be used internally as a windows // CRITICAL_SECTION structure. #if JUCE_64BIT - std::aligned_storage<44, 8>::type lock; + std::aligned_storage_t<44, 8> lock; #else - std::aligned_storage<24, 8>::type lock; + std::aligned_storage_t<24, 8> lock; #endif #else mutable pthread_mutex_t lock; diff --git a/modules/juce_dsp/containers/juce_AudioBlock.h b/modules/juce_dsp/containers/juce_AudioBlock.h index 58e1a32769..2ccf95dbd0 100644 --- a/modules/juce_dsp/containers/juce_AudioBlock.h +++ b/modules/juce_dsp/containers/juce_AudioBlock.h @@ -31,7 +31,7 @@ namespace dsp #ifndef DOXYGEN namespace SampleTypeHelpers // Internal classes needed for handling sample type classes { - template ::value> + template > struct ElementType { using Type = T; @@ -71,10 +71,10 @@ class AudioBlock private: template using MayUseConvertingConstructor = - std::enable_if_t, - std::remove_const_t>::value - && std::is_const::value - && ! std::is_const::value, + std::enable_if_t, + std::remove_const_t> + && std::is_const_v + && ! std::is_const_v, int>; public: @@ -337,7 +337,7 @@ public: SIMDRegister then incrementing dstPos by one will increase the sample position in the AudioBuffer's units by a factor of SIMDRegister::SIMDNumElements. */ - void copyTo (AudioBuffer::type>& dst, size_t srcPos = 0, size_t dstPos = 0, + void copyTo (AudioBuffer>& dst, size_t srcPos = 0, size_t dstPos = 0, size_t numElements = std::numeric_limits::max()) const { auto dstlen = static_cast (dst.getNumSamples()) / sizeFactor; @@ -518,7 +518,7 @@ public: //============================================================================== /** Finds the minimum and maximum value of the buffer. */ - Range::type> findMinAndMax() const noexcept + Range> findMinAndMax() const noexcept { if (numChannels == 0) return {}; @@ -559,11 +559,11 @@ public: //============================================================================== // This class can only be used with floating point types - static_assert (std::is_same, float>::value - || std::is_same, double>::value + static_assert (std::is_same_v, float> + || std::is_same_v, double> #if JUCE_USE_SIMD - || std::is_same, SIMDRegister>::value - || std::is_same, SIMDRegister>::value + || std::is_same_v, SIMDRegister> + || std::is_same_v, SIMDRegister> #endif , "AudioBlock only supports single or double precision floating point types"); diff --git a/modules/juce_dsp/containers/juce_AudioBlock_test.cpp b/modules/juce_dsp/containers/juce_AudioBlock_test.cpp index df06583cfc..17ffad601f 100644 --- a/modules/juce_dsp/containers/juce_AudioBlock_test.cpp +++ b/modules/juce_dsp/containers/juce_AudioBlock_test.cpp @@ -319,117 +319,109 @@ public: private: //============================================================================== - template - using ScalarVoid = typename std::enable_if_t < std::is_scalar ::value, void>; - - template - using SIMDVoid = typename std::enable_if_t ::value, void>; - - //============================================================================== - template - ScalarVoid copyingTests() + void copyingTests() { - auto unchangedElement1 = block.getSample (0, 4); - auto unchangedElement2 = block.getSample (1, 1); + if constexpr (std::is_scalar_v) + { + auto unchangedElement1 = block.getSample (0, 4); + auto unchangedElement2 = block.getSample (1, 1); - AudioBuffer otherBuffer (otherData.data(), (int) otherData.size(), numSamples); + AudioBuffer otherBuffer (otherData.data(), (int) otherData.size(), numSamples); - block.copyFrom (otherBuffer, 1, 2, 2); + block.copyFrom (otherBuffer, 1, 2, 2); - expectEquals (block.getSample (0, 4), unchangedElement1); - expectEquals (block.getSample (1, 1), unchangedElement2); - expectEquals (block.getSample (0, 2), otherBuffer.getSample (0, 1)); - expectEquals (block.getSample (1, 3), otherBuffer.getSample (1, 2)); + expectEquals (block.getSample (0, 4), unchangedElement1); + expectEquals (block.getSample (1, 1), unchangedElement2); + expectEquals (block.getSample (0, 2), otherBuffer.getSample (0, 1)); + expectEquals (block.getSample (1, 3), otherBuffer.getSample (1, 2)); - resetBlocks(); + resetBlocks(); - unchangedElement1 = otherBuffer.getSample (0, 4); - unchangedElement2 = otherBuffer.getSample (1, 3); + unchangedElement1 = otherBuffer.getSample (0, 4); + unchangedElement2 = otherBuffer.getSample (1, 3); - block.copyTo (otherBuffer, 2, 1, 2); + block.copyTo (otherBuffer, 2, 1, 2); - expectEquals (otherBuffer.getSample (0, 4), unchangedElement1); - expectEquals (otherBuffer.getSample (1, 3), unchangedElement2); - expectEquals (otherBuffer.getSample (0, 1), block.getSample (0, 2)); - expectEquals (otherBuffer.getSample (1, 2), block.getSample (1, 3)); + expectEquals (otherBuffer.getSample (0, 4), unchangedElement1); + expectEquals (otherBuffer.getSample (1, 3), unchangedElement2); + expectEquals (otherBuffer.getSample (0, 1), block.getSample (0, 2)); + expectEquals (otherBuffer.getSample (1, 2), block.getSample (1, 3)); + } + #if JUCE_USE_SIMD + else + { + auto numSIMDElements = SIMDRegister::SIMDNumElements; + AudioBuffer numericData ((int) block.getNumChannels(), + (int) (block.getNumSamples() * numSIMDElements)); + + for (int c = 0; c < numericData.getNumChannels(); ++c) + std::fill_n (numericData.getWritePointer (c), numericData.getNumSamples(), (NumericType) 1.0); + + numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 0.127, (NumericType) 17.3); + + auto lastUnchangedIndexBeforeCopiedRange = (int) ((numSIMDElements * 2) - 1); + auto firstUnchangedIndexAfterCopiedRange = (int) ((numSIMDElements * 4) + 1); + auto unchangedElement1 = numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange); + auto unchangedElement2 = numericData.getSample (1, firstUnchangedIndexAfterCopiedRange); + + block.copyTo (numericData, 1, 2, 2); + + expectEquals (numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange), unchangedElement1); + expectEquals (numericData.getSample (1, firstUnchangedIndexAfterCopiedRange), unchangedElement2); + expect (SampleType (numericData.getSample (0, 2 * (int) numSIMDElements)) == block.getSample (0, 1)); + expect (SampleType (numericData.getSample (1, 3 * (int) numSIMDElements)) == block.getSample (1, 2)); + + numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 15.1, (NumericType) 0.7); + + auto unchangedSIMDElement1 = block.getSample (0, 1); + auto unchangedSIMDElement2 = block.getSample (1, 4); + + block.copyFrom (numericData, 1, 2, 2); + + expect (block.getSample (0, 1) == unchangedSIMDElement1); + expect (block.getSample (1, 4) == unchangedSIMDElement2); + expectEquals (block.getSample (0, 2).get (0), numericData.getSample (0, (int) numSIMDElements)); + expectEquals (block.getSample (1, 3).get (0), numericData.getSample (1, (int) (numSIMDElements * 2))); + + if (numSIMDElements > 1) + { + expectEquals (block.getSample (0, 2).get (1), numericData.getSample (0, (int) (numSIMDElements + 1))); + expectEquals (block.getSample (1, 3).get (1), numericData.getSample (1, (int) ((numSIMDElements * 2) + 1))); + } + } + #endif } - #if JUCE_USE_SIMD - template - SIMDVoid copyingTests() + //============================================================================== + void smoothedValueTests() { - auto numSIMDElements = SIMDRegister::SIMDNumElements; - AudioBuffer numericData ((int) block.getNumChannels(), - (int) (block.getNumSamples() * numSIMDElements)); - - for (int c = 0; c < numericData.getNumChannels(); ++c) - std::fill_n (numericData.getWritePointer (c), numericData.getNumSamples(), (NumericType) 1.0); - - numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 0.127, (NumericType) 17.3); - - auto lastUnchangedIndexBeforeCopiedRange = (int) ((numSIMDElements * 2) - 1); - auto firstUnchangedIndexAfterCopiedRange = (int) ((numSIMDElements * 4) + 1); - auto unchangedElement1 = numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange); - auto unchangedElement2 = numericData.getSample (1, firstUnchangedIndexAfterCopiedRange); - - block.copyTo (numericData, 1, 2, 2); - - expectEquals (numericData.getSample (0, lastUnchangedIndexBeforeCopiedRange), unchangedElement1); - expectEquals (numericData.getSample (1, firstUnchangedIndexAfterCopiedRange), unchangedElement2); - expect (SampleType (numericData.getSample (0, 2 * (int) numSIMDElements)) == block.getSample (0, 1)); - expect (SampleType (numericData.getSample (1, 3 * (int) numSIMDElements)) == block.getSample (1, 2)); - - numericData.applyGainRamp (0, numericData.getNumSamples(), (NumericType) 15.1, (NumericType) 0.7); - - auto unchangedSIMDElement1 = block.getSample (0, 1); - auto unchangedSIMDElement2 = block.getSample (1, 4); - - block.copyFrom (numericData, 1, 2, 2); - - expect (block.getSample (0, 1) == unchangedSIMDElement1); - expect (block.getSample (1, 4) == unchangedSIMDElement2); - expectEquals (block.getSample (0, 2).get (0), numericData.getSample (0, (int) numSIMDElements)); - expectEquals (block.getSample (1, 3).get (0), numericData.getSample (1, (int) (numSIMDElements * 2))); - - if (numSIMDElements > 1) + if constexpr (std::is_scalar_v) { - expectEquals (block.getSample (0, 2).get (1), numericData.getSample (0, (int) (numSIMDElements + 1))); - expectEquals (block.getSample (1, 3).get (1), numericData.getSample (1, (int) ((numSIMDElements * 2) + 1))); + block.fill ((SampleType) 1.0); + SmoothedValue sv { (SampleType) 1.0 }; + sv.reset (1, 4); + sv.setTargetValue ((SampleType) 0.0); + + block.multiplyBy (sv); + expect (block.getSample (0, 2) < (SampleType) 1.0); + expect (block.getSample (1, 2) < (SampleType) 1.0); + expect (block.getSample (0, 2) > (SampleType) 0.0); + expect (block.getSample (1, 2) > (SampleType) 0.0); + expectEquals (block.getSample (0, 5), (SampleType) 0.0); + expectEquals (block.getSample (1, 5), (SampleType) 0.0); + + sv.setCurrentAndTargetValue (-1.0f); + sv.setTargetValue (0.0f); + otherBlock.fill (-1.0f); + block.replaceWithProductOf (otherBlock, sv); + expect (block.getSample (0, 2) < (SampleType) 1.0); + expect (block.getSample (1, 2) < (SampleType) 1.0); + expect (block.getSample (0, 2) > (SampleType) 0.0); + expect (block.getSample (1, 2) > (SampleType) 0.0); + expectEquals (block.getSample (0, 5), (SampleType) 0.0); + expectEquals (block.getSample (1, 5), (SampleType) 0.0); } } - #endif - - //============================================================================== - template - ScalarVoid smoothedValueTests() - { - block.fill ((SampleType) 1.0); - SmoothedValue sv { (SampleType) 1.0 }; - sv.reset (1, 4); - sv.setTargetValue ((SampleType) 0.0); - - block.multiplyBy (sv); - expect (block.getSample (0, 2) < (SampleType) 1.0); - expect (block.getSample (1, 2) < (SampleType) 1.0); - expect (block.getSample (0, 2) > (SampleType) 0.0); - expect (block.getSample (1, 2) > (SampleType) 0.0); - expectEquals (block.getSample (0, 5), (SampleType) 0.0); - expectEquals (block.getSample (1, 5), (SampleType) 0.0); - - sv.setCurrentAndTargetValue (-1.0f); - sv.setTargetValue (0.0f); - otherBlock.fill (-1.0f); - block.replaceWithProductOf (otherBlock, sv); - expect (block.getSample (0, 2) < (SampleType) 1.0); - expect (block.getSample (1, 2) < (SampleType) 1.0); - expect (block.getSample (0, 2) > (SampleType) 0.0); - expect (block.getSample (1, 2) > (SampleType) 0.0); - expectEquals (block.getSample (0, 5), (SampleType) 0.0); - expectEquals (block.getSample (1, 5), (SampleType) 0.0); - } - - template - SIMDVoid smoothedValueTests() {} //============================================================================== void resetBlocks() @@ -451,7 +443,7 @@ private: //============================================================================== static SampleType* allocateAlignedMemory (int numSamplesToAllocate) { - auto alignmentLowerBound = std::alignment_of::value; + auto alignmentLowerBound = std::alignment_of_v; #if ! JUCE_WINDOWS alignmentLowerBound = jmax (sizeof (void*), alignmentLowerBound); #endif diff --git a/modules/juce_dsp/containers/juce_FixedSizeFunction.h b/modules/juce_dsp/containers/juce_FixedSizeFunction.h index 565f865898..234c4aa971 100644 --- a/modules/juce_dsp/containers/juce_FixedSizeFunction.h +++ b/modules/juce_dsp/containers/juce_FixedSizeFunction.h @@ -56,13 +56,13 @@ namespace detail } template - typename std::enable_if::value, Ret>::type call (void* s, Args... args) + std::enable_if_t, Ret> call (void* s, Args... args) { (*reinterpret_cast (s)) (args...); } template - typename std::enable_if::value, Ret>::type call (void* s, Args... args) + std::enable_if_t, Ret> call (void* s, Args... args) { return (*reinterpret_cast (s)) (std::forward (args)...); } @@ -102,16 +102,16 @@ template class FixedSizeFunction { private: - using Storage = typename std::aligned_storage::type; + using Storage = std::aligned_storage_t; template - using Decay = typename std::decay::type; + using Decay = std::decay_t; template > - using IntIfValidConversion = typename std::enable_if::value, - int>::type; + using IntIfValidConversion = std::enable_if_t, + int>; public: /** Create an empty function. */ @@ -149,7 +149,7 @@ public: } /** Converting constructor from smaller FixedSizeFunctions. */ - template ::type = 0> + template = 0> FixedSizeFunction (FixedSizeFunction&& other) noexcept : vtable (other.vtable) { @@ -172,7 +172,7 @@ public: } /** Move assignment from smaller FixedSizeFunctions. */ - template ::type = 0> + template = 0> FixedSizeFunction& operator= (FixedSizeFunction&& other) noexcept { return *this = FixedSizeFunction (std::move (other)); diff --git a/modules/juce_dsp/containers/juce_SIMDRegister.h b/modules/juce_dsp/containers/juce_SIMDRegister.h index 270193abbb..04449a7906 100644 --- a/modules/juce_dsp/containers/juce_SIMDRegister.h +++ b/modules/juce_dsp/containers/juce_SIMDRegister.h @@ -70,7 +70,7 @@ struct SIMDRegister /** The corresponding primitive integer type, for example, this will be int32_t if type is a float. */ - using MaskType = typename SIMDInternal::MaskTypeFor::type; + using MaskType = SIMDInternal::MaskType; //============================================================================== // Here are some types which are needed internally diff --git a/modules/juce_dsp/containers/juce_SIMDRegister_test.cpp b/modules/juce_dsp/containers/juce_SIMDRegister_test.cpp index f5ed7de81c..a8881fcb77 100644 --- a/modules/juce_dsp/containers/juce_SIMDRegister_test.cpp +++ b/modules/juce_dsp/containers/juce_SIMDRegister_test.cpp @@ -30,31 +30,30 @@ namespace dsp namespace SIMDRegister_test_internal { - template struct RandomPrimitive {}; - template - struct RandomPrimitive::value>::type> + struct RandomPrimitive { static type next (Random& random) { - return static_cast (std::is_signed::value ? (random.nextFloat() * 16.0) - 8.0 - : (random.nextFloat() * 8.0)); - } - }; - - template - struct RandomPrimitive::value>::type> - { - static type next (Random& random) - { - return static_cast (random.nextInt64()); + if constexpr (std::is_floating_point_v) + { + return static_cast (std::is_signed_v ? (random.nextFloat() * 16.0) - 8.0 + : (random.nextFloat() * 8.0)); + } + else if constexpr (std::is_integral_v) + { + return static_cast (random.nextInt64()); + } } }; template struct RandomValue { - static type next (Random& random) { return RandomPrimitive::next (random); } + static type next (Random& random) + { + return RandomPrimitive::next (random); + } }; template @@ -756,11 +755,10 @@ public: template static void run (UnitTest& u, Random& random, Tag) { - bool is_signed = std::is_signed::value; type array [SIMDRegister::SIMDNumElements]; - auto value = is_signed ? static_cast ((random.nextFloat() * 16.0) - 8.0) - : static_cast (random.nextFloat() * 8.0); + auto value = std::is_signed_v ? static_cast ((random.nextFloat() * 16.0) - 8.0) + : static_cast (random.nextFloat() * 8.0); std::fill (array, array + SIMDRegister::SIMDNumElements, value); SIMDRegister a, b; diff --git a/modules/juce_dsp/frequency/juce_Convolution.h b/modules/juce_dsp/frequency/juce_Convolution.h index f9b18a0455..19c44f575e 100644 --- a/modules/juce_dsp/frequency/juce_Convolution.h +++ b/modules/juce_dsp/frequency/juce_Convolution.h @@ -184,7 +184,7 @@ public: stereo processing. */ template ::value, int> = 0> + std::enable_if_t, int> = 0> void process (const ProcessContext& context) noexcept { processSamples (context.getInputBlock(), context.getOutputBlock(), context.isBypassed); diff --git a/modules/juce_dsp/native/juce_fallback_SIMDNativeOps.h b/modules/juce_dsp/native/juce_fallback_SIMDNativeOps.h index 2e0c72b903..595e02e049 100644 --- a/modules/juce_dsp/native/juce_fallback_SIMDNativeOps.h +++ b/modules/juce_dsp/native/juce_fallback_SIMDNativeOps.h @@ -42,8 +42,10 @@ namespace SIMDInternal template <> struct MaskTypeFor > { using type = uint32_t; }; template <> struct MaskTypeFor > { using type = uint64_t; }; - template struct PrimitiveType { using type = typename std::remove_cv::type; }; - template struct PrimitiveType> { using type = typename std::remove_cv::type; }; + template using MaskType = typename MaskTypeFor::type; + + template struct PrimitiveType { using type = std::remove_cv_t; }; + template struct PrimitiveType> { using type = std::remove_cv_t; }; template struct Log2Helper { enum { value = Log2Helper::value + 1 }; }; template <> struct Log2Helper<1> { enum { value = 0 }; }; @@ -63,7 +65,7 @@ struct SIMDFallbackOps static constexpr size_t bits = SIMDInternal::Log2Helper<(int) n>::value; // helper types - using MaskType = typename SIMDInternal::MaskTypeFor::type; + using MaskType = SIMDInternal::MaskType; union UnionType { vSIMDType v; ScalarType s[n]; }; union UnionMaskType { vSIMDType v; MaskType m[n]; }; diff --git a/modules/juce_dsp/processors/juce_DelayLine.h b/modules/juce_dsp/processors/juce_DelayLine.h index a32295f001..0d92237606 100644 --- a/modules/juce_dsp/processors/juce_DelayLine.h +++ b/modules/juce_dsp/processors/juce_DelayLine.h @@ -201,126 +201,104 @@ public: private: //============================================================================== - template - typename std::enable_if ::value, SampleType>::type - interpolateSample (int channel) const + SampleType interpolateSample (int channel) { - auto index = (readPos[(size_t) channel] + delayInt) % totalSize; - return bufferData.getSample (channel, index); - } - - template - typename std::enable_if ::value, SampleType>::type - interpolateSample (int channel) const - { - auto index1 = readPos[(size_t) channel] + delayInt; - auto index2 = index1 + 1; - - if (index2 >= totalSize) + if constexpr (std::is_same_v) { - index1 %= totalSize; - index2 %= totalSize; + auto index = (readPos[(size_t) channel] + delayInt) % totalSize; + return bufferData.getSample (channel, index); } - - auto value1 = bufferData.getSample (channel, index1); - auto value2 = bufferData.getSample (channel, index2); - - return value1 + delayFrac * (value2 - value1); - } - - template - typename std::enable_if ::value, SampleType>::type - interpolateSample (int channel) const - { - auto index1 = readPos[(size_t) channel] + delayInt; - auto index2 = index1 + 1; - auto index3 = index2 + 1; - auto index4 = index3 + 1; - - if (index4 >= totalSize) + else if constexpr (std::is_same_v) { - index1 %= totalSize; - index2 %= totalSize; - index3 %= totalSize; - index4 %= totalSize; + auto index1 = readPos[(size_t) channel] + delayInt; + auto index2 = index1 + 1; + + if (index2 >= totalSize) + { + index1 %= totalSize; + index2 %= totalSize; + } + + auto value1 = bufferData.getSample (channel, index1); + auto value2 = bufferData.getSample (channel, index2); + + return value1 + delayFrac * (value2 - value1); } - - auto* samples = bufferData.getReadPointer (channel); - - auto value1 = samples[index1]; - auto value2 = samples[index2]; - auto value3 = samples[index3]; - auto value4 = samples[index4]; - - auto d1 = delayFrac - 1.f; - auto d2 = delayFrac - 2.f; - auto d3 = delayFrac - 3.f; - - auto c1 = -d1 * d2 * d3 / 6.f; - auto c2 = d2 * d3 * 0.5f; - auto c3 = -d1 * d3 * 0.5f; - auto c4 = d1 * d2 / 6.f; - - return value1 * c1 + delayFrac * (value2 * c2 + value3 * c3 + value4 * c4); - } - - template - typename std::enable_if ::value, SampleType>::type - interpolateSample (int channel) - { - auto index1 = readPos[(size_t) channel] + delayInt; - auto index2 = index1 + 1; - - if (index2 >= totalSize) + else if constexpr (std::is_same_v) { - index1 %= totalSize; - index2 %= totalSize; + auto index1 = readPos[(size_t) channel] + delayInt; + auto index2 = index1 + 1; + auto index3 = index2 + 1; + auto index4 = index3 + 1; + + if (index4 >= totalSize) + { + index1 %= totalSize; + index2 %= totalSize; + index3 %= totalSize; + index4 %= totalSize; + } + + auto* samples = bufferData.getReadPointer (channel); + + auto value1 = samples[index1]; + auto value2 = samples[index2]; + auto value3 = samples[index3]; + auto value4 = samples[index4]; + + auto d1 = delayFrac - 1.f; + auto d2 = delayFrac - 2.f; + auto d3 = delayFrac - 3.f; + + auto c1 = -d1 * d2 * d3 / 6.f; + auto c2 = d2 * d3 * 0.5f; + auto c3 = -d1 * d3 * 0.5f; + auto c4 = d1 * d2 / 6.f; + + return value1 * c1 + delayFrac * (value2 * c2 + value3 * c3 + value4 * c4); } + else if constexpr (std::is_same_v) + { + auto index1 = readPos[(size_t) channel] + delayInt; + auto index2 = index1 + 1; - auto value1 = bufferData.getSample (channel, index1); - auto value2 = bufferData.getSample (channel, index2); + if (index2 >= totalSize) + { + index1 %= totalSize; + index2 %= totalSize; + } - auto output = delayFrac == 0 ? value1 : value2 + alpha * (value1 - v[(size_t) channel]); - v[(size_t) channel] = output; + auto value1 = bufferData.getSample (channel, index1); + auto value2 = bufferData.getSample (channel, index2); - return output; + auto output = delayFrac == 0 ? value1 : value2 + alpha * (value1 - v[(size_t) channel]); + v[(size_t) channel] = output; + + return output; + } } //============================================================================== - template - typename std::enable_if ::value, void>::type - updateInternalVariables() + void updateInternalVariables() { - } - - template - typename std::enable_if ::value, void>::type - updateInternalVariables() - { - } - - template - typename std::enable_if ::value, void>::type - updateInternalVariables() - { - if (delayInt >= 1) + if constexpr (std::is_same_v) { - delayFrac++; - delayInt--; + if (delayInt >= 1) + { + delayFrac++; + delayInt--; + } } - } - - template - typename std::enable_if ::value, void>::type - updateInternalVariables() - { - if (delayFrac < (SampleType) 0.618 && delayInt >= 1) + else if constexpr (std::is_same_v) { - delayFrac++; - delayInt--; - } + if (delayFrac < (SampleType) 0.618 && delayInt >= 1) + { + delayFrac++; + delayInt--; + } - alpha = (1 - delayFrac) / (1 + delayFrac); + alpha = (1 - delayFrac) / (1 + delayFrac); + } } //============================================================================== diff --git a/modules/juce_dsp/processors/juce_FIRFilter.h b/modules/juce_dsp/processors/juce_FIRFilter.h index 560fdc2c8b..203c12836b 100644 --- a/modules/juce_dsp/processors/juce_FIRFilter.h +++ b/modules/juce_dsp/processors/juce_FIRFilter.h @@ -122,7 +122,7 @@ namespace FIR template void process (const ProcessContext& context) noexcept { - static_assert (std::is_same::value, + static_assert (std::is_same_v, "The sample-type of the FIR filter must match the sample-type supplied to this process callback"); check(); diff --git a/modules/juce_dsp/processors/juce_IIRFilter_Impl.h b/modules/juce_dsp/processors/juce_IIRFilter_Impl.h index 9644f4dc97..150ab429e9 100644 --- a/modules/juce_dsp/processors/juce_IIRFilter_Impl.h +++ b/modules/juce_dsp/processors/juce_IIRFilter_Impl.h @@ -89,7 +89,7 @@ template template void Filter::processInternal (const ProcessContext& context) noexcept { - static_assert (std::is_same::value, + static_assert (std::is_same_v, "The sample-type of the IIR filter must match the sample-type supplied to this process callback"); check(); diff --git a/modules/juce_dsp/processors/juce_ProcessorChain.h b/modules/juce_dsp/processors/juce_ProcessorChain.h index 1336fc6be9..9f821018c2 100644 --- a/modules/juce_dsp/processors/juce_ProcessorChain.h +++ b/modules/juce_dsp/processors/juce_ProcessorChain.h @@ -42,7 +42,7 @@ namespace detail } template - using TupleIndexSequence = std::make_index_sequence>>::value>; + using TupleIndexSequence = std::make_index_sequence>>>; template constexpr void forEachInTuple (Fn&& fn, Tuple&& tuple) @@ -99,23 +99,24 @@ public: } private: - template , int> = 0> + template void processOne (const Context& context, Proc& proc, std::integral_constant) noexcept { - jassert (context.getOutputBlock().getNumChannels() == context.getInputBlock().getNumChannels()); - ProcessContextReplacing replacingContext (context.getOutputBlock()); - replacingContext.isBypassed = (bypassed[Ix] || context.isBypassed); + if constexpr (detail::useContextDirectly) + { + auto contextCopy = context; + contextCopy.isBypassed = (bypassed[Ix] || context.isBypassed); - proc.process (replacingContext); - } + proc.process (contextCopy); + } + else + { + jassert (context.getOutputBlock().getNumChannels() == context.getInputBlock().getNumChannels()); + ProcessContextReplacing replacingContext (context.getOutputBlock()); + replacingContext.isBypassed = (bypassed[Ix] || context.isBypassed); - template , int> = 0> - void processOne (const Context& context, Proc& proc, std::integral_constant) noexcept - { - auto contextCopy = context; - contextCopy.isBypassed = (bypassed[Ix] || context.isBypassed); - - proc.process (contextCopy); + proc.process (replacingContext); + } } std::tuple processors; diff --git a/modules/juce_dsp/processors/juce_StateVariableFilter.h b/modules/juce_dsp/processors/juce_StateVariableFilter.h index 9a99160842..6554b2bc6e 100644 --- a/modules/juce_dsp/processors/juce_StateVariableFilter.h +++ b/modules/juce_dsp/processors/juce_StateVariableFilter.h @@ -110,7 +110,7 @@ namespace StateVariableFilter template void process (const ProcessContext& context) noexcept { - static_assert (std::is_same::value, + static_assert (std::is_same_v, "The sample-type of the filter must match the sample-type supplied to this process callback"); if (context.isBypassed) diff --git a/modules/juce_graphics/fonts/juce_TextLayout.h b/modules/juce_graphics/fonts/juce_TextLayout.h index 7e7e98235b..7bd2a0b861 100644 --- a/modules/juce_graphics/fonts/juce_TextLayout.h +++ b/modules/juce_graphics/fonts/juce_TextLayout.h @@ -44,7 +44,7 @@ private: class DereferencingIterator { public: - using value_type = typename std::remove_reference())>::type; + using value_type = std::remove_reference_t())>; using difference_type = typename std::iterator_traits::difference_type; using pointer = value_type*; using reference = value_type&; diff --git a/modules/juce_graphics/geometry/juce_Point.h b/modules/juce_graphics/geometry/juce_Point.h index da183d1e11..5525328855 100644 --- a/modules/juce_graphics/geometry/juce_Point.h +++ b/modules/juce_graphics/geometry/juce_Point.h @@ -123,7 +123,7 @@ public: template constexpr Point operator* (OtherType multiplier) const noexcept { - using CommonType = typename std::common_type::type; + using CommonType = std::common_type_t; return Point ((ValueType) ((CommonType) x * (CommonType) multiplier), (ValueType) ((CommonType) y * (CommonType) multiplier)); } @@ -132,7 +132,7 @@ public: template constexpr Point operator/ (OtherType divisor) const noexcept { - using CommonType = typename std::common_type::type; + using CommonType = std::common_type_t; return Point ((ValueType) ((CommonType) x / (CommonType) divisor), (ValueType) ((CommonType) y / (CommonType) divisor)); } @@ -150,7 +150,7 @@ public: //============================================================================== /** This type will be double if the Point's type is double, otherwise it will be float. */ - using FloatType = typename TypeHelpers::SmallestFloatType::type; + using FloatType = TypeHelpers::SmallestFloatType; //============================================================================== /** Returns the straight-line distance between this point and the origin. */ diff --git a/modules/juce_graphics/geometry/juce_Rectangle.h b/modules/juce_graphics/geometry/juce_Rectangle.h index d7f08b905e..9789f7ee27 100644 --- a/modules/juce_graphics/geometry/juce_Rectangle.h +++ b/modules/juce_graphics/geometry/juce_Rectangle.h @@ -813,7 +813,7 @@ public: */ Rectangle transformedBy (const AffineTransform& transform) const noexcept { - using FloatType = typename TypeHelpers::SmallestFloatType::type; + using FloatType = TypeHelpers::SmallestFloatType; auto x1 = static_cast (pos.x), y1 = static_cast (pos.y); auto x2 = static_cast (pos.x + w), y2 = static_cast (pos.y); diff --git a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp index cb247722a7..ba07b79ddb 100644 --- a/modules/juce_gui_basics/native/juce_win32_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_win32_Windowing.cpp @@ -2811,7 +2811,7 @@ private: CombineRgn (rgn, rgn, clipRgn, RGN_AND); DeleteObject (clipRgn); - std::aligned_storage<8192, alignof (RGNDATA)>::type rgnData; + std::aligned_storage_t<8192, alignof (RGNDATA)> rgnData; const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) &rgnData); if (res > 0 && res <= sizeof (rgnData))