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