blitz Version 0.10
|
00001 // -*- C++ -*- 00002 /*************************************************************************** 00003 * blitz/minmax.h Declaration of min and max functions 00004 * 00005 * $Id: minmax.h,v 1.7 2011/03/25 22:41:16 julianc Exp $ 00006 * 00007 * Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org> 00008 * 00009 * This file is a part of Blitz. 00010 * 00011 * Blitz is free software: you can redistribute it and/or modify 00012 * it under the terms of the GNU Lesser General Public License 00013 * as published by the Free Software Foundation, either version 3 00014 * of the License, or (at your option) any later version. 00015 * 00016 * Blitz is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with Blitz. If not, see <http://www.gnu.org/licenses/>. 00023 * 00024 * Suggestions: blitz-devel@lists.sourceforge.net 00025 * Bugs: blitz-support@lists.sourceforge.net 00026 * 00027 * For more information, please see the Blitz++ Home Page: 00028 * https://sourceforge.net/projects/blitz/ 00029 * 00030 ***************************************************************************/ 00031 00032 #ifndef BZ_MINMAX_H 00033 #define BZ_MINMAX_H 00034 00035 #include <blitz/promote.h> 00036 00037 BZ_NAMESPACE(blitz) 00038 00039 /* 00040 * These functions are in their own namespace (blitz::minmax) to avoid 00041 * conflicts with the array reduction operations min and max. 00042 */ 00043 00044 BZ_NAMESPACE(extrema) 00045 00046 template<typename T1, typename T2> 00047 BZ_PROMOTE(T1,T2) (min)(const T1& a, const T2& b) 00048 { 00049 typedef BZ_PROMOTE(T1,T2) T_promote; 00050 00051 if (a <= b) 00052 return T_promote(a); 00053 else 00054 return T_promote(b); 00055 } 00056 00057 template<typename T1, typename T2> 00058 BZ_PROMOTE(T1,T2) (max)(const T1& a, const T2& b) 00059 { 00060 typedef BZ_PROMOTE(T1,T2) T_promote; 00061 00062 if (a >= b) 00063 return T_promote(a); 00064 else 00065 return T_promote(b); 00066 } 00067 00068 BZ_NAMESPACE_END 00069 00070 BZ_NAMESPACE_END 00071 00072 #endif