diff --git a/src/Collections/List.hpp b/src/Collections/List.hpp index e6ea124..f913f88 100644 --- a/src/Collections/List.hpp +++ b/src/Collections/List.hpp @@ -9,6 +9,8 @@ namespace Arbutils::Collections { template class List { private: std::vector _vector; + using reference = typename std::vector::reference; + using const_reference = typename std::vector::const_reference; using iterator = typename std::vector::iterator; using const_iterator = typename std::vector::const_iterator; @@ -20,7 +22,7 @@ namespace Arbutils::Collections { inline void Clear() { _vector.clear(); } - inline ValueT& At(size_t index) { + inline reference At(size_t index) { #ifndef NO_ASSERT if (index >= _vector.size() || index < 0) { std::stringstream ss; @@ -31,7 +33,7 @@ namespace Arbutils::Collections { return _vector.at(index); } - inline const ValueT& At(size_t index) const { + inline const_reference At(size_t index) const { #ifndef NO_ASSERT if (index >= _vector.size() || index < 0) { std::stringstream ss; @@ -50,8 +52,8 @@ namespace Arbutils::Collections { inline void Insert(size_t index, ValueT value) { _vector.insert(index, value); } - inline ValueT& operator[](size_t index) { return At(index); } - inline const ValueT& operator[](size_t index) const { return At(index); } + inline reference operator[](size_t index) { return At(index); } + inline const_reference operator[](size_t index) const { return At(index); } inline size_t Count() const { return _vector.size(); } inline void Resize(size_t size) { _vector.resize(size); } diff --git a/tests/ListTests.cpp b/tests/ListTests.cpp index 7be267b..ab2ccb2 100644 --- a/tests/ListTests.cpp +++ b/tests/ListTests.cpp @@ -53,5 +53,13 @@ TEST_CASE("Create const List, iterate over values", "[Utilities]") { } } +TEST_CASE("Create list of bools, assign to it", "[Utilities]") { + auto ls = List({false, false, false}); + + ls[1] = true; + CHECK(ls[1]); +} + + #endif \ No newline at end of file