Reputation: 661
I am now writing wrapper for some Windows library functions so I need extract their prototype and write a new wrapper with a modified prototype. For example: the function
int recv(SOCKET, char*, int, int)
will be wrapped by
recv_wrapper(SOCKET, char*, int, int, THREADID)
To avoid erroneousness, I write a wrapper template:
template <typename F> struct wrapper;
template <typename R, typename T1, typename T2, typename T3, typename T4>
struct wrapper<R(T1,T2,T3,T4)>
{
typedef R result_type;
typedef R (type)(T1,T2,T3,T4,THREADID);
};
and then the following wrapped type works:
typedef int recv_t(SOCKET,char*,int,int);
typedef wrapper<recv_t>::type recv_wrapper_t;
But I want to go a bit further using decltype to get the type of recv automatically:
typedef decltype(recv) recv_t;
typedef wrapper<recv_t>::type recv_wrapper_t;
But this does not work, I try several ways to modify that but I get always the error from VS2010 compiler:
error C2027: use of undefined type 'wrapper<F>'
with
[
F=int (SOCKET,char *,int,int)
]
and
error C2146: syntax error : missing ';' before identifier 'recv_wrapper_t'
I am quite frustrated with that because here F
is nothing but the recv_t
defined explicitly:
typedef int recv_t(SOCKET,char*,int,int);
but when get it automatically with decltype
, it does not work anymore.
Many thanks for any consideration.
N.B. I have fix a typo error following the suggestion of n.m.; but that still does not work.
Upvotes: 0
Views: 114
Reputation: 120079
template <typename F> wrapper;
is invalid. Did you mean template <typename F> struct wrapper;
? If you fix this, the obvious syntax works:
typedef wrapper<decltype(recv)>::type recv_wrapper_t;
Upvotes: 1