diff --git a/include/boost/counting_iterator.hpp b/include/boost/counting_iterator.hpp index f4795fd..3a8762e 100644 --- a/include/boost/counting_iterator.hpp +++ b/include/boost/counting_iterator.hpp @@ -28,6 +28,8 @@ // Incrementable. // // Revision History +// 09 Feb 2001 Factored out is_numeric computation. Borland still +// unhappy :( (David Abrahams) // 08 Feb 2001 Beginning of a failed attempt to appease Borland // (David Abrahams) // 07 Feb 2001 rename counting_iterator() -> make_counting_iterator() @@ -117,20 +119,29 @@ namespace detail { }; }; + // Try to detect numeric types at compile time in ways compatible with the + // limitations of the compiler and library. + template + struct is_numeric { + enum { value = +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS + std::numeric_limits::is_specialized +#elif defined(__BORLANDC__) + ::boost::is_integral::value || ::boost::is_same::value +#else + boost::is_convertible::value && boost::is_convertible::value +#endif + }; + }; + // Compute the distance over arbitrary numeric and/or iterator types template Distance any_distance(Incrementable start, Incrementable finish, Distance* = 0) { - return distance_policy_select< -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS - std::numeric_limits::is_specialized -#else - // Causes warnings with GCC, but how else can I detect numeric types - // at compile-time? - (boost::is_convertible::value && - boost::is_convertible::value) -#endif - >::template policy::distance(start, finish); + + return distance_policy_select<( + is_numeric::value)>::template + policy::distance(start, finish); } } // namespace detail @@ -138,19 +149,10 @@ namespace detail { template struct counting_iterator_traits { private: - enum { - is_numeric = -#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS - std::numeric_limits::is_specialized -#else - // Try to detect numeric types at compile time - boost::is_convertible::value - && boost::is_convertible::value -#endif - }; - - typedef typename detail::counting_iterator_traits_select< - is_numeric>::template traits traits; + enum {numeric = detail::is_numeric::value }; + typedef typename detail::counting_iterator_traits_select<( + numeric + )>::template traits traits; public: typedef Incrementable value_type; typedef const Incrementable& reference;