forked from boostorg/concept_check
added Boolean_concept to concept checks to tighten up LessThanComparable
(thanks to Brian McNamara and Yassin Smaragdakis for catching this!) [SVN r7902]
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/pending/limits.hpp>
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__KCC) || defined(__ghs)
|
#if defined(__GNUC__) || defined(__KCC) || defined(__ghs)
|
||||||
#define BOOST_FPTR &
|
#define BOOST_FPTR &
|
||||||
@@ -190,13 +191,27 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
|
|||||||
T b;
|
T b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class TT>
|
||||||
|
struct Boolean_concept {
|
||||||
|
void constraints() {
|
||||||
|
b = x;
|
||||||
|
b = x || x;
|
||||||
|
b = x && x;
|
||||||
|
}
|
||||||
|
TT x;
|
||||||
|
bool b;
|
||||||
|
};
|
||||||
|
|
||||||
template <class TT>
|
template <class TT>
|
||||||
struct EqualityComparable_concept
|
struct EqualityComparable_concept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
r = a == b; // require equality operator
|
require_boolean_return(a == b);
|
||||||
r = a != b; // require inequality operator
|
require_boolean_return(a != b);
|
||||||
}
|
}
|
||||||
|
// Can't move the following outside, because it changes when
|
||||||
|
// the error message appears.
|
||||||
|
template <class B> void require_boolean_return(B) { REQUIRE(B, Boolean); }
|
||||||
TT a, b;
|
TT a, b;
|
||||||
bool r;
|
bool r;
|
||||||
};
|
};
|
||||||
@@ -205,11 +220,15 @@ template <class T> void ignore_unused_variable_warning(const T&) { }
|
|||||||
struct LessThanComparable_concept
|
struct LessThanComparable_concept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
// require comparison operators
|
require_boolean_return(a < b);
|
||||||
r = a < b || a > b || a <= b || a >= b;
|
require_boolean_return(a > b);
|
||||||
|
require_boolean_return(a <= b);
|
||||||
|
require_boolean_return(a >= b);
|
||||||
}
|
}
|
||||||
|
// Can't move the following outside, because it changes when
|
||||||
|
// the error message appears.
|
||||||
|
template <class B> void require_boolean_return(B) { REQUIRE(B, Boolean); }
|
||||||
TT a, b;
|
TT a, b;
|
||||||
bool r;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
|
Reference in New Issue
Block a user