MLPACK
1.0.11
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
mlpack
core
util
sfinae_utility.hpp
Go to the documentation of this file.
1
25
#ifndef __MLPACK_CORE_SFINAE_UTILITY
26
#define __MLPACK_CORE_SFINAE_UTILITY
27
28
#include <boost/utility/enable_if.hpp>
29
#include <boost/type_traits.hpp>
30
#include <
mlpack/prereqs.hpp
>
31
32
/*
33
* Constructs a template supporting the SFINAE pattern.
34
*
35
* This macro generates a template struct that is useful for enabling/disabling
36
* a method if the template class passed in contains a member function matching
37
* a given signature with a specified name.
38
*
39
* The generated struct should be used in conjunction with boost::disable_if and
40
* boost::enable_if. Here is an example usage:
41
*
42
* For general references, see:
43
* http://stackoverflow.com/a/264088/391618
44
*
45
* For an MLPACK specific use case, see /mlpack/core/util/prefixedoutstream.hpp
46
* and /mlpack/core/util/prefixedoutstream_impl.hpp
47
*
48
* @param NAME the name of the struct to construct. For example: HasToString
49
* @param FUNC the name of the function to check for. For example: ToString
50
*/
51
#define HAS_MEM_FUNC(FUNC, NAME) \
52
template<typename T, typename sig> \
53
struct NAME { \
54
typedef char yes[1]; \
55
typedef char no [2]; \
56
template<typename U, U> struct type_check; \
57
template<typename _1> static yes &chk(type_check<sig, &_1::FUNC> *); \
58
template<typename > static no &chk(...); \
59
static bool const value = sizeof(chk<T>(0)) == sizeof(yes); \
60
};
61
62
#endif
prereqs.hpp
The core includes that mlpack expects; standard C++ includes and Armadillo.
Generated by
1.8.6