Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:34

0001 // (C) Copyright 2007-2009 Andrew Sutton
0002 //
0003 // Use, modification and distribution are subject to the
0004 // Boost Software License, Version 1.0 (See accompanying file
0005 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 #ifndef BOOST_GRAPH_NUMERIC_VALUES_HPP
0008 #define BOOST_GRAPH_NUMERIC_VALUES_HPP
0009 
0010 #include <limits>
0011 
0012 namespace boost
0013 {
0014 
0015 #define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type)          \
0016     template <> struct numeric_values< type >               \
0017     {                                                       \
0018         typedef type value_type;                            \
0019         static type zero() { return 0.0; }                  \
0020         static type infinity()                              \
0021         {                                                   \
0022             return std::numeric_limits< type >::infinity(); \
0023         }                                                   \
0024     };
0025 
0026 /**
0027  * This generic type reports various numeric values for some type. In the
0028  * general case, numeric values simply treat their maximum value as infinity
0029  * and the default-constructed value as 0.
0030  *
0031  * Specializations of this template can redefine the notions of zero and
0032  * infinity for various types. For example, the class is specialized for
0033  * floating point types to use the built in notion of infinity.
0034  */
0035 template < typename T > struct numeric_values
0036 {
0037     typedef T value_type;
0038 
0039     static T zero() { return T(); }
0040 
0041     static T infinity() { return (std::numeric_limits< T >::max)(); }
0042 };
0043 
0044 // Specializations for floating point types refer to 0.0 and their infinity
0045 // value defined by numeric_limits.
0046 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float)
0047 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double)
0048 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double)
0049 
0050 #undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE
0051 }
0052 
0053 #endif