forked from boostorg/concept_check
put back the CLASS_REQUIRES macro
[SVN r8324]
This commit is contained in:
@@ -19,7 +19,7 @@ using namespace boost;
|
|||||||
|
|
||||||
class class_requires_test
|
class class_requires_test
|
||||||
{
|
{
|
||||||
typedef class_requires< EqualityComparableConcept<foo> >::check req;
|
BOOST_CLASS_REQUIRES(foo, EqualityComparableConcept);
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@@ -21,12 +21,11 @@ using namespace boost;
|
|||||||
|
|
||||||
class class_requires_test
|
class class_requires_test
|
||||||
{
|
{
|
||||||
typedef class_requires< EqualityComparableConcept<int> >::check req1;
|
BOOST_CLASS_REQUIRES(int, EqualityComparableConcept);
|
||||||
typedef class_requires<EqualityComparableConcept<int> >::check req2;
|
typedef int* int_ptr; typedef const int* const_int_ptr;
|
||||||
typedef class_requires<Comparable2Concept<int*, const int*> >::check req3;
|
BOOST_CLASS_REQUIRES2(int_ptr, const_int_ptr, Comparable2Concept);
|
||||||
typedef class_requires<UnaryFunctionConcept<foo, bool, int> >::check req4;
|
BOOST_CLASS_REQUIRES3(foo, bool, int, UnaryFunctionConcept);
|
||||||
typedef class_requires<BinaryFunctionConcept<bar, bool, int, char> >::check
|
BOOST_CLASS_REQUIRES4(bar, bool, int, char, BinaryFunctionConcept);
|
||||||
req5;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@@ -32,21 +32,42 @@ void function_requires()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Concept>
|
// The BOOST_CLASS_REQUIRES macros use function pointers as
|
||||||
class class_requires
|
// template parameters, which VC++ does not support.
|
||||||
{
|
|
||||||
#if defined(NDEBUG)
|
#define BOOST_CLASS_REQUIRES(type_var, concept) \
|
||||||
public:
|
typedef void (concept <type_var>::* func##type_var##concept)(); \
|
||||||
typedef int check;
|
template <func##type_var##concept _Tp1> \
|
||||||
#else
|
struct concept_checking_##type_var##concept { }; \
|
||||||
typedef void (Concept::* function_pointer)();
|
typedef concept_checking_##type_var##concept< \
|
||||||
|
BOOST_FPTR concept <type_var>::constraints> \
|
||||||
|
concept_checking_typedef_##type_var##concept
|
||||||
|
|
||||||
|
#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept) \
|
||||||
|
typedef void (concept <type_var1,type_var2>::* func##type_var1##type_var2##concept)(); \
|
||||||
|
template <func##type_var1##type_var2##concept _Tp1> \
|
||||||
|
struct concept_checking_##type_var1##type_var2##concept { }; \
|
||||||
|
typedef concept_checking_##type_var1##type_var2##concept< \
|
||||||
|
BOOST_FPTR concept <type_var1,type_var2>::constraints> \
|
||||||
|
concept_checking_typedef_##type_var1##type_var2##concept
|
||||||
|
|
||||||
|
#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept) \
|
||||||
|
typedef void (concept <type_var1,type_var2,type_var3>::* func##type_var1##type_var2##type_var3##concept)(); \
|
||||||
|
template <func##type_var1##type_var2##type_var3##concept _Tp1> \
|
||||||
|
struct concept_checking_##type_var1##type_var2##type_var3##concept { }; \
|
||||||
|
typedef concept_checking_##type_var1##type_var2##type_var3##concept< \
|
||||||
|
BOOST_FPTR concept <type_var1,type_var2,type_var3>::constraints> \
|
||||||
|
concept_checking_typedef_##type_var1##type_var2##type_var3##concept
|
||||||
|
|
||||||
|
#define BOOST_CLASS_REQUIRES4(type_var1, type_var2, type_var3, type_var4, concept) \
|
||||||
|
typedef void (concept <type_var1,type_var2,type_var3,type_var4>::* func##type_var1##type_var2##type_var3##type_var4##concept)(); \
|
||||||
|
template <func##type_var1##type_var2##type_var3##type_var4##concept _Tp1> \
|
||||||
|
struct concept_checking_##type_var1##type_var2##type_var3##type_var4##concept { }; \
|
||||||
|
typedef concept_checking_##type_var1##type_var2##type_var3##type_var4##concept< \
|
||||||
|
BOOST_FPTR concept <type_var1,type_var2,type_var3,type_var4>::constraints> \
|
||||||
|
concept_checking_typedef_##type_var1##type_var2##type_var3##type_var4##concept
|
||||||
|
|
||||||
|
|
||||||
template <function_pointer Fptr>
|
|
||||||
struct dummy_struct { };
|
|
||||||
public:
|
|
||||||
typedef dummy_struct< BOOST_FPTR Concept::constraints > check;
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template <class T, class U>
|
template <class T, class U>
|
||||||
@@ -64,7 +85,7 @@ struct require_same { typedef T type; };
|
|||||||
struct IntegerConcept {
|
struct IntegerConcept {
|
||||||
void constraints() {
|
void constraints() {
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
error__type_must_be_an_integer_type();
|
errortype_must_be_an_integer_type();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -82,7 +103,7 @@ struct require_same { typedef T type; };
|
|||||||
struct SignedIntegerConcept {
|
struct SignedIntegerConcept {
|
||||||
void constraints() {
|
void constraints() {
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
error__type_must_be_a_signed_integer_type();
|
errortype_must_be_a_signed_integer_type();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -97,7 +118,7 @@ struct require_same { typedef T type; };
|
|||||||
struct UnsignedIntegerConcept {
|
struct UnsignedIntegerConcept {
|
||||||
void constraints() {
|
void constraints() {
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
error__type_must_be_an_unsigned_integer_type();
|
errortype_must_be_an_unsigned_integer_type();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -167,22 +188,22 @@ struct require_same { typedef T type; };
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class TT>
|
||||||
struct CopyConstructibleConcept
|
struct CopyConstructibleConcept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
T a(b); // require copy constructor
|
TT a(b); // require copy constructor
|
||||||
T* ptr = &a; // require address of operator
|
TT* ptr = &a; // require address of operator
|
||||||
const_constraints(a);
|
const_constraints(a);
|
||||||
ignore_unused_variable_warning(ptr);
|
ignore_unused_variable_warning(ptr);
|
||||||
}
|
}
|
||||||
void const_constraints(const T& a) {
|
void const_constraints(const TT& a) {
|
||||||
T c(a); // require const copy constructor
|
TT c(a); // require const copy constructor
|
||||||
const T* ptr = &a; // require const address of operator
|
const TT* ptr = &a; // require const address of operator
|
||||||
ignore_unused_variable_warning(c);
|
ignore_unused_variable_warning(c);
|
||||||
ignore_unused_variable_warning(ptr);
|
ignore_unused_variable_warning(ptr);
|
||||||
}
|
}
|
||||||
T b;
|
TT b;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The C++ standard requirements for many concepts talk about return
|
// The C++ standard requirements for many concepts talk about return
|
||||||
@@ -194,8 +215,8 @@ struct require_same { typedef T type; };
|
|||||||
// 2) stay with convertible to bool, and also
|
// 2) stay with convertible to bool, and also
|
||||||
// specify stuff about all the logical operators.
|
// specify stuff about all the logical operators.
|
||||||
// For now we just test for convertible to bool.
|
// For now we just test for convertible to bool.
|
||||||
template <class T>
|
template <class TT>
|
||||||
void require_boolean_expr(const T& t) {
|
void require_boolean_expr(const TT& t) {
|
||||||
bool x = t;
|
bool x = t;
|
||||||
ignore_unused_variable_warning(x);
|
ignore_unused_variable_warning(x);
|
||||||
}
|
}
|
||||||
@@ -447,71 +468,71 @@ struct require_same { typedef T type; };
|
|||||||
//===========================================================================
|
//===========================================================================
|
||||||
// Function Object Concepts
|
// Function Object Concepts
|
||||||
|
|
||||||
template <class _Func, class _Ret>
|
template <class Func, class Return>
|
||||||
struct GeneratorConcept
|
struct GeneratorConcept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__r = __f(); // require operator() member function
|
r = f(); // require operator() member function
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
_Ret __r;
|
Return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template <class _Func>
|
template <class Func>
|
||||||
struct GeneratorConcept<_Func,void>
|
struct GeneratorConcept<Func,void>
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__f(); // require operator() member function
|
f(); // require operator() member function
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class _Func, class _Ret, class _Arg>
|
template <class Func, class Return, class Arg>
|
||||||
struct UnaryFunctionConcept
|
struct UnaryFunctionConcept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__r = __f(__arg); // require operator()
|
r = f(arg); // require operator()
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
_Arg __arg;
|
Arg arg;
|
||||||
_Ret __r;
|
Return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template <class _Func, class _Arg>
|
template <class Func, class Arg>
|
||||||
struct UnaryFunctionConcept<_Func,void,_Arg> {
|
struct UnaryFunctionConcept<Func, void, Arg> {
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__f(__arg); // require operator()
|
f(arg); // require operator()
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <class _Func, class _Ret, class _First, class _Second>
|
template <class Func, class Return, class First, class Second>
|
||||||
struct BinaryFunctionConcept
|
struct BinaryFunctionConcept
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__r = __f(__first, __second); // require operator()
|
r = f(first, second); // require operator()
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
_First __first;
|
First first;
|
||||||
_Second __second;
|
Second second;
|
||||||
_Ret __r;
|
Return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
#if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
template <class _Func, class _First, class _Second>
|
template <class Func, class First, class Second>
|
||||||
struct BinaryFunctionConcept<_Func,void,_First,_Second>
|
struct BinaryFunctionConcept<Func, void, First, Second>
|
||||||
{
|
{
|
||||||
void constraints() {
|
void constraints() {
|
||||||
__f(__first, __second); // require operator()
|
f(first, second); // require operator()
|
||||||
}
|
}
|
||||||
_Func __f;
|
Func f;
|
||||||
_First __first;
|
First first;
|
||||||
_Second __second;
|
Second second;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -568,7 +589,7 @@ struct require_same { typedef T type; };
|
|||||||
struct NAME { \
|
struct NAME { \
|
||||||
void constraints() { (void)constraints_(); } \
|
void constraints() { (void)constraints_(); } \
|
||||||
Ret constraints_() { \
|
Ret constraints_() { \
|
||||||
Ret x = a OP b; \
|
return a OP b; \
|
||||||
} \
|
} \
|
||||||
First a; \
|
First a; \
|
||||||
Second b; \
|
Second b; \
|
||||||
|
Reference in New Issue
Block a user