From cbfd8f83de91cb0aa1a99cee4dfb7dcc511f8c21 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 17 May 2022 18:22:17 +0300 Subject: [PATCH] Add util::key_error for use in key-value containers in place of std::out_of_range --- libs/util/include/psemek/util/key_error.hpp | 29 +++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libs/util/include/psemek/util/key_error.hpp diff --git a/libs/util/include/psemek/util/key_error.hpp b/libs/util/include/psemek/util/key_error.hpp new file mode 100644 index 00000000..ee8dbd2d --- /dev/null +++ b/libs/util/include/psemek/util/key_error.hpp @@ -0,0 +1,29 @@ +#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_; + }; + +}