Eurobot2012_Primary
Dependencies: mbed Eurobot_2012_Primary
tvmet/BinaryFunctionals.h@26:0995f61cb7b8, 2012-10-17 (annotated)
- Committer:
- narshu
- Date:
- Wed Oct 17 22:22:47 2012 +0000
- Revision:
- 26:0995f61cb7b8
- Parent:
- 25:143b19c1fb05
Eurobot 2012 Primary;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
narshu | 25:143b19c1fb05 | 1 | /* |
narshu | 25:143b19c1fb05 | 2 | * Tiny Vector Matrix Library |
narshu | 25:143b19c1fb05 | 3 | * Dense Vector Matrix Libary of Tiny size using Expression Templates |
narshu | 25:143b19c1fb05 | 4 | * |
narshu | 25:143b19c1fb05 | 5 | * Copyright (C) 2001 - 2007 Olaf Petzold <opetzold@users.sourceforge.net> |
narshu | 25:143b19c1fb05 | 6 | * |
narshu | 25:143b19c1fb05 | 7 | * This library is free software; you can redistribute it and/or |
narshu | 25:143b19c1fb05 | 8 | * modify it under the terms of the GNU Lesser General Public |
narshu | 25:143b19c1fb05 | 9 | * License as published by the Free Software Foundation; either |
narshu | 25:143b19c1fb05 | 10 | * version 2.1 of the License, or (at your option) any later version. |
narshu | 25:143b19c1fb05 | 11 | * |
narshu | 25:143b19c1fb05 | 12 | * This library is distributed in the hope that it will be useful, |
narshu | 25:143b19c1fb05 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
narshu | 25:143b19c1fb05 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
narshu | 25:143b19c1fb05 | 15 | * Lesser General Public License for more details. |
narshu | 25:143b19c1fb05 | 16 | * |
narshu | 25:143b19c1fb05 | 17 | * You should have received a copy of the GNU Lesser General Public |
narshu | 25:143b19c1fb05 | 18 | * License along with this library; if not, write to the Free Software |
narshu | 25:143b19c1fb05 | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
narshu | 25:143b19c1fb05 | 20 | * |
narshu | 25:143b19c1fb05 | 21 | * $Id: BinaryFunctionals.h,v 1.24 2007-06-23 15:58:58 opetzold Exp $ |
narshu | 25:143b19c1fb05 | 22 | */ |
narshu | 25:143b19c1fb05 | 23 | |
narshu | 25:143b19c1fb05 | 24 | #ifndef TVMET_BINARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 25 | #define TVMET_BINARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 26 | |
narshu | 25:143b19c1fb05 | 27 | namespace tvmet { |
narshu | 25:143b19c1fb05 | 28 | |
narshu | 25:143b19c1fb05 | 29 | |
narshu | 25:143b19c1fb05 | 30 | /** |
narshu | 25:143b19c1fb05 | 31 | * \class Fcnl_assign BinaryFunctionals.h "tvmet/BinaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 32 | * \brief Binary operator for assign operations. |
narshu | 25:143b19c1fb05 | 33 | * |
narshu | 25:143b19c1fb05 | 34 | * Unfortunally we have sometimes to cast on assign operations e.g., |
narshu | 25:143b19c1fb05 | 35 | * on assign on different POD. So we avoid warnings. |
narshu | 25:143b19c1fb05 | 36 | */ |
narshu | 25:143b19c1fb05 | 37 | template <class T1, class T2> |
narshu | 25:143b19c1fb05 | 38 | struct Fcnl_assign : public BinaryFunctional { |
narshu | 25:143b19c1fb05 | 39 | static inline |
narshu | 25:143b19c1fb05 | 40 | void apply_on(T1& _tvmet_restrict lhs, T2 rhs) { |
narshu | 25:143b19c1fb05 | 41 | lhs = static_cast<T1>(rhs); |
narshu | 25:143b19c1fb05 | 42 | } |
narshu | 25:143b19c1fb05 | 43 | |
narshu | 25:143b19c1fb05 | 44 | static |
narshu | 25:143b19c1fb05 | 45 | void print_xpr(std::ostream& os, std::size_t l=0) { |
narshu | 25:143b19c1fb05 | 46 | os << IndentLevel(l) << "fcnl_assign<T1=" |
narshu | 25:143b19c1fb05 | 47 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," |
narshu | 25:143b19c1fb05 | 48 | << std::endl; |
narshu | 25:143b19c1fb05 | 49 | } |
narshu | 25:143b19c1fb05 | 50 | }; |
narshu | 25:143b19c1fb05 | 51 | |
narshu | 25:143b19c1fb05 | 52 | |
narshu | 25:143b19c1fb05 | 53 | /** \class Fcnl_add_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 54 | /** \class Fcnl_sub_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 55 | /** \class Fcnl_mul_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 56 | /** \class Fcnl_div_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 57 | /** \class Fcnl_mod_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 58 | /** \class Fcnl_xor_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 59 | /** \class Fcnl_and_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 60 | /** \class Fcnl_or_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 61 | /** \class Fcnl_shl_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 62 | /** \class Fcnl_shr_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 63 | #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ |
narshu | 25:143b19c1fb05 | 64 | template <class T1, class T2> \ |
narshu | 25:143b19c1fb05 | 65 | struct Fcnl_##NAME : public BinaryFunctional { \ |
narshu | 25:143b19c1fb05 | 66 | typedef void value_type; \ |
narshu | 25:143b19c1fb05 | 67 | \ |
narshu | 25:143b19c1fb05 | 68 | static inline \ |
narshu | 25:143b19c1fb05 | 69 | void apply_on(T1& _tvmet_restrict lhs, T2 rhs) { \ |
narshu | 25:143b19c1fb05 | 70 | lhs OP rhs; \ |
narshu | 25:143b19c1fb05 | 71 | } \ |
narshu | 25:143b19c1fb05 | 72 | \ |
narshu | 25:143b19c1fb05 | 73 | static \ |
narshu | 25:143b19c1fb05 | 74 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 75 | os << IndentLevel(l) \ |
narshu | 25:143b19c1fb05 | 76 | << "Fcnl_" << #NAME << "<T1=" \ |
narshu | 25:143b19c1fb05 | 77 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \ |
narshu | 25:143b19c1fb05 | 78 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 79 | } \ |
narshu | 25:143b19c1fb05 | 80 | }; |
narshu | 25:143b19c1fb05 | 81 | |
narshu | 25:143b19c1fb05 | 82 | TVMET_IMPLEMENT_MACRO(add_eq, +=) |
narshu | 25:143b19c1fb05 | 83 | TVMET_IMPLEMENT_MACRO(sub_eq, -=) |
narshu | 25:143b19c1fb05 | 84 | TVMET_IMPLEMENT_MACRO(mul_eq, *=) |
narshu | 25:143b19c1fb05 | 85 | TVMET_IMPLEMENT_MACRO(div_eq, /=) |
narshu | 25:143b19c1fb05 | 86 | TVMET_IMPLEMENT_MACRO(mod_eq, %=) |
narshu | 25:143b19c1fb05 | 87 | TVMET_IMPLEMENT_MACRO(xor_eq, ^=) |
narshu | 25:143b19c1fb05 | 88 | TVMET_IMPLEMENT_MACRO(and_eq, &=) |
narshu | 25:143b19c1fb05 | 89 | TVMET_IMPLEMENT_MACRO(or_eq, |=) |
narshu | 25:143b19c1fb05 | 90 | TVMET_IMPLEMENT_MACRO(shl_eq, <<=) |
narshu | 25:143b19c1fb05 | 91 | TVMET_IMPLEMENT_MACRO(shr_eq, >>=) |
narshu | 25:143b19c1fb05 | 92 | |
narshu | 25:143b19c1fb05 | 93 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 94 | |
narshu | 25:143b19c1fb05 | 95 | |
narshu | 25:143b19c1fb05 | 96 | /** \class Fcnl_add BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 97 | /** \class Fcnl_sub BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 98 | /** \class Fcnl_mul BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 99 | /** \class Fcnl_div BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 100 | /** \class Fcnl_mod BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 101 | /** \class Fcnl_bitxor BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 102 | /** \class Fcnl_bitand BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 103 | /** \class Fcnl_bitor BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 104 | /** \class Fcnl_shl BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 105 | /** \class Fcnl_shr BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 106 | #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ |
narshu | 25:143b19c1fb05 | 107 | template <class T1, class T2> \ |
narshu | 25:143b19c1fb05 | 108 | struct Fcnl_##NAME : public BinaryFunctional { \ |
narshu | 25:143b19c1fb05 | 109 | typedef typename PromoteTraits<T1, T2>::value_type value_type; \ |
narshu | 25:143b19c1fb05 | 110 | \ |
narshu | 25:143b19c1fb05 | 111 | static inline \ |
narshu | 25:143b19c1fb05 | 112 | value_type apply_on(T1 lhs, T2 rhs) { \ |
narshu | 25:143b19c1fb05 | 113 | return lhs OP rhs; \ |
narshu | 25:143b19c1fb05 | 114 | } \ |
narshu | 25:143b19c1fb05 | 115 | \ |
narshu | 25:143b19c1fb05 | 116 | static \ |
narshu | 25:143b19c1fb05 | 117 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 118 | os << IndentLevel(l) \ |
narshu | 25:143b19c1fb05 | 119 | << "Fcnl_" << #NAME << "<T1=" \ |
narshu | 25:143b19c1fb05 | 120 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \ |
narshu | 25:143b19c1fb05 | 121 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 122 | } \ |
narshu | 25:143b19c1fb05 | 123 | }; |
narshu | 25:143b19c1fb05 | 124 | |
narshu | 25:143b19c1fb05 | 125 | TVMET_IMPLEMENT_MACRO(add, +) |
narshu | 25:143b19c1fb05 | 126 | TVMET_IMPLEMENT_MACRO(sub, -) |
narshu | 25:143b19c1fb05 | 127 | TVMET_IMPLEMENT_MACRO(mul, *) |
narshu | 25:143b19c1fb05 | 128 | TVMET_IMPLEMENT_MACRO(div, /) |
narshu | 25:143b19c1fb05 | 129 | TVMET_IMPLEMENT_MACRO(mod, %) |
narshu | 25:143b19c1fb05 | 130 | TVMET_IMPLEMENT_MACRO(bitxor, ^) |
narshu | 25:143b19c1fb05 | 131 | TVMET_IMPLEMENT_MACRO(bitand, &) |
narshu | 25:143b19c1fb05 | 132 | TVMET_IMPLEMENT_MACRO(bitor, |) |
narshu | 25:143b19c1fb05 | 133 | TVMET_IMPLEMENT_MACRO(shl, <<) |
narshu | 25:143b19c1fb05 | 134 | TVMET_IMPLEMENT_MACRO(shr, >>) |
narshu | 25:143b19c1fb05 | 135 | |
narshu | 25:143b19c1fb05 | 136 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 137 | |
narshu | 25:143b19c1fb05 | 138 | |
narshu | 25:143b19c1fb05 | 139 | /** \class Fcnl_greater BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 140 | /** \class Fcnl_greater_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 141 | /** \class Fcnl_less BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 142 | /** \class Fcnl_less_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 143 | /** \class Fcnl_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 144 | /** \class Fcnl_not_eq BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 145 | /** \class Fcnl_and BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 146 | /** \class Fcnl_or BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 147 | #define TVMET_IMPLEMENT_MACRO(NAME, OP) \ |
narshu | 25:143b19c1fb05 | 148 | template <class T1, class T2> \ |
narshu | 25:143b19c1fb05 | 149 | struct Fcnl_##NAME : public BinaryFunctional { \ |
narshu | 25:143b19c1fb05 | 150 | typedef bool value_type; \ |
narshu | 25:143b19c1fb05 | 151 | \ |
narshu | 25:143b19c1fb05 | 152 | static inline \ |
narshu | 25:143b19c1fb05 | 153 | bool apply_on(T1 lhs, T2 rhs) { \ |
narshu | 25:143b19c1fb05 | 154 | return lhs OP rhs; \ |
narshu | 25:143b19c1fb05 | 155 | } \ |
narshu | 25:143b19c1fb05 | 156 | \ |
narshu | 25:143b19c1fb05 | 157 | static \ |
narshu | 25:143b19c1fb05 | 158 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 159 | os << IndentLevel(l) \ |
narshu | 25:143b19c1fb05 | 160 | << "Fcnl_" << #NAME << "<T1=" \ |
narshu | 25:143b19c1fb05 | 161 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \ |
narshu | 25:143b19c1fb05 | 162 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 163 | } \ |
narshu | 25:143b19c1fb05 | 164 | }; |
narshu | 25:143b19c1fb05 | 165 | |
narshu | 25:143b19c1fb05 | 166 | TVMET_IMPLEMENT_MACRO(greater, >) |
narshu | 25:143b19c1fb05 | 167 | TVMET_IMPLEMENT_MACRO(less, <) |
narshu | 25:143b19c1fb05 | 168 | TVMET_IMPLEMENT_MACRO(greater_eq, >=) |
narshu | 25:143b19c1fb05 | 169 | TVMET_IMPLEMENT_MACRO(less_eq, <=) |
narshu | 25:143b19c1fb05 | 170 | TVMET_IMPLEMENT_MACRO(eq, ==) |
narshu | 25:143b19c1fb05 | 171 | TVMET_IMPLEMENT_MACRO(not_eq, !=) |
narshu | 25:143b19c1fb05 | 172 | TVMET_IMPLEMENT_MACRO(and, &&) |
narshu | 25:143b19c1fb05 | 173 | TVMET_IMPLEMENT_MACRO(or, ||) |
narshu | 25:143b19c1fb05 | 174 | |
narshu | 25:143b19c1fb05 | 175 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 176 | |
narshu | 25:143b19c1fb05 | 177 | |
narshu | 25:143b19c1fb05 | 178 | /** \class Fcnl_atan2 BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 179 | /** \class Fcnl_fmod BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 180 | /** \class Fcnl_pow BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 181 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 182 | template <class T1, class T2> \ |
narshu | 25:143b19c1fb05 | 183 | struct Fcnl_##NAME : public BinaryFunctional { \ |
narshu | 25:143b19c1fb05 | 184 | typedef typename PromoteTraits<T1, T2>::value_type value_type; \ |
narshu | 25:143b19c1fb05 | 185 | \ |
narshu | 25:143b19c1fb05 | 186 | static inline \ |
narshu | 25:143b19c1fb05 | 187 | value_type apply_on(T1 lhs, T2 rhs) { \ |
narshu | 25:143b19c1fb05 | 188 | return TVMET_STD_SCOPE(NAME)(lhs, rhs); \ |
narshu | 25:143b19c1fb05 | 189 | } \ |
narshu | 25:143b19c1fb05 | 190 | \ |
narshu | 25:143b19c1fb05 | 191 | static \ |
narshu | 25:143b19c1fb05 | 192 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 193 | os << IndentLevel(l) \ |
narshu | 25:143b19c1fb05 | 194 | << "Fcnl_" << #NAME << "<T1=" \ |
narshu | 25:143b19c1fb05 | 195 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \ |
narshu | 25:143b19c1fb05 | 196 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 197 | } \ |
narshu | 25:143b19c1fb05 | 198 | }; |
narshu | 25:143b19c1fb05 | 199 | |
narshu | 25:143b19c1fb05 | 200 | TVMET_IMPLEMENT_MACRO(atan2) |
narshu | 25:143b19c1fb05 | 201 | TVMET_IMPLEMENT_MACRO(fmod) |
narshu | 25:143b19c1fb05 | 202 | TVMET_IMPLEMENT_MACRO(pow) |
narshu | 25:143b19c1fb05 | 203 | |
narshu | 25:143b19c1fb05 | 204 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 205 | |
narshu | 25:143b19c1fb05 | 206 | |
narshu | 25:143b19c1fb05 | 207 | /** \class Fcnl_drem BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 208 | /** \class Fcnl_hypot BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 209 | /** \class Fcnl_jn BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 210 | /** \class Fcnl_yn BinaryFunctionals.h "tvmet/BinaryFunctionals.h" */ |
narshu | 25:143b19c1fb05 | 211 | #define TVMET_IMPLEMENT_MACRO(NAME) \ |
narshu | 25:143b19c1fb05 | 212 | template <class T1, class T2> \ |
narshu | 25:143b19c1fb05 | 213 | struct Fcnl_##NAME : public BinaryFunctional { \ |
narshu | 25:143b19c1fb05 | 214 | typedef typename PromoteTraits<T1, T2>::value_type value_type; \ |
narshu | 25:143b19c1fb05 | 215 | \ |
narshu | 25:143b19c1fb05 | 216 | static inline \ |
narshu | 25:143b19c1fb05 | 217 | value_type apply_on(T1 lhs, T2 rhs) { \ |
narshu | 25:143b19c1fb05 | 218 | return TVMET_GLOBAL_SCOPE(NAME)(lhs, rhs); \ |
narshu | 25:143b19c1fb05 | 219 | } \ |
narshu | 25:143b19c1fb05 | 220 | \ |
narshu | 25:143b19c1fb05 | 221 | static \ |
narshu | 25:143b19c1fb05 | 222 | void print_xpr(std::ostream& os, std::size_t l=0) { \ |
narshu | 25:143b19c1fb05 | 223 | os << IndentLevel(l) \ |
narshu | 25:143b19c1fb05 | 224 | << "Fcnl_" << #NAME << "<T1=" \ |
narshu | 25:143b19c1fb05 | 225 | << typeid(T1).name() << ", T2=" << typeid(T2).name() << ">," \ |
narshu | 25:143b19c1fb05 | 226 | << std::endl; \ |
narshu | 25:143b19c1fb05 | 227 | } \ |
narshu | 25:143b19c1fb05 | 228 | }; |
narshu | 25:143b19c1fb05 | 229 | |
narshu | 25:143b19c1fb05 | 230 | TVMET_IMPLEMENT_MACRO(drem) |
narshu | 25:143b19c1fb05 | 231 | TVMET_IMPLEMENT_MACRO(hypot) |
narshu | 25:143b19c1fb05 | 232 | TVMET_IMPLEMENT_MACRO(jn) |
narshu | 25:143b19c1fb05 | 233 | TVMET_IMPLEMENT_MACRO(yn) |
narshu | 25:143b19c1fb05 | 234 | |
narshu | 25:143b19c1fb05 | 235 | #undef TVMET_IMPLEMENT_MACRO |
narshu | 25:143b19c1fb05 | 236 | |
narshu | 25:143b19c1fb05 | 237 | |
narshu | 25:143b19c1fb05 | 238 | #if defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 239 | /** |
narshu | 25:143b19c1fb05 | 240 | * \class Fcnl_polar BinaryFunctionals.h "tvmet/BinaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 241 | * \brief %Functional for polar. |
narshu | 25:143b19c1fb05 | 242 | */ |
narshu | 25:143b19c1fb05 | 243 | template <class T1, class T2> struct Fcnl_polar : public BinaryFunctional { }; |
narshu | 25:143b19c1fb05 | 244 | |
narshu | 25:143b19c1fb05 | 245 | |
narshu | 25:143b19c1fb05 | 246 | /** |
narshu | 25:143b19c1fb05 | 247 | * \class Fcnl_polar<T,T> BinaryFunctionals.h "tvmet/BinaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 248 | * \brief %Functional for polar. |
narshu | 25:143b19c1fb05 | 249 | * \note This functional is partialy specialized due to the declaration |
narshu | 25:143b19c1fb05 | 250 | * of %polar in namespace std <tt>complex<T> polar(T, T)</tt>. |
narshu | 25:143b19c1fb05 | 251 | * This means especially that type promotion isn't avaible here. |
narshu | 25:143b19c1fb05 | 252 | */ |
narshu | 25:143b19c1fb05 | 253 | template <class T> |
narshu | 25:143b19c1fb05 | 254 | struct Fcnl_polar<T,T> : public BinaryFunctional { |
narshu | 25:143b19c1fb05 | 255 | typedef std::complex<T> value_type; |
narshu | 25:143b19c1fb05 | 256 | |
narshu | 25:143b19c1fb05 | 257 | static inline |
narshu | 25:143b19c1fb05 | 258 | value_type apply_on(T lhs, T rhs) { |
narshu | 25:143b19c1fb05 | 259 | return std::polar(lhs, rhs); |
narshu | 25:143b19c1fb05 | 260 | } |
narshu | 25:143b19c1fb05 | 261 | |
narshu | 25:143b19c1fb05 | 262 | static |
narshu | 25:143b19c1fb05 | 263 | void print_xpr(std::ostream& os, std::size_t l=0) { |
narshu | 25:143b19c1fb05 | 264 | os << IndentLevel(l) << "Fcnl_polar<T1=" |
narshu | 25:143b19c1fb05 | 265 | << typeid(T).name() << ", T2=" << typeid(T).name() << ">," |
narshu | 25:143b19c1fb05 | 266 | << std::endl; |
narshu | 25:143b19c1fb05 | 267 | } |
narshu | 25:143b19c1fb05 | 268 | }; |
narshu | 25:143b19c1fb05 | 269 | #endif // defined(TVMET_HAVE_COMPLEX) |
narshu | 25:143b19c1fb05 | 270 | |
narshu | 25:143b19c1fb05 | 271 | |
narshu | 25:143b19c1fb05 | 272 | /** |
narshu | 25:143b19c1fb05 | 273 | * \class Fcnl_swap BinaryFunctionals.h "tvmet/BinaryFunctionals.h" |
narshu | 25:143b19c1fb05 | 274 | * \brief Binary operator for swapping values using temporaries. |
narshu | 25:143b19c1fb05 | 275 | */ |
narshu | 25:143b19c1fb05 | 276 | template <class T1, class T2> |
narshu | 25:143b19c1fb05 | 277 | struct Fcnl_swap : public BinaryFunctional { |
narshu | 25:143b19c1fb05 | 278 | static inline |
narshu | 25:143b19c1fb05 | 279 | void apply_on(T1& _tvmet_restrict lhs, T2& _tvmet_restrict rhs) { |
narshu | 25:143b19c1fb05 | 280 | typedef typename PromoteTraits<T1, T2>::value_type temp_type; |
narshu | 25:143b19c1fb05 | 281 | |
narshu | 25:143b19c1fb05 | 282 | temp_type temp(lhs); |
narshu | 25:143b19c1fb05 | 283 | lhs = static_cast<T1>(rhs); |
narshu | 25:143b19c1fb05 | 284 | rhs = static_cast<T2>(temp); |
narshu | 25:143b19c1fb05 | 285 | } |
narshu | 25:143b19c1fb05 | 286 | |
narshu | 25:143b19c1fb05 | 287 | static |
narshu | 25:143b19c1fb05 | 288 | void print_xpr(std::ostream& os, std::size_t l=0) { |
narshu | 25:143b19c1fb05 | 289 | os << IndentLevel(l) << "Fcnl_swap<T1=" |
narshu | 25:143b19c1fb05 | 290 | << typeid(T1).name() << ", T2" << typeid(T2).name() << ">," |
narshu | 25:143b19c1fb05 | 291 | << std::endl; |
narshu | 25:143b19c1fb05 | 292 | } |
narshu | 25:143b19c1fb05 | 293 | }; |
narshu | 25:143b19c1fb05 | 294 | |
narshu | 25:143b19c1fb05 | 295 | |
narshu | 25:143b19c1fb05 | 296 | } // namespace tvmet |
narshu | 25:143b19c1fb05 | 297 | |
narshu | 25:143b19c1fb05 | 298 | #endif // TVMET_BINARY_FUNCTIONAL_H |
narshu | 25:143b19c1fb05 | 299 | |
narshu | 25:143b19c1fb05 | 300 | // Local Variables: |
narshu | 25:143b19c1fb05 | 301 | // mode:C++ |
narshu | 25:143b19c1fb05 | 302 | // tab-width:8 |
narshu | 25:143b19c1fb05 | 303 | // End: |