Some thoughts on Unary / BinaryFunctionConcept limitations
I'm just now learning about the concept_check library and how Unary and BinaryFunctionConcepts work in it. I have a few questions: (1) The implementation of Unary and Binary (FunctionConcepts) assume that the return type is assignable ("r = f(arg)" tries to assign a value to r). But what if the return type is a reference? Won't the function concept fail to compile? Is this a bug? (2) I'm implementing an NaryFunctionConcept for functors taking more than 2 arguments. The BOOST_CLASS_REQUIREx macro, however, appears to be limited to 4 types. This limits the NaryFunctionConcept to functors with up to two arguments. Is there a way to expand the BOOST_CLASS_REQUIREx macro to handle more than 4 types? (3) I ran into a compiler problem when using BOOST_CLASS_REQUIREx; when any of the type macros have spaces or non-alphanumeric characters in them, the compiler reports an error. In the following example, I try to use the macro to require a UnaryFunctor taking a const std::string & and returning an int. The code, however, fails to compile. Here's the code and error log: === CODE === template<typename T> class foo { BOOST_CLASS_REQUIRE3(T, int, const std::string &, boost, UnaryFunctionConcept); }; ============ Produces the following error (from g++): ==== ERROR LOG ==== test.cpp:42: error: parse error before `::' token test.cpp:42:80: pasting "&" and "UnaryFunctionConcept" does not give a valid preprocessing token test.cpp:42: error: parse error before `std' test.cpp:42:80: pasting "&" and "UnaryFunctionConcept" does not give a valid preprocessing token test.cpp:42:80: pasting "&" and "UnaryFunctionConcept" does not give a valid preprocessing token test.cpp:42: error: missing ';' before right brace test.cpp:42: confused by earlier errors, bailing out =================== Is this a bug? Thanks in advance for your thoughts, --Steve Stephen Gross Case Western School of Medicine Cleveland, OH "By Grabthar's hammer, by the sons of Worvan, you shall be avenged." - Dr. Lazarus
Hi Stephan, On Sep 12, 2005, at 9:25 AM, Stephen Gross wrote:
I'm just now learning about the concept_check library and how Unary and BinaryFunctionConcepts work in it. I have a few questions:
(1) The implementation of Unary and Binary (FunctionConcepts) assume that the return type is assignable ("r = f(arg)" tries to assign a value to r). But what if the return type is a reference? Won't the function concept fail to compile? Is this a bug?
That looks like a bug. Here's a challenge for you: how would you fix this bug?
(2) I'm implementing an NaryFunctionConcept for functors taking more than 2 arguments. The BOOST_CLASS_REQUIREx macro, however, appears to be limited to 4 types. This limits the NaryFunctionConcept to functors with up to two arguments. Is there a way to expand the BOOST_CLASS_REQUIREx macro to handle more than 4 types?
I'm sure there is a way. Can you think of a way to do it? Perhaps the boost preprocessor library would help.
(3) I ran into a compiler problem when using BOOST_CLASS_REQUIREx; when any of the type macros have spaces or non-alphanumeric characters in them, the compiler reports an error. In the following example, I try to use the macro to require a UnaryFunctor taking a const std::string & and returning an int.
Yes, you need to create a typedef for such types. This restriction should be documented. I've checked in a fix to the docs. Thanks, Jeremy
participants (2)
-
Jeremy Siek
-
Stephen Gross