>>108721993
doing mixins for an stl type seems a bit overkill, when i can just make my own hyper specialized class in a few lines of code. hell the basic implementation is just
struct Value
{
using Object = string_map<std::string, Value>;
std::variant<std::string, Object> data;
struct Optional
{
Optional(Value *v = nullptr) : ptr(v) {}
template<class K>
auto operator [] (const K &key) -> Optional
{
if(ptr && std::holds_alternative<Object>(ptr->data))
{
auto &obj = std::get<Object>(ptr->data);
if(auto it = obj.find(key); it != obj.end())
return &it->second;
}
return nullptr;
}
template<class T, class... Args>
auto As(Args &&...args) -> std::optional<T>
{
if(ptr && std::holds_alternative<std::string>(ptr->data))
{
auto &str = std::get<std::string>(ptr->data);
if constexpr(std::same_as<T, std::string>)
return str;
// else if other types of T
}
return std::nullopt;
}
template<>
auto As<Object>() -> std::optional<Object> = delete;
private:
Value *ptr;
};
template<class K>
auto operator [] (const K &key) -> Optional
{
return Optional(this)[key];
}
};