///////////////////////////////////////////////////////////////////////////// // Copyright (c) Electronic Arts Inc. All rights reserved. ///////////////////////////////////////////////////////////////////////////// #ifndef EASTL_FUNCTION_H #define EASTL_FUNCTION_H #if defined(EA_PRAGMA_ONCE_SUPPORTED) #pragma once #endif #include namespace eastl { /// EASTL_FUNCTION_DEFAULT_CAPTURE_SSO_SIZE /// /// Defines the size of the SSO buffer which is used to hold the specified capture state of the callable. /// #ifndef EASTL_FUNCTION_DEFAULT_CAPTURE_SSO_SIZE #define EASTL_FUNCTION_DEFAULT_CAPTURE_SSO_SIZE (2 * sizeof(void*)) #endif static_assert(EASTL_FUNCTION_DEFAULT_CAPTURE_SSO_SIZE >= sizeof(void*), "functor storage must be able to hold at least a pointer!"); template class function; template class function : public internal::function_detail { private: using Base = internal::function_detail; public: using typename Base::result_type; function() EA_NOEXCEPT = default; function(std::nullptr_t p) EA_NOEXCEPT : Base(p) { } function(const function& other) : Base(other) { } function(function&& other) : Base(eastl::move(other)) { } template function(Functor functor) : Base(eastl::move(functor)) { } ~function() EA_NOEXCEPT = default; function& operator=(const function& other) { Base::operator=(other); return *this; } function& operator=(function&& other) { Base::operator=(eastl::move(other)); return *this; } function& operator=(std::nullptr_t p) EA_NOEXCEPT { Base::operator=(p); return *this; } template function& operator=(Functor&& functor) { Base::operator=(eastl::forward(functor)); return *this; } template function& operator=(eastl::reference_wrapper f) EA_NOEXCEPT { Base::operator=(f); return *this; } void swap(function& other) EA_NOEXCEPT { Base::swap(other); } explicit operator bool() const EA_NOEXCEPT { return Base::operator bool(); } R operator ()(Args... args) const { return Base::operator ()(eastl::forward(args)...); } #if EASTL_RTTI_ENABLED const std::type_info& target_type() const EA_NOEXCEPT { return Base::target_type(); } template Functor* target() EA_NOEXCEPT { return Base::target(); } template const Functor* target() const EA_NOEXCEPT { return Base::target(); } #endif // EASTL_RTTI_ENABLED }; template bool operator==(const function& f, std::nullptr_t) EA_NOEXCEPT { return !f; } template bool operator==(std::nullptr_t, const function& f) EA_NOEXCEPT { return !f; } template bool operator!=(const function& f, std::nullptr_t) EA_NOEXCEPT { return !!f; } template bool operator!=(std::nullptr_t, const function& f) EA_NOEXCEPT { return !!f; } template void swap(function& lhs, function& rhs) { lhs.swap(rhs); } } // namespace eastl #endif // EASTL_FUNCTION_H