ivl 679
ivl/details/core/math/unary_operators.hpp
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_MATH_UNARY_OPERATORS_HPP
00025 #define IVL_CORE_DETAILS_MATH_UNARY_OPERATORS_HPP
00026 
00027 namespace ivl {
00028 namespace math {
00029 
00030 // ------------------------------------------------------------------
00031 // definition of functions that correspond to each operator
00032 using std::operator+;
00033 using std::operator-;
00034 
00035 //todo : check if this is a c++ predefined name
00036 template <class T>
00037 inline
00038 T bitcmp(const T& elem)
00039 {
00040         return ~(elem);
00041 }
00042 
00043 template <class T>
00044 inline
00045 bool cnot(const T& elem)
00046 {
00047         return !(elem);
00048 }
00049 
00050 // Note: do not change unsigned type to signed. C++ does not.
00051 template <class T>
00052 inline
00053 T uminus(const T& elem)
00054 {
00055         return -(elem);
00056 }
00057 
00058 template <class T>
00059 inline
00060 T uplus(const T& elem)
00061 {
00062         return +(elem);
00063 }
00064 
00065 template <class T>
00066 inline
00067 typename types::deref_ptr<T>::type dereference(const T& elem)
00068 {
00069         return *(elem);
00070 }
00071 
00072 // ------------------------------------------------------------------
00073 // definition of operators based on the actual functions
00074 /*
00075 template <class T> inline
00076 T operator~(const T& elem) { return bitcmp(elem); }
00077 
00078 template <class T> inline
00079 T operator!(const T& elem) { return cnot(elem); }
00080 
00081 template <class T> inline
00082 T operator-(const T& elem) { return uminus(elem); }
00083 
00084 template <class T> inline
00085 T operator+(const T& elem) { return uplus(elem); }
00086 */
00087 } /* namespace math */
00088 } /* namespace ivl */
00089 
00090 #endif // IVL_CORE_DETAILS_MATH_UNARY_OPERATORS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations