Boost logo

Boost :

Subject: [boost] [typeof] Variadic functions
From: Sergey Zubkovsky (sergzub_at_[hidden])
Date: 2009-11-21 11:54:23


Hi,

Here is a patch to support variadic functions in the Boost.Typeof.
Can anyone check it and commit?

Thank you.

Index: register_functions.hpp
===================================================================
--- register_functions.hpp (revision 57837)
+++ register_functions.hpp (working copy)
@@ -18,18 +18,25 @@
 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
 
 #ifndef BOOST_TYPEOF_LIMIT_FUNCTION_ARITY
-#define BOOST_TYPEOF_LIMIT_FUNCTION_ARITY 10
+#define BOOST_TYPEOF_LIMIT_FUNCTION_ARITY 15
 #endif
 
 enum
 {
     FUN_ID = BOOST_TYPEOF_UNIQUE_ID(),
- FUN_PTR_ID = FUN_ID + 1 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
- FUN_REF_ID = FUN_ID + 2 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
- MEM_FUN_ID = FUN_ID + 3 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
- CONST_MEM_FUN_ID = FUN_ID + 4 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
- VOLATILE_MEM_FUN_ID = FUN_ID + 5 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
- VOLATILE_CONST_MEM_FUN_ID = FUN_ID + 6 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY)
+ FUN_VAR_ID = FUN_ID + 1 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_PTR_ID = FUN_ID + 2 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_VAR_PTR_ID = FUN_ID + 3 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_REF_ID = FUN_ID + 4 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_VAR_REF_ID = FUN_ID + 5 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ MEM_FUN_ID = FUN_ID + 6 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ MEM_FUN_VAR_ID = FUN_ID + 7 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ CONST_MEM_FUN_ID = FUN_ID + 8 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ CONST_MEM_FUN_VAR_ID = FUN_ID + 9 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ VOLATILE_MEM_FUN_ID = FUN_ID + 10 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ VOLATILE_MEM_FUN_VAR_ID = FUN_ID + 11 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ VOLATILE_CONST_MEM_FUN_ID = FUN_ID + 12 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ VOLATILE_CONST_MEM_FUN_VAR_ID = FUN_ID + 13 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY)
 };
 
 BOOST_TYPEOF_BEGIN_ENCODE_NS
Index: register_functions_iterate.hpp
===================================================================
--- register_functions_iterate.hpp (revision 57837)
+++ register_functions_iterate.hpp (working copy)
@@ -6,6 +6,12 @@
 
 #define n BOOST_PP_ITERATION()
 
+#if ( n > 1 )
+# define comma ,
+#else
+# define comma
+#endif
+
 // function pointers
 
 template<class V, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)>
@@ -15,6 +21,13 @@
     typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_PTR_ID + n) type;
 };
 
+template<class V, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)>
+struct encode_type_impl<V, R(*)(BOOST_PP_ENUM_PARAMS(n, P)comma ...)>
+{
+ typedef R BOOST_PP_CAT(P, n);
+ typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_PTR_ID + n) type;
+};
+
 template<class Iter>
 struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
 {
@@ -24,6 +37,15 @@
     typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
 };
 
+template<class Iter>
+struct decode_type_impl<boost::mpl::size_t<FUN_VAR_PTR_ID + n>, Iter>
+{
+ typedef Iter iter0;
+ BOOST_TYPEOF_DECODE_PARAMS(BOOST_PP_INC(n))
+ typedef BOOST_PP_CAT(p, n)(*type)(BOOST_PP_ENUM_PARAMS(n, p)comma ...);
+ typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
+};
+
 #ifndef BOOST_TYPEOF_NO_FUNCTION_TYPES
 
     // function references
@@ -35,6 +57,13 @@
         typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_REF_ID + n) type;
     };
 
+ template<class V, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)>
+ struct encode_type_impl<V, R(&)(BOOST_PP_ENUM_PARAMS(n, P)comma ...)>
+ {
+ typedef R BOOST_PP_CAT(P, n);
+ typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_REF_ID + n) type;
+ };
+
     template<class Iter>
     struct decode_type_impl<boost::mpl::size_t<FUN_REF_ID + n>, Iter>
     {
@@ -53,6 +82,13 @@
         typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_ID + n) type;
     };
 
+ template<class V, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)>
+ struct encode_type_impl<V, R(BOOST_PP_ENUM_PARAMS(n, P)comma ...)>
+ {
+ typedef R BOOST_PP_CAT(P, n);
+ typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_ID + n) type;
+ };
+
     template<class Iter>
     struct decode_type_impl<boost::mpl::size_t<FUN_ID + n>, Iter>
     {
@@ -62,6 +98,15 @@
         typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
     };
 
+ template<class Iter>
+ struct decode_type_impl<boost::mpl::size_t<FUN_VAR_ID + n>, Iter>
+ {
+ typedef Iter iter0;
+ BOOST_TYPEOF_DECODE_PARAMS(BOOST_PP_INC(n))
+ typedef BOOST_PP_CAT(p, n)(type)(BOOST_PP_ENUM_PARAMS(n, p)comma ...);
+ typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
+ };
+
 #endif//BOOST_TYPEOF_NO_FUNCTION_TYPES
 
 #ifndef BOOST_TYPEOF_NO_MEMBER_FUNCTION_TYPES
@@ -83,5 +128,6 @@
 #define BOOST_TYPEOF_id VOLATILE_CONST_MEM_FUN_ID
 #include <boost/typeof/register_mem_functions.hpp>
 
+#undef comma
 #undef n
 #endif


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk