diff --git a/source/mijin/types/script_value.hpp b/source/mijin/types/script_value.hpp index 869ca36..96933ee 100644 --- a/source/mijin/types/script_value.hpp +++ b/source/mijin/types/script_value.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -14,6 +15,16 @@ namespace mijin { +// +// public traits +// + +template +inline constexpr bool variant_contains_v = false; + +template +inline constexpr bool variant_contains_v> = mijin::is_any_type_v; + // // public types // @@ -26,12 +37,12 @@ template struct ArrayValue { std::vector values; +}; - bool operator==(const ArrayValue& other) const; - inline bool operator!=(const ArrayValue& other) const { - return !(*this == other); - } - std::partial_ordering operator<=>(const ArrayValue& other) const; +template +struct MapValue +{ + std::unordered_map values; }; struct UndefinedValue @@ -52,6 +63,7 @@ using script_value_base_t = std::variant< script_float_t, std::string, ArrayValue, + MapValue, TAdditional... >; @@ -62,8 +74,12 @@ public: using base_t = script_value_base_t; using concrete_t = TConcrete; using array_t = ArrayValue; + using map_t = MapValue; + + template + static constexpr bool can_hold_type_v = variant_contains_v, base_t> || std::is_arithmetic_v; private: - base_t base_; + base_t base_ = UndefinedValue(); public: ScriptValue() noexcept = default; ScriptValue(const ScriptValue&) noexcept = default; @@ -79,16 +95,7 @@ public: template auto visit(TFunction&& function) const { - using result_t = std::invoke_result_t; - - if constexpr (std::is_same_v) - { - std::visit(function, base_); - } - else - { - return std::visit(function, base_); - } + return std::visit(function, base_); } [[nodiscard]] @@ -203,7 +210,8 @@ public: { return *static_cast, TConcrete>*>(this); } - else if constexpr (is_any_type_v) + else if constexpr (std::is_same_v || std::is_same_v + || is_any_type_v) { if (std::holds_alternative(base_)) {