diff --git a/class_concept_checks_fail_expected.cpp b/class_concept_checks_fail_expected.cpp index 7cbe030..24743d6 100644 --- a/class_concept_checks_fail_expected.cpp +++ b/class_concept_checks_fail_expected.cpp @@ -19,7 +19,7 @@ using namespace boost; class class_requires_test { - typedef class_requires< EqualityComparableConcept >::check req; + BOOST_CLASS_REQUIRES(foo, EqualityComparableConcept); }; int diff --git a/class_concept_checks_test.cpp b/class_concept_checks_test.cpp index 3319560..3c908da 100644 --- a/class_concept_checks_test.cpp +++ b/class_concept_checks_test.cpp @@ -21,12 +21,11 @@ using namespace boost; class class_requires_test { - typedef class_requires< EqualityComparableConcept >::check req1; - typedef class_requires >::check req2; - typedef class_requires >::check req3; - typedef class_requires >::check req4; - typedef class_requires >::check - req5; + BOOST_CLASS_REQUIRES(int, EqualityComparableConcept); + typedef int* int_ptr; typedef const int* const_int_ptr; + BOOST_CLASS_REQUIRES2(int_ptr, const_int_ptr, Comparable2Concept); + BOOST_CLASS_REQUIRES3(foo, bool, int, UnaryFunctionConcept); + BOOST_CLASS_REQUIRES4(bar, bool, int, char, BinaryFunctionConcept); }; int diff --git a/include/boost/pending/concept_checks.hpp b/include/boost/pending/concept_checks.hpp index 898505b..71ac2fa 100644 --- a/include/boost/pending/concept_checks.hpp +++ b/include/boost/pending/concept_checks.hpp @@ -32,21 +32,42 @@ void function_requires() #endif } -template -class class_requires -{ -#if defined(NDEBUG) -public: - typedef int check; -#else - typedef void (Concept::* function_pointer)(); +// The BOOST_CLASS_REQUIRES macros use function pointers as +// template parameters, which VC++ does not support. + +#define BOOST_CLASS_REQUIRES(type_var, concept) \ + typedef void (concept ::* func##type_var##concept)(); \ + template \ + struct concept_checking_##type_var##concept { }; \ + typedef concept_checking_##type_var##concept< \ + BOOST_FPTR concept ::constraints> \ + concept_checking_typedef_##type_var##concept + +#define BOOST_CLASS_REQUIRES2(type_var1, type_var2, concept) \ + typedef void (concept ::* func##type_var1##type_var2##concept)(); \ + template \ + struct concept_checking_##type_var1##type_var2##concept { }; \ + typedef concept_checking_##type_var1##type_var2##concept< \ + BOOST_FPTR concept ::constraints> \ + concept_checking_typedef_##type_var1##type_var2##concept + +#define BOOST_CLASS_REQUIRES3(type_var1, type_var2, type_var3, concept) \ + typedef void (concept ::* func##type_var1##type_var2##type_var3##concept)(); \ + template \ + struct concept_checking_##type_var1##type_var2##type_var3##concept { }; \ + typedef concept_checking_##type_var1##type_var2##type_var3##concept< \ + BOOST_FPTR concept ::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 ::* func##type_var1##type_var2##type_var3##type_var4##concept)(); \ + template \ + 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 ::constraints> \ + concept_checking_typedef_##type_var1##type_var2##type_var3##type_var4##concept + - template - struct dummy_struct { }; -public: - typedef dummy_struct< BOOST_FPTR Concept::constraints > check; -#endif -}; #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template @@ -64,7 +85,7 @@ struct require_same { typedef T type; }; struct IntegerConcept { void constraints() { #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - error__type_must_be_an_integer_type(); + errortype_must_be_an_integer_type(); #endif } }; @@ -82,7 +103,7 @@ struct require_same { typedef T type; }; struct SignedIntegerConcept { void constraints() { #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - error__type_must_be_a_signed_integer_type(); + errortype_must_be_a_signed_integer_type(); #endif } }; @@ -97,7 +118,7 @@ struct require_same { typedef T type; }; struct UnsignedIntegerConcept { void constraints() { #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - error__type_must_be_an_unsigned_integer_type(); + errortype_must_be_an_unsigned_integer_type(); #endif } }; @@ -167,22 +188,22 @@ struct require_same { typedef T type; }; } }; - template + template struct CopyConstructibleConcept { void constraints() { - T a(b); // require copy constructor - T* ptr = &a; // require address of operator + TT a(b); // require copy constructor + TT* ptr = &a; // require address of operator const_constraints(a); ignore_unused_variable_warning(ptr); } - void const_constraints(const T& a) { - T c(a); // require const copy constructor - const T* ptr = &a; // require const address of operator + void const_constraints(const TT& a) { + TT c(a); // require const copy constructor + const TT* ptr = &a; // require const address of operator ignore_unused_variable_warning(c); ignore_unused_variable_warning(ptr); } - T b; + TT b; }; // 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 // specify stuff about all the logical operators. // For now we just test for convertible to bool. - template - void require_boolean_expr(const T& t) { + template + void require_boolean_expr(const TT& t) { bool x = t; ignore_unused_variable_warning(x); } @@ -447,71 +468,71 @@ struct require_same { typedef T type; }; //=========================================================================== // Function Object Concepts - template + template struct GeneratorConcept { void constraints() { - __r = __f(); // require operator() member function + r = f(); // require operator() member function } - _Func __f; - _Ret __r; + Func f; + Return r; }; #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct GeneratorConcept<_Func,void> + template + struct GeneratorConcept { void constraints() { - __f(); // require operator() member function + f(); // require operator() member function } - _Func __f; + Func f; }; #endif - template + template struct UnaryFunctionConcept { void constraints() { - __r = __f(__arg); // require operator() + r = f(arg); // require operator() } - _Func __f; - _Arg __arg; - _Ret __r; + Func f; + Arg arg; + Return r; }; #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct UnaryFunctionConcept<_Func,void,_Arg> { + template + struct UnaryFunctionConcept { void constraints() { - __f(__arg); // require operator() + f(arg); // require operator() } - _Func __f; + Func f; }; #endif - template + template struct BinaryFunctionConcept { void constraints() { - __r = __f(__first, __second); // require operator() + r = f(first, second); // require operator() } - _Func __f; - _First __first; - _Second __second; - _Ret __r; + Func f; + First first; + Second second; + Return r; }; #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - template - struct BinaryFunctionConcept<_Func,void,_First,_Second> + template + struct BinaryFunctionConcept { void constraints() { - __f(__first, __second); // require operator() + f(first, second); // require operator() } - _Func __f; - _First __first; - _Second __second; + Func f; + First first; + Second second; }; #endif @@ -568,7 +589,7 @@ struct require_same { typedef T type; }; struct NAME { \ void constraints() { (void)constraints_(); } \ Ret constraints_() { \ - Ret x = a OP b; \ + return a OP b; \ } \ First a; \ Second b; \