ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00024 #ifndef IVL_CORE_DETAILS_TYPES_NUMERIC_HPP 00025 #define IVL_CORE_DETAILS_TYPES_NUMERIC_HPP 00026 00027 namespace ivl { 00028 namespace types { 00029 00030 template <int N> 00031 struct number 00032 { 00033 enum { value = N }; 00034 }; 00035 00036 template <class N1, class N2> 00037 struct t_add 00038 { 00039 typedef number<N1::value + N2::value> type; 00040 enum { value = type::value }; 00041 }; 00042 00043 template <class N1, class N2, class N3> 00044 struct t_add_3 00045 { 00046 typedef number<N1::value + N2::value + N3::value> type; 00047 enum { value = type::value }; 00048 }; 00049 00050 template <class N1, class N2> 00051 struct t_sub 00052 { 00053 typedef number<N1::value - N2::value> type; 00054 enum { value = type::value }; 00055 }; 00056 00057 template <class N1, class N2> 00058 struct t_mul 00059 { 00060 typedef number<N1::value * N2::value> type; 00061 enum { value = type::value }; 00062 }; 00063 00064 template <class N1, class N2> 00065 struct t_max 00066 { 00067 enum { n1 = (N1::value > N2::value) }; 00068 typedef typename t_if<t_expr<n1>, N1, N2>::type type; 00069 enum { value = type::value }; 00070 }; 00071 00072 // -------------- 00073 // relational 00074 00075 template <class N1, class N2> 00076 struct t_gt 00077 { 00078 enum { n1 = (int(N1::value) > int(N2::value)) }; 00079 typedef typename t_expr<n1>::type type; 00080 }; 00081 00082 template <class N1, class N2> 00083 struct t_ge 00084 { 00085 enum { n1 = (int(N1::value) >= int(N2::value)) }; 00086 typedef typename t_expr<n1>::type type; 00087 }; 00088 00089 template <class N1, class N2> 00090 struct t_lt 00091 { 00092 enum { n1 = (int(N1::value) < int(N2::value)) }; 00093 typedef typename t_expr<n1>::type type; 00094 }; 00095 00096 template <class N1, class N2> 00097 struct t_le 00098 { 00099 enum { n1 = (int(N1::value) <= int(N2::value)) }; 00100 typedef typename t_expr<n1>::type type; 00101 }; 00102 00103 } /* namespace types */ 00104 } /* namespace ivl */ 00105 00106 #endif // IVL_CORE_DETAILS_TYPES_NUMERIC_HPP