Skip to content

Commit

Permalink
feat: operator tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Dec 12, 2024
1 parent 66e09f5 commit 0c08169
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/common/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ class basic_array
return as_fixed_array<value_t, Size, fixed_array_t>();
}

template <typename... elem_ts>
explicit operator std::tuple<elem_ts...>() const
{
return as_tuple<elem_ts...>();
}

template <typename elem1_t, typename elem2_t>
explicit operator std::pair<elem1_t, elem2_t>() const
{
return as_pair<elem1_t, elem2_t>();
}

template <
typename jsonization_t,
std::enable_if_t<_utils::has_from_json_in_member<jsonization_t, string_t>::value, bool> =
Expand Down
2 changes: 2 additions & 0 deletions test/serializing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ bool jsonizing()
tuple_arr.emplace_back("aaabbbccc");
auto t = tuple_arr.as_tuple<int, std::string>();
auto p = tuple_arr.as_pair<int, std::string>();
auto t2 = std::tuple<int, std::string>(tuple_arr);
auto p2 = std::pair<int, std::string>(tuple_arr);

return true;
}
Expand Down

0 comments on commit 0c08169

Please sign in to comment.