X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/bc37fe765c04a93a0a7e9c5530558aa38589b70c..377d2091c1e0f30ef48fb068f672ae624ad59d0f:/include/xbt/functional.hpp diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index 99cba0d7e1..10c16bf98a 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -39,11 +39,12 @@ public: {} void operator()() const { + char noarg[] = {'\0'}; const int argc = args_->size(); std::vector args = *args_; std::unique_ptr argv(new char*[argc + 1]); for (int i = 0; i != argc; ++i) - argv[i] = args[i].empty() ? const_cast(""): &args[i].front(); + argv[i] = args[i].empty() ? noarg : &args[i].front(); argv[argc] = nullptr; code_(argc, argv.get()); } @@ -78,7 +79,7 @@ constexpr auto apply(F&& f, Tuple&& t, simgrid::xbt::index_sequence) * * auto args = std::make_tuple(1, false); * int res = apply(foo, args); - * @encode + * @endcode **/ template constexpr auto apply(F&& f, Tuple&& t) @@ -114,11 +115,23 @@ private: struct whatever {}; // Union used for storage: +#if 0 typedef typename std::aligned_union<0, void*, std::pair, std::pair >::type TaskUnion; +#else + union TaskUnion { + void* ptr; + std::pair funcptr; + std::pair memberptr; + char any1[sizeof(std::pair)]; + char any2[sizeof(std::pair)]; + TaskUnion() {} + ~TaskUnion() {} + }; +#endif // Is F suitable for small buffer optimization? template @@ -228,7 +241,7 @@ private: [](TaskUnion& buffer, Args... args) -> R { // Delete F when we go out of scope: std::unique_ptr code(*reinterpret_cast(&buffer)); - (*code)(std::forward(args)...); + return (*code)(std::forward(args)...); }, // Destroy: [](TaskUnion& buffer) {