KaMPIng 0.1.1
Flexible and (near) zero-overhead C++ bindings for MPI
Loading...
Searching...
No Matches
plugin_helpers.hpp
1// This file is part of KaMPIng.
2//
3// Copyright 2022 The KaMPIng Authors
4//
5// KaMPIng is free software : you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
7// version. KaMPIng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9// for more details.
10//
11// You should have received a copy of the GNU Lesser General Public License along with KaMPIng. If not, see
12// <https://www.gnu.org/licenses/>.
13#pragma once
14
15#include <kamping/named_parameter_filtering.hpp>
16
17namespace kamping::plugin {
18
19/// @brief Helper class for using CRTP for mixins. Which are used to implement kamping plugins.
20///
21/// Taken from https://www.fluentcpp.com/2017/05/19/crtp-helper/
22/// @tparam CommunicatorClass Type of the class we want to add functionality to, i.e. `kamping::Communicator`.
23/// @tparam DefaultContainerType Default container type of Communicator class
24/// @tparam PluginClass Type of the plugin class template which inherits from \c PluginBase and adds functionality to \c
25/// CommunicatorClass.
26template <
27 typename CommunicatorClass,
28 template <typename...>
29 typename DefaultContainerType,
30 template <typename, template <typename...> typename>
31 typename PluginClass>
32struct PluginBase {
33private:
34 /// @return Reference to the underlying Communicator class.
35 CommunicatorClass& to_communicator() {
36 return static_cast<CommunicatorClass&>(*this);
37 }
38
39 /// @return const-reference to the underlying Communicator class.
40 CommunicatorClass const& to_communicator() const {
41 return static_cast<CommunicatorClass const&>(*this);
42 }
43
44 PluginBase() {} ///< private constructor
45 friend PluginClass<CommunicatorClass, DefaultContainerType>; // this allows only the class inheriting from \c
46 // PluginBase to access the functions of this class.
47};
48
49/// @brief Filter the arguments \tparam Args for which the static member function `discard()` of \tparam Predicate
50/// returns true and pack (move) remaining arguments into a tuple.
51template <typename Predicate, typename... Args>
52auto filter_args_into_tuple(Args&&... args) {
53 using namespace kamping::internal;
54 using ArgsToKeep = typename FilterOut<Predicate, std::tuple<Args...>>::type;
56}
57
58} // namespace kamping::plugin
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Internal namespace marking the code that is not user-facing.
Definition collectives_helpers.hpp:20
Base template used to filter a list of types and only keep those whose types meet specified criteria....
Definition named_parameter_filtering.hpp:46
Helper class for using CRTP for mixins. Which are used to implement kamping plugins.
Definition plugin_helpers.hpp:32