mlpack
|
#include <type_traits>
#include <cstring>
Go to the source code of this file.
Namespaces | |
mlpack | |
Linear algebra utility functions, generally performed on matrices or vectors. | |
Macros | |
#define | HAS_MEM_FUNC(FUNC, NAME) |
#define | HAS_METHOD_FORM_BASE(METHOD, NAME, MAXN) |
Base macro for HAS_METHOD_FORM() and HAS_EXACT_METHOD_FORM() macros. | |
#define | HAS_ANY_METHOD_FORM(FUNC, NAME) |
Constructs a template structure, which will define a boolean static variable, to true, if the passed template parameter, has a member function with the specified name. More... | |
#define | SINGLE_ARG(...) __VA_ARGS__ |
#define | HAS_METHOD_FORM(METHOD, NAME) HAS_METHOD_FORM_BASE(SINGLE_ARG(METHOD), SINGLE_ARG(NAME), 7) |
HAS_METHOD_FORM generates a template that allows a compile time check for whether a given class has a method of the requested form. More... | |
#define | HAS_EXACT_METHOD_FORM(METHOD, NAME) HAS_METHOD_FORM_BASE(SINGLE_ARG(METHOD), SINGLE_ARG(NAME), 0) |
HAS_EXACT_METHOD_FORM generates a template that allows a compile time check whether a given class has a method of the requested form. More... | |
This file contains macro utilities for the SFINAE Paradigm. These utilities determine if classes passed in as template parameters contain members at compile time, which is useful for changing functionality depending on what operations an object is capable of performing.
mlpack is free software; you may redistribute it and/or modify it under the terms of the 3-clause BSD license. You should have received a copy of the 3-clause BSD license along with mlpack. If not, see http://www.opensource.org/licenses/BSD-3-Clause for more information.
#define HAS_ANY_METHOD_FORM | ( | FUNC, | |
NAME | |||
) |
Constructs a template structure, which will define a boolean static variable, to true, if the passed template parameter, has a member function with the specified name.
The check does not care about the signature or the function parameters.
FUNC | the name of the function, whose existence is to be detected |
NAME | the name of the structure that will be generated |
Use this like: NAME<ClassName>::value to check for the existence of the function in the given class name. This can also be used in conjunction with std::enable_if.
#define HAS_EXACT_METHOD_FORM | ( | METHOD, | |
NAME | |||
) | HAS_METHOD_FORM_BASE(SINGLE_ARG(METHOD), SINGLE_ARG(NAME), 0) |
HAS_EXACT_METHOD_FORM generates a template that allows a compile time check whether a given class has a method of the requested form.
For example, for the following class
class A { public: ... Train(const arma::mat&, const arma::Row<size_t>&); ... };
and the following form of Train methods
template<typename Class> using TrainForm = void(Class::*)(const arma::mat&, const arma::Row<size_t>&);
we can check whether the class A has a Train method of the specified form:
HAS_METHOD_FORM(Train, HasTrain); static_assert(HasTrain<A, TrainFrom>::value, "value should be true");
The class generated by this will only return true values if the signature matches exactly.
METHOD | The name of the method to check for. |
NAME | The name of the struct to construct. |
#define HAS_MEM_FUNC | ( | FUNC, | |
NAME | |||
) |
#define HAS_METHOD_FORM | ( | METHOD, | |
NAME | |||
) | HAS_METHOD_FORM_BASE(SINGLE_ARG(METHOD), SINGLE_ARG(NAME), 7) |
HAS_METHOD_FORM generates a template that allows a compile time check for whether a given class has a method of the requested form.
For example, for the following class
class A { public: ... Train(const arma::mat&, const arma::Row<size_t>&, double); ... };
and the following form of Train methods
template<typename Class, typename...Ts> using TrainForm = void(Class::*)(const arma::mat&, const arma::Row<size_t>&, Ts...);
we can check whether the class A has a Train method of the specified form:
HAS_METHOD_FORM(Train, HasTrain); static_assert(HasTrain<A, TrainFrom>::value, "value should be true");
The class generated by this will also return true values if the given class has a method that also has extra parameters.
METHOD | The name of the method to check for. |
NAME | The name of the struct to construct. |