KaMPIng 0.1.1
Flexible and (near) zero-overhead C++ bindings for MPI
Loading...
Searching...
No Matches
named_parameter_check.hpp File Reference

Template magic to check named parameters passed to wrappers at compile time. More...

#include <tuple>
#include <type_traits>
#include "kamping/named_parameter_selection.hpp"
#include "kamping/named_parameter_types.hpp"
#include "kamping/serialization.hpp"
Include dependency graph for named_parameter_check.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  kamping::internal::has_no_unused_parameters< RequiredParametersTuple, OptionalParametersTuple, Args >
 Struct wrapping a check that verifies that no unused parameters are part of the arguments. More...
 
struct  kamping::internal::all_unique< Tuple >
 Base wrapper (std::integral_constant) to test if all types of a tuple are unique. More...
 
struct  kamping::internal::all_unique< std::tuple< T, Ts... > >
 Recursive wrapper (std::integral_constant) to test if all types of a tuple are unique. This is done by checking for each type whether the type occurs in the types of the tuple to the right. If this is true for any type/position, the types in the tuple are not unique. More...
 
struct  kamping::internal::parameter_type_to_integral_constant< T >
 Wrapper to get an std::integral_constant for a kamping::internal::ParameterType. More...
 
struct  kamping::internal::parameter_types_to_integral_constants< ParameterTypes >
 Wrapper to get a tuple of std::integral_constant for each kamping::internal::ParameterType passed as template parameter that are extracted as tuple of std::integral_constant. More...
 
struct  kamping::internal::parameters_to_integral_constant< Parameters >
 Wrapper to get a tuple of std::integral_constant for each kamping::internal::ParameterType of the parameters. More...
 

Namespaces

namespace  kamping::internal
 Internal namespace marking the code that is not user-facing.
 

Macros

#define KAMPING_REQUIRED_PARAMETERS(...)   , ##__VA_ARGS__
 Wrapper to pass (possibly empty) list of parameter type names as required parameters to KAMPING_CHECK_PARAMETERS. Note that this macro only takes the name of parameter types, i.e., instead of using kamping::internal::ParameterType::send_buf, only pass send_buf to this macro.
 
#define KAMPING_OPTIONAL_PARAMETERS(...)   , ##__VA_ARGS__
 Wrapper to pass (possibly empty) list of parameter type names as optional parameters to KAMPING_CHECK_PARAMETERS. Note that this macro only takes the name of parameter types, i.e., instead of using kamping::internal::ParameterType::send_buf, only pass send_buf to this macro.
 
#define KAMPING_CHECK_PARAMETERS(args, required, optional)
 Assertion macro that checks if passed parameters are correct, i.e., all parameter types are unique, all required parameters are provided, and no unused parameter is passed. Also checks that all parameter types are r-value references.
 

Variables

template<typename Tuple >
static constexpr bool kamping::internal::all_unique_v = all_unique<Tuple>::value
 true if and only if all types of the tuple are unique.
 
template<ParameterType parameter_type, typename... Args>
static constexpr bool kamping::internal::is_parameter_given_as_in_buffer
 Checks if a data buffer with requested parameter type exists and it is an input parameter (i.e. its content does not have to be computed/deduced by KaMPIng).
 
template<typename BufferType >
static constexpr bool kamping::internal::has_to_be_computed
 Checks if the buffer has to be computed by kamping, i.e. if it is an output parameter or the buffer has been allocated by KaMPIng.
 
template<typename... BufferTypes>
static constexpr bool kamping::internal::all_have_to_be_computed = (has_to_be_computed<BufferTypes> && ...)
 Checks if all buffers have to be computed by kamping, i.e., if all buffers are output parameters of the buffers have been allocated by kamping.
 
template<typename... BufferTypes>
static constexpr bool kamping::internal::any_has_to_be_computed = (has_to_be_computed<BufferTypes> || ...)
 Checks if any of the buffers have to be computed by kamping, i.e., if at least one buffer is an output parameter or has been allocated by kamping.
 
template<typename DataBufferType >
static constexpr bool kamping::internal::buffer_uses_serialization
 Checks if DataBufferType is a serialization buffer.
 

Detailed Description

Template magic to check named parameters passed to wrappers at compile time.

Macro Definition Documentation

◆ KAMPING_CHECK_PARAMETERS

#define KAMPING_CHECK_PARAMETERS ( args,
required,
optional )
Value:
do { \
KAMPING_PARAMETER_CHECK_HPP_ASSERT_REQUIRED_PARAMETERS(args, required); \
\
using required_parameters_types = typename kamping::internal::parameter_types_to_integral_constants< \
KAMPING_PARAMETER_CHECK_HPP_PREFIX_PARAMETERS(required)>::type; \
using optional_parameters_types = typename kamping::internal::parameter_types_to_integral_constants< \
KAMPING_PARAMETER_CHECK_HPP_PREFIX_PARAMETERS(optional)>::type; \
using parameter_types = typename kamping::internal::parameters_to_integral_constant<args...>::type; \
static_assert( \
has_no_unused_parameters<required_parameters_types, optional_parameters_types, args...>::assertion, \
"There are unsupported parameters, only support required " \
"parameters " KAMPING_PARAMETER_CHECK_HPP_EVAL_STRINGIFY(required \
) " and optional parameters " KAMPING_PARAMETER_CHECK_HPP_EVAL_STRINGIFY(optional) \
); \
static_assert(kamping::internal::all_unique_v<parameter_types>, "There are duplicate parameter types."); \
} while (false)
Internal namespace marking the code that is not user-facing.
Definition collectives_helpers.hpp:20
Wrapper to get a tuple of std::integral_constant for each kamping::internal::ParameterType passed as ...
Definition named_parameter_check.hpp:358
Wrapper to get a tuple of std::integral_constant for each kamping::internal::ParameterType of the par...
Definition named_parameter_check.hpp:369

Assertion macro that checks if passed parameters are correct, i.e., all parameter types are unique, all required parameters are provided, and no unused parameter is passed. Also checks that all parameter types are r-value references.

The macro only expects the parameter type, i.e., a member name of the kamping::internal::ParameterType enum without the name of the enum. For instance,

++
#define KAMPING_REQUIRED_PARAMETERS(...)
Wrapper to pass (possibly empty) list of parameter type names as required parameters to KAMPING_CHECK...
Definition named_parameter_check.hpp:52
#define KAMPING_OPTIONAL_PARAMETERS(...)
Wrapper to pass (possibly empty) list of parameter type names as optional parameters to KAMPING_CHECK...
Definition named_parameter_check.hpp:58
#define KAMPING_CHECK_PARAMETERS(args, required, optional)
Assertion macro that checks if passed parameters are correct, i.e., all parameter types are unique,...
Definition named_parameter_check.hpp:80

checks that the parameter pack Args contains members of type kamping::internal::ParameterType::send_buf and type kamping::internal::ParameterType::recv_buf.

Note that expanding the macro into a do { ... } while(false) pseudo-loop is a common trick to make a macro "act like a statement". Otherwise, it would have surprising effects if the macro is used inside a if branch without braces.

Parameters
argsA parameter pack with all parameter types passed to the function. Note that this is only the name of the parameter pack without trailing ....
requiredA list of required parameter type names wrapped in a KAMPING_REQUIRED_PARAMETERS macro.
optionalA list of optional parameter type names wrapped in a KAMPING_OPTIONAL_PARAMETERS macro.