Newer
Older
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Templates for selectively including overloaded template functions. -*-C++-*-
/* Copyright 2008 Mike Williams (mwill@jlab.org)
*
* This file is part of qft++.
*
* qft++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qft++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qft++. If not, see <http://www.gnu.org/licenses/>.
*/
// Author: Mike Williams
#ifndef _SelectiveInclusion_H
#define _SelectiveInclusion_H
//_____________________________________________________________________________
/** @file SelectiveInclusion.h
* @brief Utilities for selectively including overloaded template functions.
*/
//_____________________________________________________________________________
using namespace std;
//_____________________________________________________________________________
/** @class DisableIf
* @author Mike Williams
*
* @brief Used to disable overloaded template function given a condition.
*
* DisableIf<condition,T> defines the type Type only if condition is
* @a false. Thus, this template can be used to disable an overloaded template
* function when the condition is @a true.
*
* <b> Example </b>
*
* \include DisableIf.ex
*/
//_____________________________________________________________________________
// default template: (this will be used for condition = false)
template <bool _condition, typename _Tp = void> class DisableIf {
public:
/// Only defined if condition is false
typedef _Tp Type;
};
//_____________________________________________________________________________
#ifndef DOXYGEN_SKIP_THIS
// specification for true:
template <typename _Tp> class DisableIf<true,_Tp>{};
#endif /* DOXYGEN_SKIP_THIS */
//_____________________________________________________________________________
/** @class EnableIf
* @author Mike Williams
*
* @brief Used to enable overloaded template function given a condition.
*
* EnableIf<condition,T> defines the type Type only if condition is
* @a true. Thus, this template can be used to enable an overloaded template
* function when the condition is @a true.
*
* <b> Example </b>
*
* \include EnableIf.ex
*/
//_____________________________________________________________________________
// default template: (this will be used for condition = true)
template <bool _condition, typename _Tp = void> class EnableIf {
public:
/// Only defined if condition is true
typedef _Tp Type;
};
//_____________________________________________________________________________
#ifndef DOXYGEN_SKIP_THIS
// specification for false:
template <typename _Tp> class EnableIf<false,_Tp>{};
#endif /* DOXYGEN_SKIP_THIS */
//_____________________________________________________________________________
#endif /* _SelectiveInclusion_H */