Skip to content

Commit

Permalink
change parsing order of long and int, also allows them to be intercha…
Browse files Browse the repository at this point in the history
…ngeable
  • Loading branch information
bjia56 committed Jan 13, 2025
1 parent 77152a6 commit 9869176
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/rfl/Generic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class Generic {

using Array = std::vector<Generic>;
using Object = rfl::Object<Generic>;
using VariantType = std::variant<bool, int, long, double, std::string, Object,
using VariantType = std::variant<bool, long, int, double, std::string, Object,
Array, std::nullopt_t>;
using ReflectionType = std::optional<
std::variant<bool, int, long, double, std::string, Object, Array>>;
std::variant<bool, long, int, double, std::string, Object, Array>>;

Generic();

Expand Down
4 changes: 4 additions & 0 deletions src/rfl/Generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Result<double> Generic::to_double() const noexcept {
Result<int> Generic::to_int() const noexcept {
if (const int* ptr = std::get_if<int>(&value_)) {
return *ptr;
} else if (const long* ptr = std::get_if<long>(&value_)) {
return static_cast<int>(*ptr);
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to an integer.");
Expand All @@ -114,6 +116,8 @@ Result<int> Generic::to_int() const noexcept {
Result<long> Generic::to_long() const noexcept {
if (const long* ptr = std::get_if<long>(&value_)) {
return *ptr;
} else if (const int* ptr = std::get_if<int>(&value_)) {
return static_cast<long>(*ptr);
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to a long.");
Expand Down

0 comments on commit 9869176

Please sign in to comment.