Commit 819d1ffb authored by Dominik Charousset's avatar Dominik Charousset Committed by Dominik Charousset

Respect CAF_NO_EXCEPTIONS in unordered flat map

parent 898b0be2
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <stdexcept> #include <stdexcept>
#include <functional> #include <functional>
#include "caf/config.hpp"
#include "caf/detail/comparable.hpp" #include "caf/detail/comparable.hpp"
namespace caf { namespace caf {
...@@ -223,16 +225,19 @@ public: ...@@ -223,16 +225,19 @@ public:
mapped_type& at(const K& key) { mapped_type& at(const K& key) {
auto i = find(key); auto i = find(key);
if (i == end()) if (i == end())
#ifdef CAF_NO_EXCEPTIONS
CAF_CRITICAL("caf::detail::unordered_flat_map::at out of range");
#else
throw std::out_of_range{"caf::detail::unordered_flat_map::at"}; throw std::out_of_range{"caf::detail::unordered_flat_map::at"};
#endif
return i->second; return i->second;
} }
template <class K> template <class K>
const mapped_type& at(const K& key) const { const mapped_type& at(const K& key) const {
auto i = find(key); /// We call the non-const version in order to avoid code duplication but
if (i == end()) /// restore the const-ness when returning from the function.
throw std::out_of_range{"caf::detail::unordered_flat_map::at"}; return const_cast<unordered_flat_map&>(*this).at(key);
return i->second;
} }
mapped_type& operator[](const key_type& key) { mapped_type& operator[](const key_type& key) {
...@@ -243,24 +248,23 @@ public: ...@@ -243,24 +248,23 @@ public:
} }
template <class K> template <class K>
iterator find(const K& x) { iterator find(const K& key) {
auto pred = [&](const value_type& y) { auto pred = [&](const value_type& y) {
return x == y.first; return key == y.first;
}; };
return std::find_if(xs_.begin(), xs_.end(), pred); return std::find_if(xs_.begin(), xs_.end(), pred);
} }
template <class K> template <class K>
const_iterator find(const K& x) const { const_iterator find(const K& key) const {
auto pred = [&](const value_type& y) { /// We call the non-const version in order to avoid code duplication but
return x == y.first; /// restore the const-ness when returning from the function.
}; return const_cast<unordered_flat_map&>(*this).find(key);
return std::find_if(xs_.begin(), xs_.end(), pred);
} }
template <class K> template <class K>
size_type count(const K& x) const { size_type count(const K& key) const {
return find(x) == end() ? 0 : 1; return find(key) == end() ? 0 : 1;
} }
private: private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment