From: Martin Quinson Date: Tue, 14 Aug 2018 23:58:58 +0000 (+0200) Subject: do not reimplement (poorly) std::bind X-Git-Tag: v3_21~249 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/da782b62777961ea5041717ec5ae80248d6d5785 do not reimplement (poorly) std::bind (and move deprecated symbols by the end of this file) --- diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index a0c4f26500..48803e619e 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -51,29 +51,6 @@ public: code_(argc, nullptr); } }; -class MainStdFunction { -private: - void (*code_)(std::vector); - std::shared_ptr> args_; - -public: - MainStdFunction(void (*code)(std::vector), std::vector args) - : code_(std::move(code)), args_(std::make_shared>(std::move(args))) - { - } - void operator()() const - { - std::vector args = *args_; - code_(args); - } -}; - -template -inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain( - F code, std::vector args) -{ - return MainFunction(std::move(code), std::move(args)); -} template inline std::function wrap_main(F code, std::vector args) { @@ -81,16 +58,9 @@ template inline std::function wrap_main(F code, std::vector wrap_main(void (*code)(std::vector), std::vector args) { - return MainStdFunction(std::move(code), std::move(args)); + return std::bind(std::move(code), std::move(args)); } -template -inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain(F code, int argc, - const char* const argv[]) -{ - std::vector args(argv, argv + argc); - return MainFunction(std::move(code), std::move(args)); -} template inline std::function wrap_main(F code, int argc, const char* const argv[]) { std::vector args(argv, argv + argc); @@ -320,20 +290,36 @@ public: } }; -template -XBT_ATTRIB_DEPRECATED_v323("Please use make_task()") auto makeTask(F code, Args... args) - -> Task +template auto make_task(F code, Args... args) -> Task { TaskImpl task(std::move(code), std::make_tuple(std::move(args)...)); return Task(std::move(task)); } -template auto make_task(F code, Args... args) -> Task +// Deprecated +template +XBT_ATTRIB_DEPRECATED_v323("Please use make_task()") auto makeTask(F code, Args... args) + -> Task { TaskImpl task(std::move(code), std::make_tuple(std::move(args)...)); return Task(std::move(task)); } + +template +inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain( + F code, std::vector args) +{ + return MainFunction(std::move(code), std::move(args)); } + +template +inline XBT_ATTRIB_DEPRECATED_v323("Please use wrap_main()") std::function wrapMain(F code, int argc, + const char* const argv[]) +{ + std::vector args(argv, argv + argc); + return MainFunction(std::move(code), std::move(args)); } +} // namespace xbt +} // namespace simgrid #endif