Wie kann ich herausfinden ob mein pass_by_auto richtig funktioniert. In der Typ-ID ist nichts zu erkennen, weder mit g++ noch dmc.
1 | # include <iostream>
|
2 | # include <typeinfo>
|
3 | using std :: cout; |
4 | using std :: endl; |
5 | template <bool B, typename T, typename F> |
6 | struct when { |
7 | typedef T type; |
8 | };
|
9 | template <typename T, typename F> |
10 | struct when <false, T, F> { |
11 | typedef F type; |
12 | };
|
13 | template <typename T> |
14 | struct pass_by_auto { |
15 | typedef typename when < |
16 | sizeof (void*) <= sizeof (T) |
17 | , T |
18 | , T const& |
19 | > :: type type; |
20 | };
|
21 | template <typename T> |
22 | void f (typename pass_by_auto <T> :: type t) { |
23 | cout << sizeof (t) << " Byte long = " << typeid (t) . name () << endl; |
24 | }
|
25 | void g (int const& t) { |
26 | cout << sizeof (t) << " Byte long = " << typeid (t) . name () << endl; |
27 | }
|
28 | struct s { |
29 | long i; |
30 | double r; |
31 | };
|
32 | int main (int argc, char** argv) { |
33 | g (argc); |
34 | f <int> (argc); |
35 | f <char**> (argv); |
36 | f <s> (s ()); |
37 | s o; f <s> (o); |
38 | }
|
1 | % g++ -std=c++98 -pedantic -otest test.cpp |
2 | % ./test |
3 | 4 Byte long = i |
4 | 4 Byte long = i |
5 | 8 Byte long = PPc |
6 | 16 Byte long = 1s |
7 | 16 Byte long = 1s |
1 | >dmc test.cpp |
2 | >.\test.exe |
3 | 4 Byte long = int |
4 | 4 Byte long = int |
5 | 4 Byte long = char ** |
6 | 16 Byte long = s |
7 | 16 Byte long = s |