From eff78826d21d6be7b8a1f1cb2a2ecb0df48cea86 Mon Sep 17 00:00:00 2001 From: Alexander Nasonov Date: Sun, 7 Feb 2010 19:13:43 +0000 Subject: [PATCH] Apply variadic functions patch from Sergey Zubkovsky. [SVN r59579] --- include/boost/typeof/register_functions.hpp | 19 +++++--- .../typeof/register_functions_iterate.hpp | 48 +++++++++++++++++++ test/function.cpp | 2 + test/function_binding.cpp | 16 +++++-- test/function_ptr.cpp | 17 +++++-- test/function_ptr_from_tpl.cpp | 20 +++++--- test/function_ref.cpp | 2 + 7 files changed, 103 insertions(+), 21 deletions(-) mode change 100755 => 100644 include/boost/typeof/register_functions.hpp mode change 100755 => 100644 include/boost/typeof/register_functions_iterate.hpp mode change 100755 => 100644 test/function.cpp mode change 100755 => 100644 test/function_binding.cpp mode change 100755 => 100644 test/function_ptr.cpp mode change 100755 => 100644 test/function_ptr_from_tpl.cpp mode change 100755 => 100644 test/function_ref.cpp diff --git a/include/boost/typeof/register_functions.hpp b/include/boost/typeof/register_functions.hpp old mode 100755 new mode 100644 index 2af7cec..407bba3 --- a/include/boost/typeof/register_functions.hpp +++ b/include/boost/typeof/register_functions.hpp @@ -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 diff --git a/include/boost/typeof/register_functions_iterate.hpp b/include/boost/typeof/register_functions_iterate.hpp old mode 100755 new mode 100644 index b1048ad..aaa43f3 --- a/include/boost/typeof/register_functions_iterate.hpp +++ b/include/boost/typeof/register_functions_iterate.hpp @@ -15,6 +15,13 @@ struct encode_type_impl typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_PTR_ID + n) type; }; +template +struct encode_type_impl +{ + typedef R BOOST_PP_CAT(P, n); + typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_PTR_ID + n) type; +}; + template struct decode_type_impl, Iter> { @@ -24,6 +31,15 @@ struct decode_type_impl, Iter> typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter; }; +template +struct decode_type_impl, 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 @@ struct decode_type_impl, Iter> typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_REF_ID + n) type; }; + template + struct encode_type_impl + { + typedef R BOOST_PP_CAT(P, n); + typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_REF_ID + n) type; + }; + template struct decode_type_impl, Iter> { @@ -44,6 +67,15 @@ struct decode_type_impl, Iter> typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter; }; + template + struct decode_type_impl, 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 @@ -53,6 +85,13 @@ struct decode_type_impl, Iter> typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_ID + n) type; }; + template + struct encode_type_impl + { + typedef R BOOST_PP_CAT(P, n); + typedef BOOST_TYPEOF_ENCODE_PARAMS(BOOST_PP_INC(n), FUN_VAR_ID + n) type; + }; + template struct decode_type_impl, Iter> { @@ -62,6 +101,15 @@ struct decode_type_impl, Iter> typedef BOOST_PP_CAT(iter, BOOST_PP_INC(n)) iter; }; + template + struct decode_type_impl, 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 diff --git a/test/function.cpp b/test/function.cpp old mode 100755 new mode 100644 index 86a4df2..f9a4e99 --- a/test/function.cpp +++ b/test/function.cpp @@ -6,3 +6,5 @@ BOOST_STATIC_ASSERT(boost::type_of::test::value); BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value); diff --git a/test/function_binding.cpp b/test/function_binding.cpp old mode 100755 new mode 100644 index 8ad1cf2..46a6016 --- a/test/function_binding.cpp +++ b/test/function_binding.cpp @@ -7,8 +7,16 @@ #include #include -int foo(double); -typedef int(&FREF)(double); -FREF fref = *foo; +int foo1(double); +int foo2(...); +int foo3(int, ...); +typedef int(&FREF1)(double); +typedef int(&FREF2)(...); +typedef int(&FREF3)(int, ...); +FREF1 fref1 = *foo1; +FREF2 fref2 = *foo2; +FREF3 fref3 = *foo3; -BOOST_STATIC_ASSERT((boost::is_same::value)); +BOOST_STATIC_ASSERT((boost::is_same::value)); +BOOST_STATIC_ASSERT((boost::is_same::value)); +BOOST_STATIC_ASSERT((boost::is_same::value)); diff --git a/test/function_ptr.cpp b/test/function_ptr.cpp old mode 100755 new mode 100644 index c6babfb..977546a --- a/test/function_ptr.cpp +++ b/test/function_ptr.cpp @@ -8,12 +8,19 @@ BOOST_STATIC_ASSERT(boost::type_of::test::value); BOOST_STATIC_ASSERT(boost::type_of::test::value); BOOST_STATIC_ASSERT(boost::type_of::test::value); BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value); // check that const gets stripped from function pointer -int foo(double); -typedef int(*PTR)(double); -typedef const PTR CPTR; -CPTR cptr = foo; +int foo1(double); +int foo2(...); +typedef int(*PTR1)(double); +typedef int(*PTR2)(...); +typedef const PTR1 CPTR1; +typedef const PTR2 CPTR2; +CPTR1 cptr1 = foo1; +CPTR2 cptr2 = foo2; -BOOST_STATIC_ASSERT((boost::is_same::value)); +BOOST_STATIC_ASSERT((boost::is_same::value)); +BOOST_STATIC_ASSERT((boost::is_same::value)); diff --git a/test/function_ptr_from_tpl.cpp b/test/function_ptr_from_tpl.cpp old mode 100755 new mode 100644 index 7b880a2..c048ede --- a/test/function_ptr_from_tpl.cpp +++ b/test/function_ptr_from_tpl.cpp @@ -6,15 +6,23 @@ #include #include -void f() -{} +void f1() {} +void f2(...) {} template -struct tpl +struct tpl1 { - typedef BOOST_TYPEOF_TPL(&f) type; + typedef BOOST_TYPEOF_TPL(&f1) type; }; -typedef void(*fun_type)(); +template +struct tpl2 +{ + typedef BOOST_TYPEOF_TPL(&f2) type; +}; + +typedef void(*fun1_type)(); +typedef void(*fun2_type)(...); -BOOST_STATIC_ASSERT((boost::is_same::type, fun_type>::value)); +BOOST_STATIC_ASSERT((boost::is_same::type, fun1_type>::value)); +BOOST_STATIC_ASSERT((boost::is_same::type, fun2_type>::value)); diff --git a/test/function_ref.cpp b/test/function_ref.cpp old mode 100755 new mode 100644 index b524e2a..0651276 --- a/test/function_ref.cpp +++ b/test/function_ref.cpp @@ -6,3 +6,5 @@ BOOST_STATIC_ASSERT(boost::type_of::test::value); BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value); +BOOST_STATIC_ASSERT(boost::type_of::test::value);