stlab.adobe.com Adobe Systems Incorporated

operator.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003     Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004     or a copy at http://stlab.adobe.com/licenses.html)
00005 */
00006 
00007 /*************************************************************************************************/
00008 
00009 #ifndef ADOBE_FUNCTIONAL_OPERATOR_HPP
00010 #define ADOBE_FUNCTIONAL_OPERATOR_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 #include <functional>
00015 #include <typeinfo>
00016 
00017 #include <adobe/move.hpp>
00018 
00019 /*************************************************************************************************/
00020 
00021 namespace adobe {
00022 
00023 /*************************************************************************************************/
00024 
00028 struct equal_to
00029 {
00030     typedef bool result_type;
00031 
00032     template <typename T> // T models Regular
00033     bool operator()(const T& x, const T& y) const { return std::equal_to<T>()(x, y); }
00034 };
00035 
00036 struct not_equal_to
00037 {
00038     typedef bool result_type;
00039 
00040     template <typename T> // T models Regular
00041     bool operator()(const T& x, const T& y) const { return std::not_equal_to<T>()(x, y); }
00042 };
00043 
00044 struct greater
00045 {
00046     typedef bool result_type;
00047 
00048     template <typename T> // T models Regular
00049     bool operator()(const T& x, const T& y) const { return std::greater<T>()(x, y); }
00050 };
00051 
00052 struct less
00053 {
00054     typedef bool result_type;
00055 
00056     template <typename T> // T models Regular
00057     bool operator()(const T& x, const T& y) const { return typename std::less<T>()(x, y); }
00058     
00059     bool operator()(const std::type_info& x, const std::type_info& y) { return x.before(y) != 0; }
00060 };
00061 
00062 struct greater_equal
00063 {
00064     typedef bool result_type;
00065 
00066     template <typename T> // T models Regular
00067     bool operator()(const T& x, const T& y) const { return std::greater_equal<T>()(x, y); }
00068 };
00069 
00070 struct less_equal
00071 {
00072     typedef bool result_type;
00073 
00074     template <typename T> // T models Regular
00075     bool operator()(const T& x, const T& y) const { return std::less_equal<T>()(x, y); }
00076 };
00077 
00078 struct logical_and
00079 {
00080     typedef bool result_type;
00081 
00082     template <typename T> // T models Regular
00083     bool operator()(const T& x, const T& y) const { return std::logical_and<T>()(x, y); }
00084 };
00085 
00086 struct logical_or
00087 {
00088     typedef bool result_type;
00089 
00090     template <typename T> // T models Regular
00091     bool operator()(const T& x, const T& y) const { return std::logical_or<T>()(x, y); }
00092 };
00093 
00094 struct logical_not
00095 {
00096     typedef bool result_type;
00097 
00098     template <typename T> // T models Regular
00099     bool operator()(const T& x) const { return std::logical_not<T>()(x); }
00100 };
00101 
00102 struct assign
00103 {
00104     typedef void result_type;
00105 
00106     template <typename T> // T models Regular
00107     void operator()(T x, T& r) { r = adobe::move(x); }
00108 };
00109 
00110 /*************************************************************************************************/
00111 
00112 template <typename T> // T models Regular
00113 struct pointer_to
00114 {
00115     typedef T* result_type;
00116 
00117     T* operator()(T& x) const { return &x; }
00118 };
00119 
00120 /*************************************************************************************************/
00121 
00122 template <typename T>
00123 struct identity
00124 {
00125     typedef T& result_type;
00126 
00127     T& operator()(T& x) const { return x; }
00128 };
00129 
00130 /*************************************************************************************************/
00131 
00138 struct delete_ptr
00139 {
00140     typedef void result_type;
00141 
00142     template <typename T>
00143     void operator () (const T* x) const { delete x; }
00144 };
00145 
00152 struct delete_array
00153 {
00154     typedef void result_type;
00155 
00156     template <typename T>
00157     void operator () (const T* x) const { delete [] x; }
00158 };
00159 
00160 /*************************************************************************************************/
00161 
00162 template<class T>
00163 struct constructor
00164 {
00165   typedef T result_type;
00166 
00167   T operator()() const {
00168     return T();
00169   }
00170 
00171   template<class A1>
00172   T operator()(const A1& a1) const {
00173     return T(a1);
00174   }
00175 
00176   template<class A1, class A2>
00177   T operator()(const A1& a1, const A2& a2) const {
00178     return T(a1, a2);
00179   }
00180 
00181   template<class A1, class A2, class A3>
00182   T operator()(const A1& a1, const A2& a2, const A3& a3) const {
00183     return T(a1, a2, a3);
00184   }
00185 
00186   template<class A1, class A2, class A3, class A4>
00187   T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4) const {
00188     return T(a1, a2, a3, a4);
00189   }
00190 
00191   template<class A1, class A2, class A3, class A4, class A5>
00192   T operator()(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5) const {
00193     return T(a1, a2, a3, a4, a5);
00194   }
00195 };
00196 
00197 /*************************************************************************************************/
00198 
00199 template <typename T> // T models Regular
00200 struct indirect
00201 {
00202     typedef T& result_type;
00203 
00204     template <typename P> // models TrivialIterator where value_type(P) == T
00205     T& operator () (P x) const
00206         { return *x; }
00207 };
00208 
00209 /*************************************************************************************************/
00210 
00211 template <class T>
00212 struct bitwise_or
00213     : std::binary_function<T, T, T>
00214 {
00215     T operator()(const T& x, const T& y) const {return x | y;}
00216 };
00217 
00218 /*************************************************************************************************/
00219 
00220 template <class T>
00221 struct bitwise_and
00222     : std::binary_function<T, T, T>
00223 {
00224     T operator()(const T& x, const T& y) const {return x & y;}
00225 };
00226 
00227 /*************************************************************************************************/
00228 
00229 template <class T>
00230 struct bitwise_xor
00231     : std::binary_function<T, T, T>
00232 {
00233     T operator()(const T& x, const T& y) const {return x ^ y;}
00234 };
00235 
00236 /*************************************************************************************************/
00237 
00239 template <typename T1, typename T2>
00240 struct plus_asymmetric : public std::binary_function<T1,T2,T1>
00241 {
00242     T1 operator()(T1 f1, T2 f2) const {
00243         return f1+f2;
00244     }
00245 };
00246 
00247 /*************************************************************************************************/
00248 
00250 template <typename T>
00251 struct inc : public std::unary_function<T,T>
00252 {
00253     T operator()(T x) const { return ++x; }
00254 };
00255 
00256 /*************************************************************************************************/
00257 
00259 template <typename T>
00260 struct dec : public std::unary_function<T,T>
00261 {
00262     T operator()(T x) const { return --x; }
00263 };
00264 
00266 
00267 /*************************************************************************************************/
00268 
00269 } // namespace adobe
00270 
00271 /*************************************************************************************************/
00272 
00273 #endif
00274 
00275 /*************************************************************************************************/

Copyright © 2006-2007 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.

Search powered by Google