diff --git a/examples/DemoRunner/Source/UI/DemoContentComponent.cpp b/examples/DemoRunner/Source/UI/DemoContentComponent.cpp index 1c6d9a3562..c00b8165e0 100644 --- a/examples/DemoRunner/Source/UI/DemoContentComponent.cpp +++ b/examples/DemoRunner/Source/UI/DemoContentComponent.cpp @@ -103,7 +103,7 @@ struct CodeContent : public Component //============================================================================== DemoContentComponent::DemoContentComponent (Component& mainComponent, std::function callback) : TabbedComponent (TabbedButtonBar::Orientation::TabsAtTop), - demoChangedCallback (callback) + demoChangedCallback (std::move (callback)) { demoContent.reset (new DemoContent()); addTab ("Demo", Colours::transparentBlack, demoContent.get(), false); diff --git a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp index 5c96871bac..d852991a71 100644 --- a/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp +++ b/extras/Projucer/Source/LiveBuildEngine/jucer_CompileEngineClient.cpp @@ -336,9 +336,6 @@ private: if (exporter->canLaunchProject()) defs.add (exporter->getExporterIdentifierMacro() + "=1"); - // Use the JUCE implementation of std::function until the live build - // engine can compile the one from the standard library - defs.add (" _LIBCPP_FUNCTIONAL=1"); defs.removeEmptyStrings(); return defs.joinIntoString (" "); diff --git a/modules/juce_core/juce_core.cpp b/modules/juce_core/juce_core.cpp index e3880a0f03..1c58ba7732 100644 --- a/modules/juce_core/juce_core.cpp +++ b/modules/juce_core/juce_core.cpp @@ -141,7 +141,6 @@ #include "misc/juce_RuntimePermissions.cpp" #include "misc/juce_Result.cpp" #include "misc/juce_Uuid.cpp" -#include "misc/juce_StdFunctionCompat.cpp" #include "misc/juce_ConsoleApplication.cpp" #include "network/juce_MACAddress.cpp" #include "network/juce_NamedPipe.cpp" diff --git a/modules/juce_core/misc/juce_StdFunctionCompat.cpp b/modules/juce_core/misc/juce_StdFunctionCompat.cpp deleted file mode 100644 index ece1e5ec97..0000000000 --- a/modules/juce_core/misc/juce_StdFunctionCompat.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - ============================================================================== - - This file is part of the JUCE library. - Copyright (c) 2017 - ROLI Ltd. - - Permission is granted to use this software under the terms of the ISC license - http://www.isc.org/downloads/software-support-policy/isc-license/ - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD - TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, - OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF - USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - OF THIS SOFTWARE. - - ----------------------------------------------------------------------------- - - To release a closed-source product which uses other parts of JUCE not - licensed under the ISC terms, commercial licenses are available: visit - www.juce.com for more information. - - ============================================================================== -*/ - -namespace juce -{ - -#if JUCE_UNIT_TESTS - -namespace FunctionTestsHelpers -{ - static void incrementArgument (int& x) { x++; } - static double multiply (double x, double a) noexcept { return a * x; } - - struct BigData - { - BigData() - { - for (auto i = 0; i < bigDataSize; ++i) - content[i] = i + 1; - } - - int sum() const - { - int result = 0; - for (auto i = 0; i < bigDataSize; ++i) - result += content[i]; - - return result; - } - - static const int bigDataSize = 32, - bigDataSum = bigDataSize * (bigDataSize + 1) / 2; - int content[bigDataSize]; - }; - - struct FunctionObject - { - FunctionObject() = default; - - FunctionObject (const FunctionObject& other) - { - bigData.reset (new BigData (*other.bigData)); - } - - int operator()(int i) const { return bigData->sum() + i; } - - std::unique_ptr bigData { new BigData() }; - - JUCE_LEAK_DETECTOR (FunctionObject) - }; - - struct BigFunctionObject - { - BigFunctionObject() = default; - - BigFunctionObject (const BigFunctionObject& other) - { - bigData.reset (new BigData (*other.bigData)); - } - - int operator()(int i) const { return bigData->sum() + i; } - - std::unique_ptr bigData { new BigData() }; - - int stackUsage[32]; - - JUCE_LEAK_DETECTOR (BigFunctionObject) - }; -} - -class FunctionTests : public UnitTest -{ -public: - FunctionTests() - : UnitTest ("Function", UnitTestCategories::function) - {} - - void runTest() override - { - FunctionTestsHelpers::BigData bigData; - - { - beginTest ("Functions"); - - std::function f1 (FunctionTestsHelpers::incrementArgument); - - auto x = 0; - f1 (x); - expectEquals (x, 1); - - std::function f2 (FunctionTestsHelpers::multiply); - expectEquals (6.0, f2 (2.0, 3.0)); - } - - { - beginTest ("Function objects"); - - std::function f1 = FunctionTestsHelpers::FunctionObject(); - expectEquals (f1 (5), FunctionTestsHelpers::BigData::bigDataSum + 5); - - std::function f2 { FunctionTestsHelpers::BigFunctionObject() }; - expectEquals (f2 (5), FunctionTestsHelpers::BigData::bigDataSum + 5); - } - - { - beginTest ("Lambdas"); - - std::function fStack ([] { return 3; }); - expectEquals (fStack(), 3); - - std::function fHeap ([=] { return bigData.sum(); }); - expectEquals (fHeap(), FunctionTestsHelpers::BigData::bigDataSum); - } - - { - beginTest ("Boolean"); - - std::function f1; - - if (f1) - expect (false); - - std::function f2 ([]() { return 3; }); - - if (! f2) - expect (false); - } - - std::function fEmpty; - - std::function fStack ([] { return 3; }); - - std::function fHeap ([=] { return bigData.sum(); }); - - { - beginTest ("copy constructor"); - - std::function f1 (fStack); - expectEquals (f1(), 3); - - std::function f2 (fHeap); - expectEquals (f2(), FunctionTestsHelpers::BigData::bigDataSum); - - std::function f3 (fEmpty); - if (f3) - expect (false); - } - - { - beginTest ("assignment"); - - std::function f1; - f1 = fStack; - expectEquals (f1(), 3); - - std::function f2; - f2 = fHeap; - expectEquals (f2(), FunctionTestsHelpers::BigData::bigDataSum); - - f1 = fHeap; - expectEquals (f1(), FunctionTestsHelpers::BigData::bigDataSum); - - f2 = fStack; - expectEquals (f2(), 3); - - f1 = fEmpty; - if (f1) - expect (false); - } - - { - beginTest ("move constructor"); - - std::unique_ptr> fStackTmp (new std::function (fStack)); - std::function f1 (std::move (*fStackTmp)); - - fStackTmp.reset(); - expectEquals (f1(), 3); - - std::unique_ptr> fHeapTmp (new std::function (fHeap)); - std::function f2 (std::move (*fHeapTmp)); - if (*fHeapTmp) - expect (false); - - fHeapTmp.reset(); - expectEquals (f2(), FunctionTestsHelpers::BigData::bigDataSum); - - std::unique_ptr> fEmptyTmp (new std::function()); - std::function f3 (std::move (*fEmptyTmp)); - fEmptyTmp.reset(); - if (f3) - expect (false); - } - - { - beginTest ("move assignment"); - - std::function f1 (fHeap); - std::unique_ptr> fStackTmp (new std::function (fStack)); - f1 = std::move (*fStackTmp); - - fStackTmp.reset(); - expectEquals (f1(), 3); - - std::function f2 (fStack); - std::unique_ptr> fHeapTmp (new std::function (fHeap)); - f2 = std::move (*fHeapTmp); - if (*fHeapTmp) - expect (false); - - fHeapTmp.reset(); - expectEquals (f2(), FunctionTestsHelpers::BigData::bigDataSum); - - std::function f3 (fHeap); - std::unique_ptr> fEmptyTmp (new std::function()); - f3 = std::move (*fEmptyTmp); - fEmptyTmp.reset(); - if (f3) - expect (false); - } - - { - beginTest ("nullptr"); - - std::function f1 (nullptr); - if (f1) - expect (false); - - std::function f2 ([]() { return 11; }); - f2 = nullptr; - if (f2) - expect (false); - } - - { - beginTest ("Swap"); - - std::function f1; - std::function f2 (fStack); - f2.swap (f1); - expectEquals (f1(), 3); - if (f2) - expect (false); - - std::function f3 (fHeap); - f3.swap (f1); - expectEquals (f3(), 3); - expectEquals (f1(), FunctionTestsHelpers::BigData::bigDataSum); - } - } -}; - -static FunctionTests functionTests; - -#endif - -} // namespace juce diff --git a/modules/juce_core/misc/juce_StdFunctionCompat.h b/modules/juce_core/misc/juce_StdFunctionCompat.h deleted file mode 100644 index 94c65f4a3c..0000000000 --- a/modules/juce_core/misc/juce_StdFunctionCompat.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - ============================================================================== - - This file is part of the JUCE library. - Copyright (c) 2017 - ROLI Ltd. - - Permission is granted to use this software under the terms of the ISC license - http://www.isc.org/downloads/software-support-policy/isc-license/ - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD - TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, - OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF - USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE - OF THIS SOFTWARE. - - ----------------------------------------------------------------------------- - - To release a closed-source product which uses other parts of JUCE not - licensed under the ISC terms, commercial licenses are available: visit - www.juce.com for more information. - - ============================================================================== -*/ - -namespace std -{ - /** - This class provides an alternative to std::function that is compatible - with OS X 10.6 and earlier. This will only be used in OS X versions 10.6 - and earlier and the Projucer live build. - - @tags{Core} - */ - template - class function; - - #ifndef DOXYGEN - template - class function - { - public: - /** Creates an empty function. */ - function() noexcept {} - - /** Creates an empty function. */ - function (decltype (nullptr)) noexcept {} - - /** Creates a function targeting the provided Functor. */ - template - function (Functor f) - { - functorHolderHelper = getFunctorStorage (sizeof (FunctorHolder)); - new (functorHolderHelper) FunctorHolder (f); - } - - /** Copy constructor. */ - function (function const& other) - { - copy (other); - } - - /** Move constructor */ - function (function&& other) - { - move (other); - } - - /** Destructor. */ - ~function() - { - release(); - } - - /** Replaces the contents of this function with the contents of another. */ - function& operator= (function const& other) - { - release(); - copy (other); - - return *this; - } - - /** Moves the contents of another function into this one. */ - function& operator= (function&& other) - { - release(); - move (other); - - return *this; - } - - /** Allows conditional expressions to test if this function is empty. */ - explicit operator bool() const noexcept - { - return functorHolderHelper != nullptr; - } - - /** Swaps the contents of this function with another. After this operation the - two functions will be pointing at each other's targets. */ - void swap (function& other) - { - function tmp (*this); - *this = other; - other = tmp; - } - - /** Invokes the target of this function. */ - Result operator() (Arguments... args) const - { - return (*functorHolderHelper) (std::forward (args)...); - } - - bool operator== (decltype (nullptr)) const noexcept { return (functorHolderHelper == nullptr); } - bool operator!= (decltype (nullptr)) const noexcept { return (functorHolderHelper != nullptr); } - - private: - //============================================================================== - template - struct FunctorHolderBase - { - virtual ~FunctorHolderBase() {} - virtual int getSize() const noexcept = 0; - virtual void copy (void*) const = 0; - virtual ReturnType operator()(Args...) = 0; - }; - - template - struct FunctorHolder : FunctorHolderBase - { - FunctorHolder (Functor func) : f (func) {} - - int getSize() const noexcept override final - { - return sizeof (*this); - } - - void copy (void* destination) const override final - { - new (destination) FunctorHolder (f); - } - - ReturnType operator()(Args... args) override final - { - return f (std::forward (args)...); - } - - Functor f; - }; - - FunctorHolderBase* getFunctorStorage (int size) - { - return reinterpret_cast*> - (size > functorHolderStackSize ? new char [static_cast (size)] - : &(stackFunctorStorage[0])); - } - - void copy (function const& other) - { - if (other.functorHolderHelper != nullptr) - { - functorHolderHelper = getFunctorStorage (other.functorHolderHelper->getSize()); - other.functorHolderHelper->copy (functorHolderHelper); - } - } - - void move (function& other) - { - if (other.functorHolderHelper != nullptr) - { - if (other.functorHolderHelper->getSize() > functorHolderStackSize) - { - functorHolderHelper = other.functorHolderHelper; - } - else - { - std::copy (other.stackFunctorStorage, other.stackFunctorStorage + functorHolderStackSize, - stackFunctorStorage); - functorHolderHelper = reinterpret_cast*> (&(stackFunctorStorage[0])); - } - - other.functorHolderHelper = nullptr; - } - } - - void release() - { - if (functorHolderHelper != nullptr) - { - functorHolderHelper->~FunctorHolderBase(); - functorHolderHelper = nullptr; - } - } - - static const int functorHolderStackSize = 24; - char stackFunctorStorage[functorHolderStackSize]; - - FunctorHolderBase* functorHolderHelper = nullptr; - }; - #endif -} diff --git a/modules/juce_core/native/juce_mac_ClangBugWorkaround.h b/modules/juce_core/native/juce_mac_ClangBugWorkaround.h index 0eac3a315e..eb02c1710e 100644 --- a/modules/juce_core/native/juce_mac_ClangBugWorkaround.h +++ b/modules/juce_core/native/juce_mac_ClangBugWorkaround.h @@ -20,10 +20,10 @@ ============================================================================== */ - -// This hack is a workaround for a bug (?) in Apple's 10.11 SDK headers -// which cause some configurations of Clang to throw out a spurious error.. #if JUCE_PROJUCER_LIVE_BUILD && (defined (__APPLE_CPP__) || defined(__APPLE_CC__)) + + // This hack is a workaround for a bug (?) in Apple's 10.11 SDK headers + // which cause some configurations of Clang to throw out a spurious error.. #include #undef CF_OPTIONS #define CF_OPTIONS(_type, _name) _type _name; enum @@ -33,93 +33,9 @@ #define _Nullable #define _Nonnull - // In later versions of libc++ these methods are defined in the functional header, - // which we don't compile in the live-build engine, so we'll define them here - #if defined (_LIBCPP_VERSION) && _LIBCPP_VERSION >= 7000 - #include - - namespace std { inline namespace __1 { - template - pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 - __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, - _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, - forward_iterator_tag, forward_iterator_tag) - { - if (__first2 == __last2) - return make_pair(__first1, __first1); // Everything matches an empty sequence - while (true) - { - // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks - while (true) - { - if (__first1 == __last1) // return __last1 if no element matches *__first2 - return make_pair(__last1, __last1); - if (__pred(*__first1, *__first2)) - break; - ++__first1; - } - // *__first1 matches *__first2, now match elements after here - _ForwardIterator1 __m1 = __first1; - _ForwardIterator2 __m2 = __first2; - while (true) - { - if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) - return make_pair(__first1, __m1); - if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found - return make_pair(__last1, __last1); - if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 - { - ++__first1; - break; - } // else there is a match, check next elements - } - } - } - - template - _LIBCPP_CONSTEXPR_AFTER_CXX11 - pair<_RandomAccessIterator1, _RandomAccessIterator1> - __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, - _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, - random_access_iterator_tag, random_access_iterator_tag) - { - typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; - typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; - // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern - const _D2 __len2 = __last2 - __first2; - if (__len2 == 0) - return make_pair(__first1, __first1); - const _D1 __len1 = __last1 - __first1; - if (__len1 < __len2) - return make_pair(__last1, __last1); - const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here - - while (true) - { - while (true) - { - if (__first1 == __s) - return make_pair(__last1, __last1); - if (__pred(*__first1, *__first2)) - break; - ++__first1; - } - - _RandomAccessIterator1 __m1 = __first1; - _RandomAccessIterator2 __m2 = __first2; - while (true) - { - if (++__m2 == __last2) - return make_pair(__first1, __first1 + __len2); - ++__m1; // no need to check range on __m1 because __s guarantees we have enough source - if (!__pred(*__m1, *__m2)) - { - ++__first1; - break; - } - } - } - } - } } - #endif + // A workaround for compiling the 10.15 headers with an older compiler version + #undef API_UNAVAILABLE_BEGIN + #define API_UNAVAILABLE_BEGIN(...) + #undef API_UNAVAILABLE_END + #define API_UNAVAILABLE_END #endif diff --git a/modules/juce_core/system/juce_StandardHeader.h b/modules/juce_core/system/juce_StandardHeader.h index 9239d6b9b5..4a1b240bea 100644 --- a/modules/juce_core/system/juce_StandardHeader.h +++ b/modules/juce_core/system/juce_StandardHeader.h @@ -120,11 +120,6 @@ #undef minor #undef KeyPress -// Include a replacement for std::function -#if JUCE_PROJUCER_LIVE_BUILD - #include "../misc/juce_StdFunctionCompat.h" -#endif - //============================================================================== // DLL building settings on Windows #if JUCE_MSVC