Y
ybailly
Greetings all,
Here's a problem I have, here reduced to the minimum I could get.
Please consider the following complete program:
1 #include <iostream>
2
3 struct S
4 {
5 typedef void (*slot_t) ();
6 };
7
8 template<typename T>
9 struct ST
10 {
11 typedef T slot_t;
12 };
13
14 void m(S::slot_t f)
15 {
16 std::cout << "::m(S::slot_t)\n";
17 f();
18 }
19
20 template<typename T>
21 void m(typename ST<T>::slot_t f)
22 {
23 std::cout << "::m<T>(ST<T>::slot_t)\n";
24 f();
25 }
26
27 void ff()
28 {
29 std::cout << "::ff()\n";
30 }
31
32 int main(int /*argc*/, char* /*argv*/[])
33 {
34 auto ll = [](){ std::cout << "main()::<lambda>()\n"; };
35
36 m(ff);
37 m(ll);
38 m<decltype(ll)>(ll);
39
40 return 0;
41 }
Using GCC 4.6.3 and GCC 4.7.0, this program is compiled
using this command-line:
$ g++-4.7 -std=c++0x -Wall -Wextra -pedantic -o test.x test.cpp
Gives no error, no warning. When executed, I get:
$ ./text.x
::m(S::slot_t)
::ff()
::m(S::slot_t)
main()::<lambda>()
::m<T>(ST<T>::slot_t)
main()::<lambda>()
I assumed the call line 37 would be resolved in calling the template declared lines 20-25, but it just calls the global, non-template line 14. The call line 38 is the wanted behavior, though I would prefer to avoid giving the template parameter.
This makes me believe that the type of the lambda line 34 is the same as the type of the function ff() line 27 - or at least it can be converted to.
Is this correct?
How can I have the behavior like line 38, without giving explicitly the template parameter?
Thanks for any hint and have all a nice day
Here's a problem I have, here reduced to the minimum I could get.
Please consider the following complete program:
1 #include <iostream>
2
3 struct S
4 {
5 typedef void (*slot_t) ();
6 };
7
8 template<typename T>
9 struct ST
10 {
11 typedef T slot_t;
12 };
13
14 void m(S::slot_t f)
15 {
16 std::cout << "::m(S::slot_t)\n";
17 f();
18 }
19
20 template<typename T>
21 void m(typename ST<T>::slot_t f)
22 {
23 std::cout << "::m<T>(ST<T>::slot_t)\n";
24 f();
25 }
26
27 void ff()
28 {
29 std::cout << "::ff()\n";
30 }
31
32 int main(int /*argc*/, char* /*argv*/[])
33 {
34 auto ll = [](){ std::cout << "main()::<lambda>()\n"; };
35
36 m(ff);
37 m(ll);
38 m<decltype(ll)>(ll);
39
40 return 0;
41 }
Using GCC 4.6.3 and GCC 4.7.0, this program is compiled
using this command-line:
$ g++-4.7 -std=c++0x -Wall -Wextra -pedantic -o test.x test.cpp
Gives no error, no warning. When executed, I get:
$ ./text.x
::m(S::slot_t)
::ff()
::m(S::slot_t)
main()::<lambda>()
::m<T>(ST<T>::slot_t)
main()::<lambda>()
I assumed the call line 37 would be resolved in calling the template declared lines 20-25, but it just calls the global, non-template line 14. The call line 38 is the wanted behavior, though I would prefer to avoid giving the template parameter.
This makes me believe that the type of the lambda line 34 is the same as the type of the function ff() line 27 - or at least it can be converted to.
Is this correct?
How can I have the behavior like line 38, without giving explicitly the template parameter?
Thanks for any hint and have all a nice day