|
Boost : |
Subject: Re: [boost] [typeof] Variadic functions
From: Sergey Zubkovsky (sergzub_at_[hidden])
Date: 2010-01-22 16:05:45
Hi, Alexander!
You are right, thank you.
Here is the corrected patch.
Another error has been fixed too: struct
decode_type_impl<boost::mpl::size_t<FUN_VAR_REF_ID + n>, Iter>
definition was abcent.
Alexander Nasonov wrote:
> Oops, I didn't intend to send this to boost-devel. Here is the translation to English:
>
> ------------
> Hi Sergey,
> IIRC, comma is not required before '...'
> If it's required, you can use BOOST_PP_COMMA_IF(n).
> ------------
>
> Alex
>
> 21.01.10, 20:34, "Alexander Nasonov" <alnsn_at_[hidden]>:
>
>
>> Privet Sergey,
>> Po standartu kazhetsja zpt mozhno ne statit' pered ...
>> Nu a esli nado, to est' BOOST_PP_COMMA_IF(n)
>>
>> Sergey Zubkovsky wrote:
>> > 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 59225)
+++ register_functions.hpp (working copy)
@@ -24,12 +24,19 @@
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_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 + 7 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_VAR_PTR_ID = FUN_ID + 8 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ FUN_VAR_REF_ID = FUN_ID + 9 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ MEM_FUN_VAR_ID = FUN_ID + 10 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ CONST_MEM_FUN_VAR_ID = FUN_ID + 11 * BOOST_PP_INC(BOOST_TYPEOF_LIMIT_FUNCTION_ARITY),
+ VOLATILE_MEM_FUN_VAR_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 59225)
+++ register_functions_iterate.hpp (working copy)
@@ -15,6 +15,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) ...)>
+{
+ 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 +31,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) ...);
+ typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
+};
+
#ifndef BOOST_TYPEOF_NO_FUNCTION_TYPES
// function references
@@ -35,6 +51,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) ...)>
+ {
+ 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>
{
@@ -44,6 +67,15 @@
typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
};
+ template<class Iter>
+ struct decode_type_impl<boost::mpl::size_t<FUN_VAR_REF_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) ...);
+ typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
+ };
+
// functions
template<class V, class R BOOST_PP_ENUM_TRAILING_PARAMS(n, class P)>
@@ -53,6 +85,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) ...)>
+ {
+ 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 +101,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) ...);
+ typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter;
+ };
+
#endif//BOOST_TYPEOF_NO_FUNCTION_TYPES
#ifndef BOOST_TYPEOF_NO_MEMBER_FUNCTION_TYPES
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk