mirror of
https://github.com/boostorg/typeof.git
synced 2025-05-09 15:04:00 +00:00
Apply variadic functions patch from Sergey Zubkovsky.
[SVN r59579]
This commit is contained in:
parent
b420583f9c
commit
eff78826d2
19
include/boost/typeof/register_functions.hpp
Executable file → Normal file
19
include/boost/typeof/register_functions.hpp
Executable file → Normal file
@ -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
|
||||
|
48
include/boost/typeof/register_functions_iterate.hpp
Executable file → Normal file
48
include/boost/typeof/register_functions_iterate.hpp
Executable file → Normal file
@ -15,6 +15,13 @@ struct encode_type_impl<V, R(*)(BOOST_PP_ENUM_PARAMS(n, P))>
|
||||
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 @@ struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
|
||||
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 @@ struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
|
||||
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 @@ struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
|
||||
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 @@ struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
|
||||
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 @@ struct decode_type_impl<boost::mpl::size_t<FUN_PTR_ID + n>, Iter>
|
||||
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
|
||||
|
2
test/function.cpp
Executable file → Normal file
2
test/function.cpp
Executable file → Normal file
@ -6,3 +6,5 @@
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void()>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<double(bool)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(...)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<float(int, ...)>::value);
|
||||
|
16
test/function_binding.cpp
Executable file → Normal file
16
test/function_binding.cpp
Executable file → Normal file
@ -7,8 +7,16 @@
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
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<BOOST_TYPEOF(fref), int(double)>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(fref1), int(double)>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(fref2), int(...)>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(fref3), int(int,...)>::value));
|
||||
|
17
test/function_ptr.cpp
Executable file → Normal file
17
test/function_ptr.cpp
Executable file → Normal file
@ -8,12 +8,19 @@ BOOST_STATIC_ASSERT(boost::type_of::test<double(*)()>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<double(*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(*)()>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(*)(...)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(*)(int, double, short, char*, bool, char, float, long, unsigned short, ...)>::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<BOOST_TYPEOF(cptr), PTR>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(cptr1), PTR1>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(cptr2), PTR2>::value));
|
||||
|
20
test/function_ptr_from_tpl.cpp
Executable file → Normal file
20
test/function_ptr_from_tpl.cpp
Executable file → Normal file
@ -6,15 +6,23 @@
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
void f()
|
||||
{}
|
||||
void f1() {}
|
||||
void f2(...) {}
|
||||
|
||||
template<class T>
|
||||
struct tpl
|
||||
struct tpl1
|
||||
{
|
||||
typedef BOOST_TYPEOF_TPL(&f) type;
|
||||
typedef BOOST_TYPEOF_TPL(&f1) type;
|
||||
};
|
||||
|
||||
typedef void(*fun_type)();
|
||||
template<class T>
|
||||
struct tpl2
|
||||
{
|
||||
typedef BOOST_TYPEOF_TPL(&f2) type;
|
||||
};
|
||||
|
||||
typedef void(*fun1_type)();
|
||||
typedef void(*fun2_type)(...);
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<tpl<void>::type, fun_type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<tpl1<void>::type, fun1_type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<tpl2<void>::type, fun2_type>::value));
|
||||
|
2
test/function_ref.cpp
Executable file → Normal file
2
test/function_ref.cpp
Executable file → Normal file
@ -6,3 +6,5 @@
|
||||
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<void(&)()>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<int(&)(int, short)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<int(&)(...)>::value);
|
||||
BOOST_STATIC_ASSERT(boost::type_of::test<int(&)(int,...)>::value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user