fork download
  1. #include <vector>
  2. #include <utility>
  3. #include <algorithm>
  4. #include <iterator>
  5.  
  6. template<class container>
  7. struct iterator_type {
  8. typedef typename container::iterator iterator;
  9. typedef typename container::const_iterator const_iterator;
  10. };
  11. template<class element, int size>
  12. struct iterator_type<element[size]> {
  13. typedef element* iterator;
  14. typedef const element* const_iterator;
  15. };
  16. template<class element, int size>
  17. struct iterator_type<const element[size]> {
  18. typedef const element* iterator;
  19. typedef const element* const_iterator;
  20. };
  21.  
  22. template<class container>
  23. typename container::iterator begin(container& rhs){return rhs.begin();}
  24. template<class container>
  25. typename container::iterator begin(const container& rhs) {return rhs.begin();}
  26. template<class element, int size>
  27. element* begin(element(&rhs)[size]) {return rhs;}
  28. template<class container>
  29. typename container::iterator end(container& rhs) {return rhs.end();}
  30. template<class container>
  31. typename container::iterator end(const container& rhs) {return rhs.end();}
  32. template<class element, int size>
  33. element* end(element(&rhs)[size]) {return rhs+size;}
  34.  
  35. template<class iter1, class iter2>
  36. iter1 search(iter1 stackbegin, iter1 stackend, iter2 needlebegin, iter2 needleend)
  37. {return std::search(stackbegin, stackend, needlebegin, needleend);}
  38.  
  39. template<class iter1, class needlecontainer>
  40. iter1 search(iter1 stackbegin, iter1 stackend, const needlecontainer& needle)
  41. {return std::search(stackbegin, stackend, begin(needle), end(needle));}
  42.  
  43. template<class stackcontainer, class needlecontainer>
  44. typename stackcontainer::iterator
  45. search(const stackcontainer& stack, const needlecontainer& needle)
  46. {return std::search(begin(stack), end(stack), begin(needle), end(needle));}
  47.  
  48. template<class stackcontainer, class needlecontainer>
  49. typename iterator_type<stackcontainer>::iterator
  50. search(stackcontainer& stack, const needlecontainer& needle)
  51. {return std::search(begin(stack), end(stack), begin(needle), end(needle));}
  52.  
  53. template<class stackcontainer, class needlecontainer>
  54. typename iterator_type<stackcontainer>::const_iterator
  55. search(const stackcontainer& stack, const needlecontainer& needle)
  56. {return std::search(begin(stack), end(stack), begin(needle), end(needle));}
  57.  
  58. int main() {
  59. std::vector<char> str1;
  60. std::vector<char>::iterator it;
  61. it = search(str1, "Look for this");
  62. const char* it2 = search("ABCDEFGHI", "DEF");
  63. }
Success #stdin #stdout 0s 2924KB
stdin
Standard input is empty
stdout

Standard output is empty