Go to the source code of this file.
Classes | |
struct | MethodFormDetector< Class, MethodForm, AdditionalArgsCount > |
struct | MethodFormDetector< Class, MethodForm, 0 > |
struct | MethodFormDetector< Class, MethodForm, 1 > |
struct | MethodFormDetector< Class, MethodForm, 2 > |
struct | MethodFormDetector< Class, MethodForm, 3 > |
struct | MethodFormDetector< Class, MethodForm, 4 > |
struct | MethodFormDetector< Class, MethodForm, 5 > |
struct | MethodFormDetector< Class, MethodForm, 6 > |
struct | MethodFormDetector< Class, MethodForm, 7 > |
struct | SigCheck< U, U > |
Utility struct for checking signatures. More... | |
Namespaces | |
mlpack | |
Linear algebra utility functions, generally performed on matrices or vectors. | |
mlpack::sfinae | |
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 | 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... | |
#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. More... | |
#define | HAS_METHOD_FORM_BASE(METHOD, NAME, MAXN) |
Base macro for HAS_METHOD_FORM() and HAS_EXACT_METHOD_FORM() macros. More... | |
#define | SINGLE_ARG(...) __VA_ARGS__ |
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.
Definition in file sfinae_utility.hpp.
#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.
Definition at line 201 of file sfinae_utility.hpp.
#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
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. |
Definition at line 285 of file sfinae_utility.hpp.
#define HAS_MEM_FUNC | ( | FUNC, | |
NAME | |||
) |
Definition at line 128 of file sfinae_utility.hpp.
#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. |
Definition at line 252 of file sfinae_utility.hpp.
#define HAS_METHOD_FORM_BASE | ( | METHOD, | |
NAME, | |||
MAXN | |||
) |
Base macro for HAS_METHOD_FORM() and HAS_EXACT_METHOD_FORM() macros.
Definition at line 143 of file sfinae_utility.hpp.
#define SINGLE_ARG | ( | ... | ) | __VA_ARGS__ |
Definition at line 220 of file sfinae_utility.hpp.