stlab.adobe.com Adobe Systems Incorporated

ternary_function.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_TERNARY_FUNCTION_HPP
00010 #define ADOBE_TERNARY_FUNCTION_HPP
00011 
00012 #include <adobe/config.hpp>
00013 
00014 /*************************************************************************************************/
00015 
00016 namespace adobe {
00017 
00018 /*************************************************************************************************/
00019 
00020 template <typename T, typename U, typename V, typename R>
00021 struct ternary_function
00022 {
00023     typedef T   first_argument_type;
00024     typedef U   second_argument_type;
00025     typedef V   third_argument_type;
00026     typedef R   result_type;
00027 };
00028 
00029 /*************************************************************************************************/
00030 
00031 template <typename T, typename U, typename V, typename R>
00032 class pointer_to_ternary_function : public ternary_function<T, U, V, R>
00033 {
00034 public:
00035     typedef ternary_function<T, U, V, R>            _super;
00036     typedef typename _super::first_argument_type    first_argument_type;
00037     typedef typename _super::second_argument_type   second_argument_type;
00038     typedef typename _super::third_argument_type    third_argument_type;
00039     typedef typename _super::result_type            result_type;
00040 
00041     explicit pointer_to_ternary_function(result_type (*f)(first_argument_type, second_argument_type, third_argument_type)) :
00042         f_m(f)
00043         { }
00044 
00045     result_type operator()(first_argument_type x, second_argument_type y, third_argument_type z) const
00046     {
00047         return f_m(x, y, z);
00048     }
00049 
00050 private:
00051     result_type (*f_m)(first_argument_type, second_argument_type, third_argument_type);
00052 };
00053 
00054 /*************************************************************************************************/
00055 
00056 template <typename T, typename U, typename V, typename R>
00057 inline pointer_to_ternary_function<T, U, V, R> ptr_fun(R (*f)(T, U, V))
00058 {
00059     return pointer_to_ternary_function<T, U, V, R>(f);
00060 }
00061 
00062 /*************************************************************************************************/
00063 
00064 } // namespace adobe
00065 
00066 /*************************************************************************************************/
00067 
00068 #endif
00069 
00070 /*************************************************************************************************/

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