Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_METAL_MATH_POW_HH 00027 # define MLN_METAL_MATH_POW_HH 00028 00034 # include <mln/metal/bool.hh> 00035 # include <mln/metal/int.hh> 00036 00037 00038 # define mlc_pow(X, N) typename mln::metal::math::pow< X, N >::ret 00039 # define mlc_pow_int(x, n) mln::metal::math::pow_int< x, n >::value 00040 00041 00042 00043 namespace mln 00044 { 00045 00046 namespace metal 00047 { 00048 00049 namespace math 00050 { 00051 00052 // pow_int<x, n> 00053 00054 namespace impl 00055 { 00056 00057 template <int x, int n> 00058 struct pow_int_ 00059 { 00060 enum res_ { value = x * pow_int_<x, n-1>::value }; 00061 }; 00062 00063 template <int x> 00064 struct pow_int_< x, 0 > 00065 { 00066 enum res_ { value = 1 }; 00067 }; 00068 00069 template <> 00070 struct pow_int_< 0, 0 >; 00071 00072 00073 // Entry. 00074 00075 template <int x, int n, bool b> 00076 struct pow_int_if_ : pow_int_<x, n> 00077 { 00078 }; 00079 00080 template <int x, int n> 00081 struct pow_int_if_< x, n, false > 00082 { 00083 }; 00084 00085 } 00086 00087 template <int x, int n> 00088 struct pow_int : impl::pow_int_if_< x, n, 00089 (n >= 0 && ! (x == 0 && n == 0)) > 00090 { 00091 }; 00092 00093 00094 // pow<X, N> 00095 00096 template <typename X, typename N> 00097 struct pow; 00098 00099 template <int x, int n> 00100 struct pow< int_<x>, int_<n> > 00101 { 00102 typedef int_< pow_int<x, n>::value > ret; 00103 }; 00104 00105 00106 } // end of namespace mln::metal::math 00107 00108 } // end of namespace mln::metal 00109 00110 } // end of namespace mln 00111 00112 00113 #endif // ! MLN_METAL_MATH_POW_HH