Add util::key_error for use in key-value containers in place of std::out_of_range

This commit is contained in:
Nikita Lisitsa 2022-05-17 18:22:17 +03:00
parent 14a2e00b39
commit cbfd8f83de

View file

@ -0,0 +1,29 @@
#pragma once
#include <psemek/util/to_string.hpp>
#include <psemek/util/type_name.hpp>
#include <stdexcept>
namespace psemek::util
{
template <typename Key>
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)
{}
Key const & key() const noexcept
{
return key_;
}
private:
Key key_;
};
}