diff --git a/runtime/Cpp/runtime/src/antlr4-common.h b/runtime/Cpp/runtime/src/antlr4-common.h index 47312978a..020c6a560 100644 --- a/runtime/Cpp/runtime/src/antlr4-common.h +++ b/runtime/Cpp/runtime/src/antlr4-common.h @@ -34,7 +34,6 @@ #include #include #include -#include #ifndef USE_UTF8_INSTEAD_OF_CODECVT #include diff --git a/runtime/Cpp/runtime/src/support/CPPUtils.cpp b/runtime/Cpp/runtime/src/support/CPPUtils.cpp index 86a3751a2..496f6c932 100755 --- a/runtime/Cpp/runtime/src/support/CPPUtils.cpp +++ b/runtime/Cpp/runtime/src/support/CPPUtils.cpp @@ -202,12 +202,6 @@ namespace antlrcpp { return result; } - //----------------- FinallyAction ------------------------------------------------------------------------------------ - - FinalAction finally(std::function f) { - return FinalAction(f); - } - //----------------- SingleWriteMultipleRead -------------------------------------------------------------------------- void SingleWriteMultipleReadLock::readLock() { diff --git a/runtime/Cpp/runtime/src/support/CPPUtils.h b/runtime/Cpp/runtime/src/support/CPPUtils.h index fc83503cf..5f2ad609f 100644 --- a/runtime/Cpp/runtime/src/support/CPPUtils.h +++ b/runtime/Cpp/runtime/src/support/CPPUtils.h @@ -19,8 +19,9 @@ namespace antlrcpp { std::string indent(const std::string &s, const std::string &indentation, bool includingFirst = true); // Using RAII + a lambda to implement a "finally" replacement. + template struct FinalAction { - FinalAction(std::function f) : _cleanUp { f } {} + FinalAction(OnEnd f) : _cleanUp { std::move(f) } {} FinalAction(FinalAction &&other) : _cleanUp(std::move(other._cleanUp)), _enabled(other._enabled) { other._enabled = false; // Don't trigger the lambda after ownership has moved. @@ -29,11 +30,14 @@ namespace antlrcpp { void disable() { _enabled = false; } private: - std::function _cleanUp; + OnEnd _cleanUp; bool _enabled {true}; }; - ANTLR4CPP_PUBLIC FinalAction finally(std::function f); + template + FinalAction finally(OnEnd f) { + return FinalAction(std::move(f)); + } // Convenience functions to avoid lengthy dynamic_cast() != nullptr checks in many places. template