Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.23 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function returning iterator in C  
  2. vector<string> types;
  3.  
  4. // some code here
  5.  
  6. Iterator Union::types()
  7. {
  8.     return types.iterator();
  9. }
  10.        
  11. std::vector<string>::iterator Union::types()
  12. {
  13.     return types.begin();
  14. }
  15.        
  16. std::pair<std::vector<std::string>::iterator,
  17.           std::vector<std::string>::iterator> Union::types()
  18. {
  19.     return std::make_pair(types.begin(), types.end());
  20. }
  21.  
  22. std::pair<std::vector<std::string>::iterator,
  23.           std::vector<std::string>::iterator> p =  Union::types();
  24.  
  25. for (; p.first != p.second; p.first++)
  26. {
  27. }
  28.        
  29. std::vector<string>::iterator Union::begin()
  30. {
  31.   return types.begin();
  32. }
  33.  
  34. std::vector<string>::iterator Union::end()
  35. {
  36.   return types.end();
  37. }
  38.        
  39. std::vector<string>::const_iterator Union::begin()const
  40. {
  41.   return types.begin();
  42. }
  43.  
  44. std::vector<string>::const_iterator Union::end()const
  45. {
  46.   return types.end();
  47. }
  48.        
  49. std::vector<string>::const_iterator Union::types_begin() const {
  50.   return types.begin();
  51. }
  52.  
  53. std::vector<string>::const_iterator Union::types_end() const {
  54.   return types.end();
  55. }
  56.        
  57. std::vector<std::string> types;
  58.  
  59. // some code here
  60.  
  61. std::vector<std::string>::iterator Union::returnTheBeginIterator()
  62. {
  63.     return types.begin();
  64. }
  65.        
  66. std::vector<std::string>::iterator Union::typesBegin()
  67. {
  68.     return types.begin();
  69. }
  70.  
  71. std::vector<std::string>::iterator Union::typesEnd()
  72. {
  73.     return types.end();
  74. }
  75.        
  76. // alias, because the full declaration is too long
  77. typedef std::vector<std::string> VecStr ;
  78.  
  79. void foo(Union & p_union)
  80. {
  81.    VecStr::iterator it = p_union.typesBegin() ;
  82.    VecStr::iterator itEnd = p_union.typesEnd() ;
  83.  
  84.    for(; it != itEnd; ++it)
  85.    {
  86.        // here, "*it" is the current string item
  87.        std::cout << "The current value is " << *it << ".n" ;
  88.    }
  89. }
  90.        
  91. void foo(std::vector<std::string> & p_types)
  92. {
  93.    for(std::string & item : p_types)
  94.    {
  95.        // here, "item " is the current string item
  96.        std::cout << "The current value is " << item  << ".n" ;
  97.    }
  98. }
  99.        
  100. std::vector<std::string> types
  101.  
  102. std::vector<std::string>::iterator Union::types(){
  103.     return types.begin();
  104. }
  105.        
  106. class Union
  107. {
  108. std::vector< std::string > types
  109. public:
  110. typedef std::vector< std::string >::iterator iterator;
  111. iterator begin() { return types.begin(); }
  112. iterator end() { return types.end(); }
  113.  
  114. };