Add util::key_error for use in key-value containers in place of std::out_of_range
This commit is contained in:
parent
14a2e00b39
commit
cbfd8f83de
1 changed files with 29 additions and 0 deletions
29
libs/util/include/psemek/util/key_error.hpp
Normal file
29
libs/util/include/psemek/util/key_error.hpp
Normal 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_;
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue