forked from boostorg/iterator
Factored out is_numeric computation. Borland still unhappy :(
[SVN r9057]
This commit is contained in:
@ -28,6 +28,8 @@
|
|||||||
// Incrementable.
|
// Incrementable.
|
||||||
//
|
//
|
||||||
// Revision History
|
// 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
|
// 08 Feb 2001 Beginning of a failed attempt to appease Borland
|
||||||
// (David Abrahams)
|
// (David Abrahams)
|
||||||
// 07 Feb 2001 rename counting_iterator() -> make_counting_iterator()
|
// 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 <class T>
|
||||||
|
struct is_numeric {
|
||||||
|
enum { value =
|
||||||
|
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||||
|
std::numeric_limits<T>::is_specialized
|
||||||
|
#elif defined(__BORLANDC__)
|
||||||
|
::boost::is_integral<T>::value || ::boost::is_same<T,char>::value
|
||||||
|
#else
|
||||||
|
boost::is_convertible<int,T>::value && boost::is_convertible<T,int>::value
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// Compute the distance over arbitrary numeric and/or iterator types
|
// Compute the distance over arbitrary numeric and/or iterator types
|
||||||
template <class Distance, class Incrementable>
|
template <class Distance, class Incrementable>
|
||||||
Distance any_distance(Incrementable start, Incrementable finish, Distance* = 0)
|
Distance any_distance(Incrementable start, Incrementable finish, Distance* = 0)
|
||||||
{
|
{
|
||||||
return distance_policy_select<
|
|
||||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
return distance_policy_select<(
|
||||||
std::numeric_limits<Incrementable>::is_specialized
|
is_numeric<Incrementable>::value)>::template
|
||||||
#else
|
policy<Distance, Incrementable>::distance(start, finish);
|
||||||
// Causes warnings with GCC, but how else can I detect numeric types
|
|
||||||
// at compile-time?
|
|
||||||
(boost::is_convertible<int,Incrementable>::value &&
|
|
||||||
boost::is_convertible<Incrementable,int>::value)
|
|
||||||
#endif
|
|
||||||
>::template policy<Distance, Incrementable>::distance(start, finish);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
@ -138,19 +149,10 @@ namespace detail {
|
|||||||
template <class Incrementable>
|
template <class Incrementable>
|
||||||
struct counting_iterator_traits {
|
struct counting_iterator_traits {
|
||||||
private:
|
private:
|
||||||
enum {
|
enum {numeric = detail::is_numeric<Incrementable>::value };
|
||||||
is_numeric =
|
typedef typename detail::counting_iterator_traits_select<(
|
||||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
numeric
|
||||||
std::numeric_limits<Incrementable>::is_specialized
|
)>::template traits<Incrementable> traits;
|
||||||
#else
|
|
||||||
// Try to detect numeric types at compile time
|
|
||||||
boost::is_convertible<int,Incrementable>::value
|
|
||||||
&& boost::is_convertible<Incrementable,int>::value
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef typename detail::counting_iterator_traits_select<
|
|
||||||
is_numeric>::template traits<Incrementable> traits;
|
|
||||||
public:
|
public:
|
||||||
typedef Incrementable value_type;
|
typedef Incrementable value_type;
|
||||||
typedef const Incrementable& reference;
|
typedef const Incrementable& reference;
|
||||||
|
Reference in New Issue
Block a user