6#include <unordered_map>
17 using iterator = std::unordered_map<std::string, std::any>::iterator;
18 using const_iterator = std::unordered_map<std::string, std::any>::const_iterator;
21 return config_.begin();
27 return config_.begin();
33 return config_.cbegin();
36 return config_.cend();
40 [[nodiscard]] std::optional<T>
Try(
const std::string &key)
const {
45 return std::optional{std::any_cast<T>(config_.at(key))};
46 }
catch (
const std::bad_any_cast &) {
52 [[nodiscard]] std::optional<T>
Get(
const std::string &key)
const {
54 Panic(
"Key not found: " + key);
57 return std::optional{std::any_cast<T>(config_.at(key))};
58 }
catch (
const std::bad_any_cast &) {
59 Panic(
"Invalid type requested for key: " + key);
63 [[nodiscard]] std::optional<std::any>
TryAny(
const std::string &key)
const {
67 return std::optional{config_.at(key)};
70 [[nodiscard]] std::any
GetAny(
const std::string &key)
const {
72 Panic(
"Key not found: " + key);
74 return config_.at(key);
77 void Put(
const std::string &key,
const std::any &value) {
78 config_.insert_or_assign(key, value);
81 [[nodiscard]]
bool Contains(
const std::string &key)
const {
82 return config_.contains(key);
85 [[nodiscard]] std::optional<std::type_index>
GetType(
const std::string &key)
const {
89 return config_.at(key).type();
93 std::unordered_map<std::string, std::any> config_;
std::optional< T > Get(const std::string &key) const
std::optional< std::type_index > GetType(const std::string &key) const
const_iterator end() const noexcept
std::unordered_map< std::string, std::any >::const_iterator const_iterator
const_iterator begin() const noexcept
std::unordered_map< std::string, std::any >::iterator iterator
void Put(const std::string &key, const std::any &value)
bool Contains(const std::string &key) const
iterator begin() noexcept
std::optional< std::any > TryAny(const std::string &key) const
std::optional< T > Try(const std::string &key) const
std::any GetAny(const std::string &key) const
const_iterator cbegin() const noexcept
const_iterator cend() const noexcept
void Panic(const StringViewSourceLoc &s) noexcept