#pragma once #include #include //#include namespace fnd { template class List { public: // constructors List(); List(const List& other); // copy operator void operator=(const List& other); // equivalence operators bool operator==(const List& other) const; bool operator!=(const List& other) const; // back relative insertion void addElement(const T& element); // element access const T& operator[](size_t index) const; T& operator[](size_t index); const T& atBack() const; T& atBack(); // element num size_t size() const; // clear List void clear(); // element access by key template bool hasElement(const K& key) const; template const T& getElement(const K& key) const; template T& getElement(const K& key); private: std::vector m_Vec; }; template inline List::List() : m_Vec() { } template inline List::List(const List& other) : List() { *this = other; } template inline void List::operator=(const List& other) { m_Vec = other.m_Vec; } template inline bool List::operator==(const List& other) const { return m_Vec == other.m_Vec; } template inline bool List::operator!=(const List& other) const { return !(*this == other); } template inline void List::addElement(const T & element) { m_Vec.push_back(element); } template inline const T & List::operator[](size_t index) const { return m_Vec[index]; } template inline T & List::operator[](size_t index) { return m_Vec[index]; } template inline const T & List::atBack() const { return m_Vec.back(); } template inline T & List::atBack() { return m_Vec.back(); } template inline size_t List::size() const { return m_Vec.size(); } template inline void List::clear() { m_Vec.clear(); } template template inline bool List::hasElement(const K & key) const { for (size_t i = 0; i < m_Vec.size(); i++) { if (m_Vec[i] == key) { return true; } } return false; } template template inline const T & List::getElement(const K & key) const { for (size_t i = 0; i < m_Vec.size(); i++) { if (m_Vec[i] == key) { return m_Vec[i]; } } throw fnd::Exception("getElement(): element does not exist"); } template template inline T & List::getElement(const K & key) { for (size_t i = 0; i < m_Vec.size(); i++) { if (m_Vec[i] == key) { return m_Vec[i]; } } throw fnd::Exception("getElement(): element does not exist"); } }