MLPACK
1.0.4
|
00001 00025 #ifndef __MLPACK_CORE_SFINAE_UTILITY 00026 #define __MLPACK_CORE_SFINAE_UTILITY 00027 00028 #include <boost/utility/enable_if.hpp> 00029 #include <boost/type_traits.hpp> 00030 00031 /* 00032 * Constructs a template supporting the SFINAE pattern. 00033 * 00034 * This macro generates a template struct that is useful for enabling/disabling 00035 * a method if the template class passed in contains a member function matching 00036 * a given signature with a specified name. 00037 * 00038 * The generated struct should be used in conjunction with boost::disable_if and 00039 * boost::enable_if. Here is an example usage: 00040 * 00041 * For general references, see: 00042 * http://stackoverflow.com/a/264088/391618 00043 * 00044 * For an MLPACK specific use case, see /mlpack/core/util/prefixedoutstream.hpp 00045 * and /mlpack/core/util/prefixedoutstream_impl.hpp 00046 * 00047 * @param NAME the name of the struct to construct. For example: HasToString 00048 * @param FUNC the name of the function to check for. For example: ToString 00049 */ 00050 #define HAS_MEM_FUNC(FUNC, NAME) \ 00051 template<typename T, typename sig> \ 00052 struct NAME { \ 00053 typedef char yes[1]; \ 00054 typedef char no [2]; \ 00055 template<typename U, U> struct type_check; \ 00056 template<typename _1> static yes &chk(type_check<sig, &_1::FUNC> *); \ 00057 template<typename > static no &chk(...); \ 00058 static bool const value = sizeof(chk<T>(0)) == sizeof(yes); \ 00059 }; 00060 00061 #endif