From 368d1edd71a74b2709ec877188644346fbc9b8ce Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 29 Jan 2024 17:43:52 +0300 Subject: [PATCH] Remove duplicate util::key_error exception, don't require the key to be convertible to string --- libs/util/include/psemek/util/at.hpp | 20 +++++++++++++- libs/util/include/psemek/util/key_error.hpp | 29 --------------------- libs/util/include/psemek/util/lru_cache.hpp | 2 +- 3 files changed, 20 insertions(+), 31 deletions(-) delete mode 100644 libs/util/include/psemek/util/key_error.hpp diff --git a/libs/util/include/psemek/util/at.hpp b/libs/util/include/psemek/util/at.hpp index fdf7dec5..fcfb4496 100644 --- a/libs/util/include/psemek/util/at.hpp +++ b/libs/util/include/psemek/util/at.hpp @@ -2,12 +2,30 @@ #include #include +#include #include namespace psemek::util { + namespace detail + { + + template + std::string key_error_to_string(Key const & key, decltype(util::to_string(key)) *) + { + return util::to_string("key ", key, " not found of type ", type_name()); + } + + template + std::string key_error_to_string(Key const &, ...) + { + return util::to_string("key not found of type ", type_name()); + } + + } + struct key_error_base : exception { @@ -19,7 +37,7 @@ namespace psemek::util : key_error_base { key_error(Key const & key, boost::stacktrace::stacktrace stacktrace = {}) - : key_error_base(util::to_string("no such key: ", key), std::move(stacktrace)) + : key_error_base(detail::key_error_to_string(key), std::move(stacktrace)) , key_(key) {} diff --git a/libs/util/include/psemek/util/key_error.hpp b/libs/util/include/psemek/util/key_error.hpp deleted file mode 100644 index ee8dbd2d..00000000 --- a/libs/util/include/psemek/util/key_error.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include -#include - -#include - -namespace psemek::util -{ - - template - struct key_error - : std::out_of_range - { - key_error(Key const & key) - : std::out_of_range(to_string("unknown key ", key, " of type ", type_name())) - , key_(key) - {} - - Key const & key() const noexcept - { - return key_; - } - - private: - Key key_; - }; - -} diff --git a/libs/util/include/psemek/util/lru_cache.hpp b/libs/util/include/psemek/util/lru_cache.hpp index a2dd2e70..01e9760b 100644 --- a/libs/util/include/psemek/util/lru_cache.hpp +++ b/libs/util/include/psemek/util/lru_cache.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include