// StreamUtils - github.com/bblanchon/ArduinoStreamUtils // Copyright Benoit Blanchon 2019-2021 // MIT License #pragma once namespace StreamUtils { namespace Polyfills { template struct remove_reference { using type = T; }; template struct remove_reference { using type = T; }; template typename remove_reference::type &&move(T &&t) { return static_cast::type &&>(t); } // poor man's std::function class function { struct callable_base { virtual void operator()() = 0; virtual ~callable_base() {} }; template struct callable : callable_base { Functor functor; callable(Functor functor) : functor(functor) {} virtual void operator()() { functor(); } }; callable_base *_callable; public: template function(Functor f) { _callable = new callable(f); } function(function &&src) { _callable = src._callable, src._callable = 0; } ~function() { delete _callable; } void operator()() const { (*_callable)(); } }; } // namespace Polyfills } // namespace StreamUtils