has_serialize.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_UTIL_HAS_SERIALIZE_HPP
14 #define MLPACK_CORE_UTIL_HAS_SERIALIZE_HPP
15 
17 #include
18 #include
19 #include
20 
21 namespace mlpack {
22 namespace data {
23 
24 // This gives us a HasSerializeCheck type (where U is a function pointer)
25 // we can use with SFINAE to catch when a type has a Serialize() function.
26 HAS_EXACT_METHOD_FORM(serialize, HasSerializeCheck);
27 
28 // Don't call this with a non-class. HasSerializeFunction::value is true if the
29 // type T has a static or non-static Serialize() function.
30 template<typename T>
32 {
33  template<typename C>
34  using NonStaticSerialize = void(C::*)(boost::archive::xml_oarchive&,
35  const unsigned int);
36  template<typename /* C */>
37  using StaticSerialize = void(*)(boost::archive::xml_oarchive&,
38  const unsigned int);
39 
40  static const bool value = HasSerializeCheck::value ||
41  HasSerializeCheck::value;
42 };
43 
44 template<typename T>
46 {
47  // We have to handle the case where T isn't a class...
48  typedef char yes[1];
49  typedef char no [2];
50  template<typename U, typename V, typename W> struct check;
51  template<typename U> static yes& chk( // This matches classes.
52  check
53  typename std::enable_if_t::value>*,
55  template<typename > static no& chk(...); // This matches non-classes.
56 
57  static const bool value = (sizeof(chk(0)) == sizeof(yes));
58 };
59 
60 } // namespace data
61 } // namespace mlpack
62 
63 #endif
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
Linear algebra utility functions, generally performed on matrices or vectors.
HAS_EXACT_METHOD_FORM(serialize, HasSerializeCheck)
void(C::*)(boost::archive::xml_oarchive &, const unsigned int) NonStaticSerialize
void(*)(boost::archive::xml_oarchive &, const unsigned int) StaticSerialize