STK++ 0.9.13
STK_MetaTemplate.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::
27 * created on: Sep 23, 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
37#ifndef STK_METATEMPLATE_H
38#define STK_METATEMPLATE_H
39
40namespace STK
41{
42namespace hidden
43{
44
45struct TrueType { enum { value = 1 }; };
46struct FalseType { enum { value = 0 }; };
47
48template<bool Condition, typename Then, typename Else>
49struct If;
50
51template<typename Then, typename Else>
52struct If <true, Then, Else> { typedef Then Result; };
53
54template<typename Then, typename Else>
55struct If <false, Then, Else> { typedef Else Result; };
56
57/* C/C++ fundamental Types */
58template<typename T>
59struct IsArithmetic { enum { yes = false, no = true}; };
60
61/* specializations */
62template<> struct IsArithmetic<float> { enum { yes = true, no = false }; };
63template<> struct IsArithmetic<double> { enum { yes = true, no = false }; };
64template<> struct IsArithmetic<long double> { enum { yes = true, no = false }; };
65
66template<> struct IsArithmetic<bool> { enum { yes = true, no = false }; };
67template<> struct IsArithmetic<char> { enum { yes = true, no = false }; };
68template<> struct IsArithmetic<signed char> { enum { yes = true, no = false }; };
69template<> struct IsArithmetic<unsigned char> { enum { yes = true, no = false }; };
70template<> struct IsArithmetic<signed short> { enum { yes = true, no = false }; };
71template<> struct IsArithmetic<unsigned short>{ enum { yes = true, no = false }; };
72template<> struct IsArithmetic<signed int> { enum { yes = true, no = false }; };
73template<> struct IsArithmetic<unsigned int> { enum { yes = true, no = false }; };
74template<> struct IsArithmetic<signed long> { enum { yes = true, no = false }; };
75template<> struct IsArithmetic<unsigned long> { enum { yes = true, no = false }; };
76//template<> struct IsArithmetic<signed long long> { enum { yes = true, no = false }; };
77//template<> struct IsArithmetic<unsigned long long> { enum { yes = true, no = false }; };
78
79/* C/C++ fundamental Types */
80template<typename Type>
81struct IsInt { enum { yes = false, no = true}; };
82
83template<> struct IsInt<bool> { enum { yes = true, no = false }; };
84template<> struct IsInt<char> { enum { yes = true, no = false }; };
85template<> struct IsInt<signed char> { enum { yes = true, no = false }; };
86template<> struct IsInt<unsigned char> { enum { yes = true, no = false }; };
87template<> struct IsInt<signed short> { enum { yes = true, no = false }; };
88template<> struct IsInt<unsigned short>{ enum { yes = true, no = false }; };
89template<> struct IsInt<signed int> { enum { yes = true, no = false }; };
90template<> struct IsInt<unsigned int> { enum { yes = true, no = false }; };
91template<> struct IsInt<signed long> { enum { yes = true, no = false }; };
92template<> struct IsInt<unsigned long> { enum { yes = true, no = false }; };
93//template<> struct IsInt<signed long long> { enum { yes = true, no = false }; };
94//template<> struct IsInt<unsigned long long> { enum { yes = true, no = false }; };
95
96
97// remove const and const& to typename
98template<typename Type_> struct RemoveConst { typedef Type_ Type; };
99template<typename Type_> struct RemoveConst<Type_ const> { typedef typename RemoveConst<Type_>::Type Type; };
100template<typename Type_> struct RemoveConst<Type_ const&> { typedef typename RemoveConst<Type_>::Type Type; };
101
102
103
105template<typename T, typename U> struct isSame { enum { value_ = 0 }; };
106template<typename T> struct isSame<T,T> { enum { value_ = 1 }; };
107
109template<int M, int N> struct IsEqual { enum { value_ = (M==N) }; };
110
114template<typename Type1, typename Type2>
116{ typedef typename If<(sizeof(Type1) > sizeof(Type2)), Type1, Type2>::Result result_type;};
120template<typename Type>
121struct Promote<Type, Type>
122{ typedef Type result_type;};
123
128template<int Size1, int Size2> struct ProductSizeRowsBySizeCols;
129
130// easy part
131template<>
132struct ProductSizeRowsBySizeCols<1, 1> { enum { prod_ = 1};};
133template<>
135template<>
137template<>
139template<int Size1>
140struct ProductSizeRowsBySizeCols<Size1, 1> { enum { prod_ = Size1};};
141template<int Size2>
142struct ProductSizeRowsBySizeCols<1, Size2> { enum { prod_ = Size2};};
143template<int Size1>
145template<int Size2>
147
148template<bool isSmallSize1, bool isSmallSize2, int Size1, int Size2>
150template<int Size1, int Size2>
151struct ProductSizesHelper<false, false, Size1, Size2> { enum { prod_ = Size1 * Size2};};
152
157template<int Size1, int Size2>
162
163
164}// namespace hidden
165
166} // namespace STK
167
168#endif /* STK_METATEMPLATE_H_ */
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
const int UnknownSize
This value means that an integer is not known at compile-time, and that instead the value is stored i...
const int SqrtUnknownSize
Same as floor(sqrt(INT_MAX+1))
The namespace STK is the main domain space of the Statistical ToolKit project.
check if T and U are equal
Convenient structure for computing the product of two template integer parameters without overflow.
Convenient struct to Promote the result Type of some binary functors.
If<(sizeof(Type1)>sizeof(Type2)), Type1, Type2 >::Result result_type
check if T and U are of the same type.