stlab.adobe.com Adobe Systems Incorporated

identity_element.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 #ifndef ADOBE_ALGORITHM_IDENTITY_ELEMENT_HPP
00009 #define ADOBE_ALGORITHM_IDENTITY_ELEMENT_HPP
00010 
00011 #include <adobe/config.hpp>
00012 
00013 #include <algorithm>
00014 #include <functional>
00015 
00016 /*************************************************************************************************/
00017 
00018 namespace adobe {
00019 
00020 /*************************************************************************************************/
00027 template <typename Op>
00028 struct identity_element
00029 {
00031     typedef typename Op::result_type result_type;
00032 
00034     result_type operator()() const;
00035 };
00036 
00042 template <typename T>
00043 struct identity_element<std::plus<T> >
00044 {
00046     typedef T result_type;
00047 
00049     result_type operator()() const
00050     { return T(0); }
00051 };
00052 
00058 template <typename T>
00059 struct identity_element<std::multiplies<T> >
00060 {
00062     typedef T result_type;
00063 
00065     result_type operator()() const
00066     { return T(1); }
00067 };
00068 
00069 /*************************************************************************************************/
00070 
00071 } // namespace adobe
00072 
00073 /*************************************************************************************************/
00074 
00075 #endif
00076 
00077 /*************************************************************************************************/

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