Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 /* boost random/detail/signed_unsigned_compare.hpp header file
3 * Copyright Jens Maurer 2000-2001
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org for most recent version including documentation.
14 #ifndef BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_COMPARE
15 #define BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_COMPARE
17 #include <boost/limits.hpp>
23 * Correctly compare two numbers whose types possibly differ in signedness.
24 * See boost::numeric_cast<> for the general idea.
25 * Most "if" statements involve only compile-time constants, so the
26 * optimizing compiler can do its job easily.
28 * With most compilers, the straightforward implementation produces a
29 * bunch of (legitimate) warnings. Some template magic helps, though.
33 template<bool signed1, bool signed2>
38 struct do_compare<false, false>
40 // cast to the larger type is automatic with built-in types
41 template<class T1, class T2>
42 static bool equal(T1 x, T2 y) { return x == y; }
43 template<class T1, class T2>
44 static bool lessthan(T1 x, T2 y) { return x < y; }
48 struct do_compare<true, true> : do_compare<false, false>
52 struct do_compare<true, false>
54 template<class T1, class T2>
55 static bool equal(T1 x, T2 y) { return x >= 0 && static_cast<T2>(x) == y; }
56 template<class T1, class T2>
57 static bool lessthan(T1 x, T2 y) { return x < 0 || static_cast<T2>(x) < y; }
61 struct do_compare<false, true>
63 template<class T1, class T2>
64 static bool equal(T1 x, T2 y) { return y >= 0 && x == static_cast<T1>(y); }
65 template<class T1, class T2>
66 static bool lessthan(T1 x, T2 y) { return y >= 0 && x < static_cast<T1>(y); }
72 template<class T1, class T2>
73 int equal_signed_unsigned(T1 x, T2 y)
75 typedef std::numeric_limits<T1> x_traits;
76 typedef std::numeric_limits<T2> y_traits;
77 return detail::do_compare<x_traits::is_signed, y_traits::is_signed>::equal(x, y);
80 template<class T1, class T2>
81 int lessthan_signed_unsigned(T1 x, T2 y)
83 typedef std::numeric_limits<T1> x_traits;
84 typedef std::numeric_limits<T2> y_traits;
85 return detail::do_compare<x_traits::is_signed, y_traits::is_signed>::lessthan(x, y);
91 #endif // BOOST_RANDOM_DETAIL_SIGNED_UNSIGNED_COMPARE