1 /* 2 * Copyright 2014 Google Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef FRUIT_META_NUMERIC_OPERATIONS_H 18 #define FRUIT_META_NUMERIC_OPERATIONS_H 19 20 #include <fruit/impl/meta/basics.h> 21 22 namespace fruit { 23 namespace impl { 24 namespace meta { 25 26 struct Sum { 27 template <typename... Ints> 28 struct apply; 29 30 template <int n, int m> 31 struct apply<Int<n>, Int<m>> { 32 using type = Int<n + m>; 33 }; 34 }; 35 36 struct SumAll { 37 template <typename... Ints> 38 struct apply { 39 using type = Int<0>; 40 }; 41 42 template <typename N1, typename... Ints> 43 struct apply<N1, Ints...> { 44 using type = Int<N1::value + apply<Ints...>::type::value>; 45 }; 46 47 // Optimization, not required for correctness. 48 template <typename N0, typename N1, typename N2, typename N3, typename N4, typename... Ints> 49 struct apply<N0, N1, N2, N3, N4, Ints...> { 50 using type = Int<N0::value + N1::value + N2::value + N3::value + N4::value + apply<Ints...>::type::value>; 51 }; 52 }; 53 54 struct Minus { 55 template <typename N, typename M> 56 struct apply; 57 58 template <int n, int m> 59 struct apply<Int<n>, Int<m>> { 60 using type = Int<n - m>; 61 }; 62 }; 63 64 struct GreaterThan { 65 template <typename N, typename M> 66 struct apply; 67 68 template <int n, int m> 69 struct apply<Int<n>, Int<m>> { 70 using type = Bool<(n > m)>; 71 }; 72 }; 73 74 } // namespace meta 75 } // namespace impl 76 } // namespace fruit 77 78 #endif // FRUIT_META_NUMERIC_OPERATIONS_H 79