Follow code style with noexcept, add Const() function to BorrowedPtr to return a const pointer of itself.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-06-20 17:45:41 +02:00
parent 893aa969d5
commit f59ec6c957
8 changed files with 107 additions and 96 deletions

View File

@@ -17,7 +17,7 @@ namespace ArbUt {
explicit Dictionary(size_t capacity) : _map(capacity) {}
explicit Dictionary(const std::initializer_list<std::pair<const KeyT, ValueT>>& l) : _map(l) {}
inline void Clear() { _map.clear(); }
inline void Clear() noexcept { _map.clear(); }
inline void Insert(const KeyT& key, const ValueT& value) {
[[maybe_unused]] const auto& v = _map.insert({key, value});
@@ -39,7 +39,7 @@ namespace ArbUt {
[[nodiscard]] inline const ValueT& Get(const KeyT& key) const { return _map.at(key); }
inline bool TryGet(const KeyT& key, ValueT& out) const {
inline bool TryGet(const KeyT& key, ValueT& out) const noexcept {
const auto& find = _map.find(key);
if (find == _map.end()) {
return false;
@@ -50,21 +50,21 @@ namespace ArbUt {
inline void Remove(const KeyT& key) { _map.erase(key); }
[[nodiscard]] inline size_t Count() const { return _map.size(); }
[[nodiscard]] inline size_t Count() const noexcept { return _map.size(); }
inline bool Has(const KeyT& key) const noexcept { return _map.find(key) != _map.end(); }
inline ValueT& operator[](const KeyT& key) { return Get(key); }
inline const ValueT& operator[](const KeyT& key) const { return Get(key); }
iterator begin() { return _map.begin(); }
const_iterator begin() const { return _map.begin(); }
iterator begin() noexcept { return _map.begin(); }
const_iterator begin() const noexcept { return _map.begin(); }
iterator end() { return _map.end(); }
iterator end() noexcept { return _map.end(); }
const_iterator end() const { return _map.end(); }
const std::unordered_map<KeyT, ValueT>& GetStdMap() const { return _map; }
std::unordered_map<KeyT, ValueT>& GetStdMap() { return _map; }
const std::unordered_map<KeyT, ValueT>& GetStdMap() const noexcept { return _map; }
std::unordered_map<KeyT, ValueT>& GetStdMap() noexcept { return _map; }
};
}

View File

@@ -15,12 +15,12 @@ namespace ArbUt {
using const_iterator = typename std::vector<ValueT>::const_iterator;
public:
List() : _vector() {}
List() noexcept : _vector() {}
explicit List(size_t capacity) : _vector() { _vector.reserve(capacity); }
List(const std::initializer_list<ValueT>& l) : _vector(l) {}
List(const ValueT* begin, const ValueT* end) : _vector(begin, end) {}
List(const std::initializer_list<ValueT>& l) noexcept : _vector(l) {}
List(const ValueT* begin, const ValueT* end) noexcept : _vector(begin, end) {}
inline void Clear() { _vector.clear(); }
inline void Clear() noexcept { _vector.clear(); }
inline reference At(size_t index) {
#ifndef NO_ASSERT
@@ -64,7 +64,7 @@ namespace ArbUt {
/// Find the index of the first occurrence of a value in the list, return -1 if none is found.
/// \param value The value we want the index for.
/// \return The index of the first occurrence of the value in the list, or -1 if none is found.
inline size_t IndexOf(const ValueT& value) const {
inline size_t IndexOf(const ValueT& value) const noexcept {
const auto& it = std::find(_vector.begin(), _vector.end(), value);
if (it == _vector.end())
return -1;
@@ -78,23 +78,23 @@ namespace ArbUt {
inline reference operator[](size_t index) { return At(index); }
inline const const_reference& operator[](size_t index) const { return At(index); }
inline size_t Count() const { return _vector.size(); }
inline size_t Count() const noexcept { return _vector.size(); }
inline void Reserve(size_t size) { _vector.reserve(size); }
inline void Resize(size_t size) { _vector.resize(size); }
inline void Resize(size_t size, const ValueT& defaultValue) { _vector.resize(size, defaultValue); }
inline void Remove(size_t index) { _vector.erase(_vector.begin() + index); }
iterator begin() { return _vector.begin(); }
const_iterator begin() const { return _vector.begin(); }
iterator begin() noexcept { return _vector.begin(); }
const_iterator begin() const noexcept { return _vector.begin(); }
iterator end() { return _vector.end(); }
const_iterator end() const { return _vector.end(); }
iterator end() noexcept { return _vector.end(); }
const_iterator end() const noexcept { return _vector.end(); }
const ValueT* RawData() const { return _vector.data(); }
const ValueT* RawData() const noexcept { return _vector.data(); }
const std::vector<ValueT>& GetStdList() const { return _vector; }
std::vector<ValueT>& GetStdList() { return _vector; }
const std::vector<ValueT>& GetStdList() const noexcept { return _vector; }
std::vector<ValueT>& GetStdList() noexcept { return _vector; }
};
}