fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <typeinfo>
  5.  
  6. template<template<typename, typename> class T, typename T_T, typename T_U>
  7. void func(T<T_T, T_U> t) {
  8. typename decltype(t)::iterator t_it;
  9. typename T<T_T, T_U>::iterator t_it2;
  10. std::cout << "* Passed as: "
  11. << typeid(T<T_T, T_U>).name() << '\n'
  12. << "** With element type: "
  13. << typeid(T_T).name() << '\n'
  14. << "** And allocator type: "
  15. << typeid(T_U).name() << '\n'
  16. << "** And iterator type: "
  17. << typeid(t_it).name() << '\n'
  18. << " (" << typeid(t_it2).name() << ")"
  19. << std::endl;
  20. }
  21.  
  22. template<typename T>
  23. void cnuf(T t) {
  24. std::cout << "* And as: "
  25. << typeid(T).name() << '\n'
  26. << "* With iterator type: "
  27. << typeid(typename T::iterator).name()
  28. << std::endl;
  29. }
  30.  
  31. int main() {
  32. std::vector<int> vIntA;
  33. std::vector<int, std::allocator<std::string>> vStrA;
  34.  
  35. decltype(vIntA)::iterator vII;
  36. decltype(vStrA)::iterator vSI;
  37.  
  38. std::cout << "First vector: \n"
  39. << "* " << typeid(decltype(vIntA)).name() << '\n'
  40. << "* Allocator: "
  41. << typeid(decltype(vIntA)::allocator_type).name() << '\n'
  42. << "* Iterator: "
  43. << typeid(vII).name() << std::endl;
  44. func(vIntA);
  45. cnuf(vIntA);
  46. std::cout << std::endl;
  47.  
  48.  
  49. std::cout << "Second vector: \n"
  50. << "* " << typeid(decltype(vStrA)).name() << '\n'
  51. << "* Allocator: "
  52. << typeid(decltype(vStrA)::allocator_type).name() << '\n'
  53. << "* Iterator: "
  54. << typeid(vSI).name() << std::endl;
  55. func(vStrA);
  56. cnuf(vStrA);
  57. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
First vector: 
* St6vectorIiSaIiEE
* Allocator: SaIiE
* Iterator: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE
* Passed as: St6vectorIiSaIiEE
** With element type: i
** And allocator type: SaIiE
** And iterator type: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE
                     (N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE)
* And as: St6vectorIiSaIiEE
* With iterator type: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaIiEEEE

Second vector: 
* St6vectorIiSaISsEE
* Allocator: SaISsE
* Iterator: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaISsEEEE
* Passed as: St6vectorIiSaISsEE
** With element type: i
** And allocator type: SaISsE
** And iterator type: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaISsEEEE
                     (N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaISsEEEE)
* And as: St6vectorIiSaISsEE
* With iterator type: N9__gnu_cxx17__normal_iteratorIPiSt6vectorIiSaISsEEEE