Fixed not being to iterate over const collections.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c1167e704a
commit
79ab962e2f
|
@ -9,6 +9,7 @@ namespace Arbutils::Collections {
|
||||||
std::unordered_map<KeyT, ValueT> _map;
|
std::unordered_map<KeyT, ValueT> _map;
|
||||||
|
|
||||||
using iterator = typename std::unordered_map<KeyT, ValueT>::iterator;
|
using iterator = typename std::unordered_map<KeyT, ValueT>::iterator;
|
||||||
|
using const_iterator = typename std::unordered_map<KeyT, ValueT>::const_iterator;
|
||||||
public:
|
public:
|
||||||
Dictionary() : _map() {}
|
Dictionary() : _map() {}
|
||||||
explicit Dictionary(size_t capacity) : _map(capacity) {}
|
explicit Dictionary(size_t capacity) : _map(capacity) {}
|
||||||
|
@ -73,10 +74,10 @@ namespace Arbutils::Collections {
|
||||||
inline const ValueT& operator[](KeyT key) const { return Get(key); }
|
inline const ValueT& operator[](KeyT key) const { return Get(key); }
|
||||||
|
|
||||||
iterator begin() { return _map.begin(); }
|
iterator begin() { return _map.begin(); }
|
||||||
iterator begin() const { return _map.begin(); }
|
const_iterator begin() const { return _map.begin(); }
|
||||||
|
|
||||||
iterator end() { return _map.end(); }
|
iterator end() { return _map.end(); }
|
||||||
iterator end() const { return _map.end(); }
|
const_iterator end() const { return _map.end(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace Arbutils::Collections {
|
||||||
private:
|
private:
|
||||||
std::vector<ValueT> _vector;
|
std::vector<ValueT> _vector;
|
||||||
using iterator = typename std::vector<ValueT>::iterator;
|
using iterator = typename std::vector<ValueT>::iterator;
|
||||||
|
using const_iterator = typename std::vector<ValueT>::const_iterator;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
List() : _vector() {}
|
List() : _vector() {}
|
||||||
|
@ -40,7 +41,9 @@ namespace Arbutils::Collections {
|
||||||
return _vector.at(index);
|
return _vector.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Contains(ValueT value) { return std::find(_vector.begin(), _vector.end(), value) != _vector.end(); }
|
inline bool Contains(ValueT value) const {
|
||||||
|
return std::find(_vector.begin(), _vector.end(), value) != _vector.end();
|
||||||
|
}
|
||||||
|
|
||||||
inline void Append(ValueT value) { _vector.push_back(value); }
|
inline void Append(ValueT value) { _vector.push_back(value); }
|
||||||
|
|
||||||
|
@ -54,10 +57,10 @@ namespace Arbutils::Collections {
|
||||||
inline void Resize(size_t size, ValueT defaultValue) { _vector.resize(size, defaultValue); }
|
inline void Resize(size_t size, ValueT defaultValue) { _vector.resize(size, defaultValue); }
|
||||||
|
|
||||||
iterator begin() { return _vector.begin(); }
|
iterator begin() { return _vector.begin(); }
|
||||||
iterator begin() const { return _vector.begin(); }
|
const_iterator begin() const { return _vector.begin(); }
|
||||||
|
|
||||||
iterator end() { return _vector.end(); }
|
iterator end() { return _vector.end(); }
|
||||||
iterator end() const { return _vector.end(); }
|
const_iterator end() const { return _vector.end(); }
|
||||||
|
|
||||||
const ValueT* RawData() const { return _vector.data(); }
|
const ValueT* RawData() const { return _vector.data(); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -45,5 +45,13 @@ TEST_CASE("Create List, insert values, iterate over values", "[Utilities]") {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Create const List, iterate over values", "[Utilities]") {
|
||||||
|
const auto& ls = List<int>({10, 100, 50});
|
||||||
|
|
||||||
|
for (auto v: ls){
|
||||||
|
CHECK(ls.Contains(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue