]> git.lyx.org Git - features.git/blobdiff - boost/boost/functional/hash/detail/float_functions.hpp
boost: add eol property
[features.git] / boost / boost / functional / hash / detail / float_functions.hpp
index b46b6735f86684e57d2867f03c91d3b301abeacc..01cac097224c4cab9d7b9bae64ed2760d734927a 100644 (file)
-\r
-// Copyright 2005-2009 Daniel James.\r
-// Distributed under the Boost Software License, Version 1.0. (See accompanying\r
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\r
-\r
-#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP)\r
-#define BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP\r
-\r
-#include <boost/config.hpp>\r
-#include <boost/config/no_tr1/cmath.hpp>\r
-\r
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)\r
-# pragma once\r
-#endif\r
-\r
-// The C++ standard requires that the C float functions are overloarded\r
-// for float, double and long double in the std namespace, but some of the older\r
-// library implementations don't support this. On some that don't, the C99\r
-// float functions (frexpf, frexpl, etc.) are available.\r
-//\r
-// The following tries to automatically detect which are available.\r
-\r
-namespace boost {\r
-    namespace hash_detail {\r
-\r
-        // Returned by dummy versions of the float functions.\r
-    \r
-        struct not_found {\r
-            // Implicitly convertible to float and long double in order to avoid\r
-            // a compile error when the dummy float functions are used.\r
-\r
-            inline operator float() const { return 0; }\r
-            inline operator long double() const { return 0; }\r
-        };\r
-          \r
-        // A type for detecting the return type of functions.\r
-\r
-        template <typename T> struct is;\r
-        template <> struct is<float> { char x[10]; };\r
-        template <> struct is<double> { char x[20]; };\r
-        template <> struct is<long double> { char x[30]; };\r
-        template <> struct is<boost::hash_detail::not_found> { char x[40]; };\r
-            \r
-        // Used to convert the return type of a function to a type for sizeof.\r
-\r
-        template <typename T> is<T> float_type(T);\r
-\r
-        // call_ldexp\r
-        //\r
-        // This will get specialized for float and long double\r
-        \r
-        template <typename Float> struct call_ldexp\r
-        {\r
-            typedef double float_type;\r
-            \r
-            inline double operator()(double a, int b) const\r
-            {\r
-                using namespace std;\r
-                return ldexp(a, b);\r
-            }\r
-        };\r
-\r
-        // call_frexp\r
-        //\r
-        // This will get specialized for float and long double\r
-\r
-        template <typename Float> struct call_frexp\r
-        {\r
-            typedef double float_type;\r
-            \r
-            inline double operator()(double a, int* b) const\r
-            {\r
-                using namespace std;\r
-                return frexp(a, b);\r
-            }\r
-        };\r
-    }\r
-}\r
-            \r
-// A namespace for dummy functions to detect when the actual function we want\r
-// isn't available. ldexpl, ldexpf etc. might be added tby the macros below.\r
-//\r
-// AFAICT these have to be outside of the boost namespace, as if they're in\r
-// the boost namespace they'll always be preferable to any other function\r
-// (since the arguments are built in types, ADL can't be used).\r
-\r
-namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS {\r
-    template <class Float> boost::hash_detail::not_found ldexp(Float, int);\r
-    template <class Float> boost::hash_detail::not_found frexp(Float, int*);    \r
-}\r
-\r
-// Macros for generating specializations of call_ldexp and call_frexp.\r
-//\r
-// check_cpp and check_c99 check if the C++ or C99 functions are available.\r
-//\r
-// Then the call_* functions select an appropriate implementation.\r
-//\r
-// I used c99_func in a few places just to get a unique name.\r
-//\r
-// Important: when using 'using namespace' at namespace level, include as\r
-// little as possible in that namespace, as Visual C++ has an odd bug which\r
-// can cause the namespace to be imported at the global level. This seems to\r
-// happen mainly when there's a template in the same namesapce.\r
-\r
-#define BOOST_HASH_CALL_FLOAT_FUNC(cpp_func, c99_func, type1, type2)    \\r
-namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS {                           \\r
-    template <class Float>                                              \\r
-    boost::hash_detail::not_found c99_func(Float, type2);               \\r
-}                                                                       \\r
-                                                                        \\r
-namespace boost {                                                       \\r
-    namespace hash_detail {                                             \\r
-        namespace c99_func##_detect {                                   \\r
-            using namespace std;                                        \\r
-            using namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS;          \\r
-                                                                        \\r
-            struct check {                                              \\r
-                static type1 x;                                         \\r
-                static type2 y;                                         \\r
-                BOOST_STATIC_CONSTANT(bool, cpp =                       \\r
-                    sizeof(float_type(cpp_func(x,y)))                   \\r
-                        == sizeof(is<type1>));                          \\r
-                BOOST_STATIC_CONSTANT(bool, c99 =                       \\r
-                    sizeof(float_type(c99_func(x,y)))                   \\r
-                        == sizeof(is<type1>));                          \\r
-            };                                                          \\r
-        }                                                               \\r
-                                                                        \\r
-        template <bool x>                                               \\r
-        struct call_c99_##c99_func :                                    \\r
-            boost::hash_detail::call_##cpp_func<double> {};             \\r
-                                                                        \\r
-        template <>                                                     \\r
-        struct call_c99_##c99_func<true> {                              \\r
-            typedef type1 float_type;                                   \\r
-                                                                        \\r
-            template <typename T>                                       \\r
-            inline type1 operator()(type1 a, T b)  const                \\r
-            {                                                           \\r
-                using namespace std;                                    \\r
-                return c99_func(a, b);                                  \\r
-            }                                                           \\r
-        };                                                              \\r
-                                                                        \\r
-        template <bool x>                                               \\r
-        struct call_cpp_##c99_func :                                    \\r
-            call_c99_##c99_func<                                        \\r
-                ::boost::hash_detail::c99_func##_detect::check::c99     \\r
-            > {};                                                       \\r
-                                                                        \\r
-        template <>                                                     \\r
-        struct call_cpp_##c99_func<true> {                              \\r
-            typedef type1 float_type;                                   \\r
-                                                                        \\r
-            template <typename T>                                       \\r
-            inline type1 operator()(type1 a, T b)  const                \\r
-            {                                                           \\r
-                using namespace std;                                    \\r
-                return cpp_func(a, b);                                  \\r
-            }                                                           \\r
-        };                                                              \\r
-                                                                        \\r
-        template <>                                                     \\r
-        struct call_##cpp_func<type1> :                                 \\r
-            call_cpp_##c99_func<                                        \\r
-                ::boost::hash_detail::c99_func##_detect::check::cpp     \\r
-            > {};                                                       \\r
-    }                                                                   \\r
-}\r
-\r
-#define BOOST_HASH_CALL_FLOAT_MACRO(cpp_func, c99_func, type1, type2)   \\r
-namespace boost {                                                       \\r
-    namespace hash_detail {                                             \\r
-                                                                        \\r
-        template <>                                                     \\r
-        struct call_##cpp_func<type1> {                                 \\r
-            typedef type1 float_type;                                   \\r
-            inline type1 operator()(type1 x, type2 y) const {           \\r
-                return c99_func(x, y);                                  \\r
-            }                                                           \\r
-        };                                                              \\r
-    }                                                                   \\r
-}\r
-\r
-#if defined(ldexpf)\r
-BOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpf, float, int)\r
-#else\r
-BOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpf, float, int)\r
-#endif\r
-\r
-#if defined(ldexpl)\r
-BOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpl, long double, int)\r
-#else\r
-BOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpl, long double, int)\r
-#endif\r
-\r
-#if defined(frexpf)\r
-BOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpf, float, int*)\r
-#else\r
-BOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpf, float, int*)\r
-#endif\r
-\r
-#if defined(frexpl)\r
-BOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpl, long double, int*)\r
-#else\r
-BOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpl, long double, int*)\r
-#endif\r
-\r
-#undef BOOST_HASH_CALL_FLOAT_MACRO\r
-#undef BOOST_HASH_CALL_FLOAT_FUNC\r
-\r
-\r
-namespace boost\r
-{\r
-    namespace hash_detail\r
-    {\r
-        template <typename Float1, typename Float2>\r
-        struct select_hash_type_impl {\r
-            typedef double type;\r
-        };\r
-\r
-        template <>\r
-        struct select_hash_type_impl<float, float> {\r
-            typedef float type;\r
-        };\r
-\r
-        template <>\r
-        struct select_hash_type_impl<long double, long double> {\r
-            typedef long double type;\r
-        };\r
-\r
-\r
-        // select_hash_type\r
-        //\r
-        // If there is support for a particular floating point type, use that\r
-        // otherwise use double (there's always support for double).\r
-             \r
-        template <typename Float>\r
-        struct select_hash_type : select_hash_type_impl<\r
-                BOOST_DEDUCED_TYPENAME call_ldexp<Float>::float_type,\r
-                BOOST_DEDUCED_TYPENAME call_frexp<Float>::float_type\r
-            > {};            \r
-    }\r
-}\r
-\r
-#endif\r
+
+// Copyright 2005-2009 Daniel James.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#if !defined(BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP)
+#define BOOST_FUNCTIONAL_HASH_DETAIL_FLOAT_FUNCTIONS_HPP
+
+#include <boost/config.hpp>
+#include <boost/config/no_tr1/cmath.hpp>
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+# pragma once
+#endif
+
+// The C++ standard requires that the C float functions are overloarded
+// for float, double and long double in the std namespace, but some of the older
+// library implementations don't support this. On some that don't, the C99
+// float functions (frexpf, frexpl, etc.) are available.
+//
+// The following tries to automatically detect which are available.
+
+namespace boost {
+    namespace hash_detail {
+
+        // Returned by dummy versions of the float functions.
+    
+        struct not_found {
+            // Implicitly convertible to float and long double in order to avoid
+            // a compile error when the dummy float functions are used.
+
+            inline operator float() const { return 0; }
+            inline operator long double() const { return 0; }
+        };
+          
+        // A type for detecting the return type of functions.
+
+        template <typename T> struct is;
+        template <> struct is<float> { char x[10]; };
+        template <> struct is<double> { char x[20]; };
+        template <> struct is<long double> { char x[30]; };
+        template <> struct is<boost::hash_detail::not_found> { char x[40]; };
+            
+        // Used to convert the return type of a function to a type for sizeof.
+
+        template <typename T> is<T> float_type(T);
+
+        // call_ldexp
+        //
+        // This will get specialized for float and long double
+        
+        template <typename Float> struct call_ldexp
+        {
+            typedef double float_type;
+            
+            inline double operator()(double a, int b) const
+            {
+                using namespace std;
+                return ldexp(a, b);
+            }
+        };
+
+        // call_frexp
+        //
+        // This will get specialized for float and long double
+
+        template <typename Float> struct call_frexp
+        {
+            typedef double float_type;
+            
+            inline double operator()(double a, int* b) const
+            {
+                using namespace std;
+                return frexp(a, b);
+            }
+        };
+    }
+}
+            
+// A namespace for dummy functions to detect when the actual function we want
+// isn't available. ldexpl, ldexpf etc. might be added tby the macros below.
+//
+// AFAICT these have to be outside of the boost namespace, as if they're in
+// the boost namespace they'll always be preferable to any other function
+// (since the arguments are built in types, ADL can't be used).
+
+namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS {
+    template <class Float> boost::hash_detail::not_found ldexp(Float, int);
+    template <class Float> boost::hash_detail::not_found frexp(Float, int*);    
+}
+
+// Macros for generating specializations of call_ldexp and call_frexp.
+//
+// check_cpp and check_c99 check if the C++ or C99 functions are available.
+//
+// Then the call_* functions select an appropriate implementation.
+//
+// I used c99_func in a few places just to get a unique name.
+//
+// Important: when using 'using namespace' at namespace level, include as
+// little as possible in that namespace, as Visual C++ has an odd bug which
+// can cause the namespace to be imported at the global level. This seems to
+// happen mainly when there's a template in the same namesapce.
+
+#define BOOST_HASH_CALL_FLOAT_FUNC(cpp_func, c99_func, type1, type2)    \
+namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS {                           \
+    template <class Float>                                              \
+    boost::hash_detail::not_found c99_func(Float, type2);               \
+}                                                                       \
+                                                                        \
+namespace boost {                                                       \
+    namespace hash_detail {                                             \
+        namespace c99_func##_detect {                                   \
+            using namespace std;                                        \
+            using namespace BOOST_HASH_DETECT_FLOAT_FUNCTIONS;          \
+                                                                        \
+            struct check {                                              \
+                static type1 x;                                         \
+                static type2 y;                                         \
+                BOOST_STATIC_CONSTANT(bool, cpp =                       \
+                    sizeof(float_type(cpp_func(x,y)))                   \
+                        == sizeof(is<type1>));                          \
+                BOOST_STATIC_CONSTANT(bool, c99 =                       \
+                    sizeof(float_type(c99_func(x,y)))                   \
+                        == sizeof(is<type1>));                          \
+            };                                                          \
+        }                                                               \
+                                                                        \
+        template <bool x>                                               \
+        struct call_c99_##c99_func :                                    \
+            boost::hash_detail::call_##cpp_func<double> {};             \
+                                                                        \
+        template <>                                                     \
+        struct call_c99_##c99_func<true> {                              \
+            typedef type1 float_type;                                   \
+                                                                        \
+            template <typename T>                                       \
+            inline type1 operator()(type1 a, T b)  const                \
+            {                                                           \
+                using namespace std;                                    \
+                return c99_func(a, b);                                  \
+            }                                                           \
+        };                                                              \
+                                                                        \
+        template <bool x>                                               \
+        struct call_cpp_##c99_func :                                    \
+            call_c99_##c99_func<                                        \
+                ::boost::hash_detail::c99_func##_detect::check::c99     \
+            > {};                                                       \
+                                                                        \
+        template <>                                                     \
+        struct call_cpp_##c99_func<true> {                              \
+            typedef type1 float_type;                                   \
+                                                                        \
+            template <typename T>                                       \
+            inline type1 operator()(type1 a, T b)  const                \
+            {                                                           \
+                using namespace std;                                    \
+                return cpp_func(a, b);                                  \
+            }                                                           \
+        };                                                              \
+                                                                        \
+        template <>                                                     \
+        struct call_##cpp_func<type1> :                                 \
+            call_cpp_##c99_func<                                        \
+                ::boost::hash_detail::c99_func##_detect::check::cpp     \
+            > {};                                                       \
+    }                                                                   \
+}
+
+#define BOOST_HASH_CALL_FLOAT_MACRO(cpp_func, c99_func, type1, type2)   \
+namespace boost {                                                       \
+    namespace hash_detail {                                             \
+                                                                        \
+        template <>                                                     \
+        struct call_##cpp_func<type1> {                                 \
+            typedef type1 float_type;                                   \
+            inline type1 operator()(type1 x, type2 y) const {           \
+                return c99_func(x, y);                                  \
+            }                                                           \
+        };                                                              \
+    }                                                                   \
+}
+
+#if defined(ldexpf)
+BOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpf, float, int)
+#else
+BOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpf, float, int)
+#endif
+
+#if defined(ldexpl)
+BOOST_HASH_CALL_FLOAT_MACRO(ldexp, ldexpl, long double, int)
+#else
+BOOST_HASH_CALL_FLOAT_FUNC(ldexp, ldexpl, long double, int)
+#endif
+
+#if defined(frexpf)
+BOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpf, float, int*)
+#else
+BOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpf, float, int*)
+#endif
+
+#if defined(frexpl)
+BOOST_HASH_CALL_FLOAT_MACRO(frexp, frexpl, long double, int*)
+#else
+BOOST_HASH_CALL_FLOAT_FUNC(frexp, frexpl, long double, int*)
+#endif
+
+#undef BOOST_HASH_CALL_FLOAT_MACRO
+#undef BOOST_HASH_CALL_FLOAT_FUNC
+
+
+namespace boost
+{
+    namespace hash_detail
+    {
+        template <typename Float1, typename Float2>
+        struct select_hash_type_impl {
+            typedef double type;
+        };
+
+        template <>
+        struct select_hash_type_impl<float, float> {
+            typedef float type;
+        };
+
+        template <>
+        struct select_hash_type_impl<long double, long double> {
+            typedef long double type;
+        };
+
+
+        // select_hash_type
+        //
+        // If there is support for a particular floating point type, use that
+        // otherwise use double (there's always support for double).
+             
+        template <typename Float>
+        struct select_hash_type : select_hash_type_impl<
+                BOOST_DEDUCED_TYPENAME call_ldexp<Float>::float_type,
+                BOOST_DEDUCED_TYPENAME call_frexp<Float>::float_type
+            > {};            
+    }
+}
+
+#endif