Merge pull request #3 from ruslo/compare.errors

Fixed compare errors.
This commit is contained in:
Robert Ramey
2013-10-01 09:43:18 -07:00
2 changed files with 50 additions and 4 deletions

View File

@@ -508,7 +508,7 @@ typename boost::enable_if<
bool
>::type
operator<(const T & lhs, const safe_range_base<Stored, Derived> & rhs) {
return rhs >= lhs;
return rhs > lhs;
}
template<class T, class Stored, class Derived>
typename boost::enable_if<
@@ -516,7 +516,7 @@ typename boost::enable_if<
bool
>::type
inline operator>(const T & lhs, const safe_range_base<Stored, Derived> & rhs) {
return rhs <= lhs;
return rhs < lhs;
}
template<class T, class Stored, class Derived>
typename boost::enable_if<
@@ -540,7 +540,7 @@ typename boost::enable_if<
bool
>::type
inline operator>=(const T & lhs, const safe_range_base<Stored, Derived> & rhs) {
return rhs < lhs;
return rhs <= lhs;
}
template<class T, class Stored, class Derived>
typename boost::enable_if<
@@ -548,7 +548,7 @@ typename boost::enable_if<
bool
>::type
inline operator<=(const T & lhs, const safe_range_base<Stored, Derived> & rhs) {
return rhs > lhs;
return rhs >= lhs;
}
// addition

View File

@@ -0,0 +1,46 @@
// Copyright (c) 2013 Ruslan Baratov
//
// 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)
#include "../include/safe_integer.hpp"
#include <cassert>
template <class T>
void test_equal(T test_val) {
namespace num = boost::numeric;
num::safe<T> x = test_val;
num::safe<T> y = test_val;
assert(x == y);
assert(x >= y);
assert(x <= y);
assert(!(x < y));
assert(!(x > y));
}
template <class T>
void test_non_equal(T test_val) {
namespace num = boost::numeric;
num::safe<T> x(test_val);
num::safe<T> y(test_val + 1);
assert(x != y);
assert(!(x >= y));
assert(x <= y);
assert(x < y);
assert(!(x > y));
}
int main() {
test_equal<unsigned>(0);
test_equal<unsigned>(3);
test_equal<unsigned short>(14);
test_equal<int>(3);
test_equal<uint64_t>(45);
test_non_equal<unsigned>(342);
test_non_equal<signed char>(33);
test_non_equal<int32_t>(-988);
}