Changeset 7401 for code/trunk/src/libraries/util/VA_NARGS.h
- Timestamp:
- Sep 11, 2010, 12:34:00 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/doc (added) merged: 7290-7292,7296-7300,7302-7304,7306-7312,7315-7318,7323,7325,7327,7331-7332,7334-7335,7345-7347,7352-7353,7356-7357,7361,7363-7367,7371-7375,7388
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/util/VA_NARGS.h
r7284 r7401 29 29 /** 30 30 @file 31 @ingroup Util 31 32 @brief Declaration of the ORXONOX_VA_NARGS macro which returns the number of arguments passed to a variadic macro. 33 34 With this utility you can overload a macro for different numbers of arguments 35 (of course overloading is not possible for different types, as macros are not 36 type aware, but for different numbers of arguments is still very powerful). 37 38 Example: A macro to call functions 39 @code 40 myfunction(); // A static function 41 MyClass::myStaticFunction(); // A static class function 42 MyClass::myFunction(); // A member function 43 44 #define CallFunction(...) \ // Define a variadic macro that passes the arguments to the overloaded implementations 45 BOOST_PP_EXPAND(BOOST_PP_CAT(CallFunction, ORXONOX_VA_NARGS(__VA_ARGS__))(__VA_ARGS__)) 46 47 #define CallFunction1(function) \ // Overloaded macro for 1 argument 48 function() // Calls the static function 49 50 #define CallFunction2(class, function) \ // Overloaded macro for 2 arguments 51 class::function() // Calls the static class function 52 53 #define CallFunction3(class, function, object) \ // Overloaded macro for 3 arguments 54 object->class::function() // Calls the function on the object 55 56 57 CallFunction(myFunction); // Call the macro with 1 argument 58 CallFunction(MyClass, myStaticFunction); // Call the macro with 2 arguments 59 CallFunction(MyClass, myFunction, new MyClass()); // Call the macro with 3 arguments 60 @endcode 61 62 Note that the first (variadic) macro concatenates the name "CallFunction" with 63 the number of arguments ("1" - "N"). Then all arguments are passed to the right macro. 32 64 */ 33 65
Note: See TracChangeset
for help on using the changeset viewer.