fork(1) download
  1. #include <iostream>
  2. #include <typeinfo>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6.  
  7. template <class T>
  8. void doLoop(T from,T to)
  9. {
  10. for (T theVar = from; theVar<to; theVar++) cout << theVar << "\n";
  11. }
  12.  
  13. template <class T>
  14. struct BestParameterPassingType
  15. {
  16. typedef T Type;
  17. };
  18.  
  19. // int взят для наглядности
  20. template <>
  21. struct BestParameterPassingType<int>
  22. {
  23. typedef int &Type;
  24. };
  25.  
  26. int main ()
  27. {
  28. int j = 0, k = 10;
  29. doLoop<BestParameterPassingType<int>::Type> (j,k);
  30. cout << "j = " << j << "\n";
  31. }
  32.  
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0
1
2
3
4
5
6
7
8
9
j = 10