1// (C) Copyright 2007-2009 Andrew Sutton
2//
3// Use, modification and distribution are subject to the
4// Boost Software License, Version 1.0 (See accompanying file
5// LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
6
7#ifndef BOOST_GRAPH_NUMERIC_VALUES_HPP
8#define BOOST_GRAPH_NUMERIC_VALUES_HPP
9
10#include <limits>
11
12namespace boost
13{
14
15#define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type) \
16 template <> struct numeric_values<type> { \
17 typedef type value_type; \
18 static type zero() { return 0.0; } \
19 static type infinity() { return std::numeric_limits<type>::infinity(); } \
20 };
21
22 /**
23 * This generic type reports various numeric values for some type. In the
24 * general case, numeric values simply treat their maximum value as infinity
25 * and the default-constructed value as 0.
26 *
27 * Specializations of this template can redefine the notions of zero and
28 * infinity for various types. For example, the class is specialized for
29 * floating point types to use the built in notion of infinity.
30 */
31 template <typename T>
32 struct numeric_values
33 {
34 typedef T value_type;
35
36 static T zero()
37 { return T(); }
38
39 static T infinity()
40 { return (std::numeric_limits<T>::max)(); }
41 };
42
43 // Specializations for floating point types refer to 0.0 and their infinity
44 // value defined by numeric_limits.
45 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float)
46 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double)
47 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double)
48
49#undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE
50}
51
52#endif
53

source code of boost/boost/graph/numeric_values.hpp