X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/056b1668e0d3af35c8d35b88694a65c23fbbd6ca..35bf365de6be434aeeafa8b3d5f5c9a1e3082ce3:/include/xbt/functional.hpp diff --git a/include/xbt/functional.hpp b/include/xbt/functional.hpp index f4065f8e35..9d1b337c49 100644 --- a/include/xbt/functional.hpp +++ b/include/xbt/functional.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -23,8 +23,7 @@ #include #include -namespace simgrid { -namespace xbt { +namespace simgrid::xbt { template class MainFunction { F code_; @@ -37,11 +36,10 @@ public: } void operator()() const { - const int argc = args_->size(); std::vector args = *args_; std::vector argv(args.size() + 1); // argv[argc] is nullptr std::transform(begin(args), end(args), begin(argv), [](std::string& s) { return &s.front(); }); - code_(argc, argv.data()); + code_(static_cast(args.size()), argv.data()); } }; @@ -75,12 +73,12 @@ constexpr auto apply(F&& f, Tuple&& t, std::index_sequence) * @endcode **/ template -constexpr auto apply(F&& f, Tuple&& t) -> decltype( - simgrid::xbt::bits::apply(std::forward(f), std::forward(t), - std::make_index_sequence>::value>())) +constexpr auto apply(F&& f, Tuple&& t) + -> decltype(simgrid::xbt::bits::apply(std::forward(f), std::forward(t), + std::make_index_sequence>>())) { return simgrid::xbt::bits::apply(std::forward(f), std::forward(t), - std::make_index_sequence>::value>()); + std::make_index_sequence>>()); } template class Task; @@ -168,7 +166,7 @@ public: } private: - template typename std::enable_if_t()> init(F code) + template typename std::enable_if_t()> init(F task_code) { const static TaskVtable vtable { // Call: @@ -180,7 +178,7 @@ private: return code(std::forward(args)...); }, // Destroy: - std::is_trivially_destructible::value ? + std::is_trivially_destructible_v ? static_cast(nullptr) : [](TaskUnion& buffer) { auto* code = reinterpret_cast(&buffer); @@ -194,11 +192,11 @@ private: src_code->~F(); } }; - new(&buffer_) F(std::move(code)); + new (&buffer_) F(std::move(task_code)); vtable_ = &vtable; } - template typename std::enable_if_t()> init(F code) + template typename std::enable_if_t()> init(F task_code) { const static TaskVtable vtable { // Call: @@ -216,7 +214,7 @@ private: // Move: nullptr }; - *reinterpret_cast(&buffer_) = new F(std::move(code)); + *reinterpret_cast(&buffer_) = new F(std::move(task_code)); vtable_ = &vtable; } @@ -261,6 +259,5 @@ template auto make_task(F code, Args... args) -> Task(std::move(task)); } -} // namespace xbt -} // namespace simgrid +} // namespace simgrid::xbt #endif