Advertisement
weeez

string_implemented_with

Feb 7th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #ifndef HEADER_INCLUDED
  2. #define HEADER_INCLUDED
  3.  
  4. /* Feladat: Egy olyan string_implemented_with<...> létrehozása, mely biztosítja a template-ben kapott típusnak a String műveleteit:
  5.  
  6.         - létrehozás: pl.:
  7.                                                 char v[]="kukumuku"; // de ez lehet más típus is
  8.                                                 string_implement_with<...> (v); -> ezután a char v[]-nek 0-nak kell lennie ( \0-t az elejére kell hozni -> "kukumuku\0")
  9.                                                
  10.         - at(int, ind)
  11.         - erease(pos, int) -> adott pozíciótól hány elemet töröljön (a típusnak megfelelően)
  12. */
  13.  
  14. #include <string>
  15.  
  16. template <class T, class S>
  17. class string_implemented_with{
  18.     private:
  19.         T lista;
  20.     public:
  21.         string_implemented_with(S* s){
  22.             for(int i =0; i < sizeof(*s); ++i){
  23.                 lista.push_back(s[i]);
  24.             }
  25.         }
  26.         string_implemented_with &erase(int x, int y){
  27.             typename T::iterator it = lista.begin();
  28.             int i = 0;
  29.             while(i != x){
  30.                 ++it;
  31.                 ++i;
  32.             }
  33.             while(i != y){
  34.                 std::cout<<"szia\n";
  35.                 lista.erase(it);
  36.                 ++it;
  37.                 ++i;
  38.             }
  39.             return *this;
  40.         }
  41.         S at(int x) const{
  42.             typename T::const_iterator it = lista.begin();
  43.             for(int i = 0; i < x; ++i){
  44.                 ++it;
  45.             }
  46.             return *it;
  47.         }
  48.         const int length() const{
  49.             return lista.size();
  50.         }
  51. };
  52.  
  53. #endif // HEADER_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement