Created
September 27, 2015 17:43
-
-
Save krysseltillada/308b18356daeef7705d7 to your computer and use it in GitHub Desktop.
template Vector header and implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#ifndef TMPCONTAINER_HEADER | |
#define TMPCONTAINER_HEADER | |
#include <vector> | |
#include <memory> | |
template <typename type> | |
class Vector { | |
public: | |
typedef typename std::vector <type>::iterator Iter; | |
Vector () : | |
c_sp (std::make_shared <std::vector <type> > (0)) { } | |
Vector (std::initializer_list <type> iv) : | |
c_sp (std::make_shared <std::vector <type> > (iv.begin (), iv.end ())) { } | |
Vector (const Vector &c_obj) : | |
c_sp (std::make_shared <std::vector <type> > (c_obj.c_sp->begin(), c_obj.c_sp->end())) { } | |
Vector (Vector &&m_obj) : | |
c_sp (std::make_shared <std::vector <type> > (m_obj.c_sp->begin(), m_obj.c_sp->end())) { } | |
Vector &add (const type &t) { | |
c_sp->push_back (t); | |
return *this; | |
} | |
Iter Start () { | |
return c_sp->begin (); | |
} | |
Iter End () { | |
return c_sp->end (); | |
} | |
private: | |
std::shared_ptr <std::vector <type> > c_sp; | |
}; | |
#endif // TMPCONTAINER_HEADER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "TmpContainer.h" | |
int main () | |
{ | |
Vector <std::string> msg = {"mlg", "420", "weed", "crate", "snoopdog"}; | |
for (Vector <std::string>::Iter it = msg.Start(); | |
it != msg.End (); ++it) { | |
std::cout << *it << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment