Home
Get Started
Documentation
Community
Google Summer of Code
FAQ
GitHub
Home
Get Started
Documentation
Community
Google Summer of Code
FAQ
GitHub
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
16
#include <
mlpack/core/util/sfinae_utility.hpp
>
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>
31
struct
HasSerializeFunction
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>
45
struct
HasSerialize
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>*,
54
typename
std::enable_if_t
<
HasSerializeFunction
::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
mlpack::data::HasSerializeFunction::value
static const bool value
Definition:
has_serialize.hpp:40
std::enable_if_t
typename enable_if< B, T >::type enable_if_t
Definition:
prereqs.hpp:70
mlpack::data::HasSerialize
Definition:
has_serialize.hpp:45
mlpack
Linear algebra utility functions, generally performed on matrices or vectors.
Definition:
add_to_cli11.hpp:21
sfinae_utility.hpp
mlpack::data::HasSerializeFunction
Definition:
has_serialize.hpp:31
mlpack::data::HAS_EXACT_METHOD_FORM
HAS_EXACT_METHOD_FORM(serialize, HasSerializeCheck)
mlpack::data::HasSerializeFunction::NonStaticSerialize
void(C::*)(boost::archive::xml_oarchive &, const unsigned int) NonStaticSerialize
Definition:
has_serialize.hpp:35
mlpack::data::HasSerializeFunction::StaticSerialize
void(*)(boost::archive::xml_oarchive &, const unsigned int) StaticSerialize
Definition:
has_serialize.hpp:38
mlpack::data::HasSerialize::check
Definition:
has_serialize.hpp:50