mlpack 3.4.2
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 <boost/serialization/serialization.hpp>
18#include <boost/archive/xml_oarchive.hpp>
19#include <type_traits>
20
21namespace mlpack {
22namespace data {
23
24// This gives us a HasSerializeCheck<T, U> type (where U is a function pointer)
25// we can use with SFINAE to catch when a type has a Serialize() function.
26HAS_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.
30template<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<T, NonStaticSerialize>::value ||
41 HasSerializeCheck<T, StaticSerialize>::value;
42};
43
44template<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<U,
53 typename std::enable_if_t<std::is_class<U>::value>*,
55 template<typename > static no& chk(...); // This matches non-classes.
56
57 static const bool value = (sizeof(chk<T>(0)) == sizeof(yes));
58};
59
60} // namespace data
61} // namespace mlpack
62
63#endif
HAS_EXACT_METHOD_FORM(serialize, HasSerializeCheck)
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
typename enable_if< B, T >::type enable_if_t
Definition: prereqs.hpp:70
void(C::*)(boost::archive::xml_oarchive &, const unsigned int) NonStaticSerialize
void(*)(boost::archive::xml_oarchive &, const unsigned int) StaticSerialize
static yes & chk(check< U, typename std::enable_if_t< std::is_class< U >::value > *, typename std::enable_if_t< HasSerializeFunction< U >::value > * > *)