Chris@16: // (C) Copyright 2007-2009 Andrew Sutton Chris@16: // Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0 (See accompanying file Chris@16: // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GRAPH_NUMERIC_VALUES_HPP Chris@16: #define BOOST_GRAPH_NUMERIC_VALUES_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: Chris@16: #define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type) \ Chris@16: template <> struct numeric_values { \ Chris@16: typedef type value_type; \ Chris@16: static type zero() { return 0.0; } \ Chris@16: static type infinity() { return std::numeric_limits::infinity(); } \ Chris@16: }; Chris@16: Chris@16: /** Chris@16: * This generic type reports various numeric values for some type. In the Chris@16: * general case, numeric values simply treat their maximum value as infinity Chris@16: * and the default-constructed value as 0. Chris@16: * Chris@16: * Specializations of this template can redefine the notions of zero and Chris@16: * infinity for various types. For example, the class is specialized for Chris@16: * floating point types to use the built in notion of infinity. Chris@16: */ Chris@16: template Chris@16: struct numeric_values Chris@16: { Chris@16: typedef T value_type; Chris@16: Chris@16: static T zero() Chris@16: { return T(); } Chris@16: Chris@16: static T infinity() Chris@16: { return (std::numeric_limits::max)(); } Chris@16: }; Chris@16: Chris@16: // Specializations for floating point types refer to 0.0 and their infinity Chris@16: // value defined by numeric_limits. Chris@16: BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float) Chris@16: BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double) Chris@16: BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double) Chris@16: Chris@16: #undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE Chris@16: } Chris@16: Chris@16: #endif