blob: 4f21f9b69ce3ad86781f682ec813cbc533e70690 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_NUM_NONNEGATIVE_WEIGHtS_Hh_
#define DLIB_NUM_NONNEGATIVE_WEIGHtS_Hh_
#include "../enable_if.h"
namespace dlib
{
namespace impl2
{
template <
typename T,
unsigned long (T::*funct)()const
>
struct hnnf_helper
{
typedef char type;
};
template <typename T>
char has_num_nonnegative_weights_helper( typename hnnf_helper<T,&T::num_nonnegative_weights>::type = 0 ) { return 0;}
struct two_bytes
{
char a[2];
};
template <typename T>
two_bytes has_num_nonnegative_weights_helper(int) { return two_bytes();}
template <typename T>
struct work_around_visual_studio_bug
{
const static unsigned long U = sizeof(has_num_nonnegative_weights_helper<T>('a'));
};
// This is a template to tell you if a feature_extractor has a num_nonnegative_weights function or not.
template <typename T, unsigned long U = work_around_visual_studio_bug<T>::U >
struct has_num_nonnegative_weights
{
static const bool value = false;
};
template <typename T>
struct has_num_nonnegative_weights <T,1>
{
static const bool value = true;
};
}
// call fe.num_nonnegative_weights() if it exists, otherwise return 0.
template <typename feature_extractor>
typename enable_if<impl2::has_num_nonnegative_weights<feature_extractor>,unsigned long>::type num_nonnegative_weights (
const feature_extractor& fe
)
{
return fe.num_nonnegative_weights();
}
template <typename feature_extractor>
typename disable_if<impl2::has_num_nonnegative_weights<feature_extractor>,unsigned long>::type num_nonnegative_weights (
const feature_extractor& /*fe*/
)
{
return 0;
}
}
#endif // DLIB_NUM_NONNEGATIVE_WEIGHtS_Hh_
|