Function type to function call, how to?

Hi all, I was trying to come up with a useful example of LVALUE_TYPEOF, so I decided to implement the "trace" function from the motivation section of decltype/auto proposal. However I ran into unexpected problem: Given a function type F, and parameter type T, how to create an expression for typeof to use in the return type? I use VC71, and the only thing that seems to work (but with a warning) is: F()(T()) The warning is something about using a null pointer to call a function... *(F*)0 doesn't work, and something like make<F>() doesn't work either -- 'expression can't be evaluated to a function call with one parameter', or something like this. What would be the correct way of doing this, and is there one? Thanks in advance. Regards, Arkadiy

Arkadiy Vertleyb wrote:
I was trying to come up with a useful example of LVALUE_TYPEOF, so I decided to implement the "trace" function from the motivation section of decltype/auto proposal. However I ran into unexpected problem:
Given a function type F, and parameter type T, how to create an expression for typeof to use in the return type? I use VC71, and the only thing that seems to work (but with a warning) is:
F()(T())
I'm not sure if this if what you have in mind, but the following compiles without warning with VC7.1, como and GCC 3.4: struct F { template<typename T> int operator()(T t) { return 0; } }; int main() { (void) sizeof( (*(F*)0)( *(int*)0 ) ); } Jonathan

"Jonathan Turkanis" <technews@kangaroologic.com> wrote
Arkadiy Vertleyb wrote:
I was trying to come up with a useful example of LVALUE_TYPEOF, so I decided to implement the "trace" function from the motivation section of decltype/auto proposal. However I ran into unexpected problem:
Given a function type F, and parameter type T, how to create an expression for typeof to use in the return type? I use VC71, and the only thing that seems to work (but with a warning) is:
F()(T())
I'm not sure if this if what you have in mind, but the following compiles without warning with VC7.1, como and GCC 3.4:
struct F { template<typename T> int operator()(T t) { return 0; } };
int main() { (void) sizeof( (*(F*)0)( *(int*)0 ) ); }
Actually here is a minimal example of what I meant: template<int n> struct int_; template<class F> int_<sizeof( (*(F*)0)() )> foo(); // doesn't compile in VC71 template<class F> int_<sizeof( (F())() )> foo(); // compiles with a warning in VC71 int main() { }

Arkadiy Vertleyb wrote:
"Jonathan Turkanis" wrote
Arkadiy Vertleyb wrote:
Given a function type F, and parameter type T, how to create an expression for typeof to use in the return type? I use VC71, and the only thing that seems to work (but with a warning) is:
I'm not sure if this if what you have in mind, but the following compiles without warning with VC7.1, como and GCC 3.4:
Actually here is a minimal example of what I meant:
template<int n> struct int_;
template<class F> int_<sizeof( (*(F*)0)() )> foo(); // doesn't compile in VC71
It compiles with GCC 3.4.2, como 4.3.3 (strict) and CodeWarrior 9.4. Looks like ETI. BTW, you can avoid dereferencing a null pointer by using a helper struct with a static member. Jonathan
participants (3)
-
Arkadiy Vertleyb
-
Jonathan Turkanis
-
Pavel Chikulaev