/*! \file max.h * \brief return maximum element value (prototypes) * * ---------------------------------------------------------------------------- * * $Id: max.h,v 1.4 2005-04-29 18:31:46 tforb Exp $ * \author Thomas Forbriger * \date 20/03/2005 * * return maximum element value (prototypes) * * Copyright (c) 2005 by Thomas Forbriger (BFO Schiltach) * * REVISIONS and CHANGES * - 20/03/2005 V1.0 Thomas Forbriger * - 28/04/2005 V1.1 provide return type * * ============================================================================ */ // include guard #ifndef AFF_MAX_H_VERSION #define AFF_MAX_H_VERSION \ "AFF_MAX_H V1.1 " #define AFF_MAX_H_CVSID \ "$Id: max.h,v 1.4 2005-04-29 18:31:46 tforb Exp $" #include namespace aff { namespace func { namespace util { /*! utility class to extract the largest value from a container * * This class should be used together with the * aff::func::util::collect() function template. * * \param C any container class like aff::Array */ template class Extractmax { typedef typename C::Tcoc Tcont; typedef typename C::Tvalue Tvalue; public: typedef Tvalue Tretval; //! initialize member data Extractmax(const Tcont& c): Mval(c(c.first())) { } //! collect another value void operator() (const Tvalue& v) { Mval = Mval > v ? Mval : v; } //! return result of operation Tretval result() const { return(Mval); } private: Tvalue Mval; }; // class Extractmax } // namespace util /*----------------------------------------------------------------------*/ /*! Function template to extract the largest from the values * stored in a container * * \param C any container class like aff::Array * (this value is deduced by the compiler) * \param c any container of numerical values * \return largest value of container contents * * \sa aff::func::util::collect, aff::func::util::Extractmax */ template typename C::Tvalue max(const C& c) { return(aff::func::util::collect(c)); } // max() } // namespace func } // namespace aff #endif // AFF_MAX_H_VERSION (includeguard) /* ----- END OF max.h ----- */