Skip to content

Commit

Permalink
Fix compilation issue with std::tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
leemaguire committed Jul 12, 2024
1 parent 1bf2799 commit 6a5b3ed
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ NEXT-RELEASE Release notes (YYYY-MM-DD)

### Fixed
* Using the `==` operator in a type safe query for a nullable string property would return the incorrect result when algined storage was disabled.
* Fix compilation issue when building with Bionic due to use of std::tuple (since 2.1.0).

### Enhancements
* Add ability to use `managed<std::map<std::string, T>>` in type safe queries when comparing a value for a key. e.g.
Expand Down
10 changes: 10 additions & 0 deletions include/cpprealm/internal/bridge/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ namespace realm::internal {
static_assert(sizeof...(Ts) == sizeof...(Us), "Tuples must have the same size");
return zip_tuples_impl(tuple1, tuple2, std::index_sequence_for<Ts...>());
}

template <typename T, std::size_t N, std::size_t... Is>
auto constexpr array_to_tuple_impl(const std::array<T, N>& arr, std::index_sequence<Is...>) {
return std::make_tuple(arr[Is]...);
}

template <typename T, std::size_t N>
auto constexpr array_to_tuple(const std::array<T, N>& arr) {
return array_to_tuple_impl(arr, std::make_index_sequence<N>{});
}
}

#endif //CPPREALM_BRIDGE_UTILS_HPP
23 changes: 13 additions & 10 deletions include/cpprealm/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,21 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
static constexpr auto managed_pointers() { \
return std::tuple{FOR_EACH(DECLARE_MANAGED_PROPERTY, cls, __VA_ARGS__)}; \
} \
template <typename PtrType> static constexpr auto unmanaged_to_managed_pointer(PtrType ptr) { \
FOR_EACH(DECLARE_COND_UNMANAGED_TO_MANAGED, cls, __VA_ARGS__); \
} \
static constexpr auto managed_pointers_names_todo() { return std::tuple{FOR_EACH(DECLARE_MANAGED_PROPERTY_NAME, cls, __VA_ARGS__)}; } \
template <typename PtrType> static constexpr auto unmanaged_to_managed_pointer(PtrType ptr) { \
FOR_EACH(DECLARE_COND_UNMANAGED_TO_MANAGED, cls, __VA_ARGS__); \
} \
static constexpr auto managed_pointers_names() { \
constexpr auto managed_pointers_names = std::array<std::string_view, std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value>{FOR_EACH(DECLARE_MANAGED_PROPERTY_NAME, cls, __VA_ARGS__)}; \
return internal::array_to_tuple(managed_pointers_names); \
} \
\
static constexpr bool is_object = true; \
explicit managed(const internal::bridge::obj& obj, \
internal::bridge::realm realm) \
: m_obj(std::move(obj)) \
, m_realm(std::move(realm)) \
{ \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
std::apply([&](auto& ...pair) { \
((*this.*pair.first).assign(&m_obj, &m_realm, m_obj.get_table().get_column_key(pair.second)), ...); \
}, zipped); \
Expand All @@ -420,7 +423,7 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
m_obj = other.m_obj; \
m_realm = other.m_realm; \
m_rbool_query = other.m_rbool_query; \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
if (m_rbool_query) { \
auto schema = m_realm.schema().find(other.schema.name); \
auto group = m_realm.read_group(); \
Expand All @@ -438,7 +441,7 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
m_obj = other.m_obj; \
m_realm = other.m_realm; \
m_rbool_query = other.m_rbool_query; \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
if (m_rbool_query) { \
auto schema = m_realm.schema().find(other.schema.name); \
auto group = m_realm.read_group(); \
Expand All @@ -457,7 +460,7 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
m_obj = std::move(other.m_obj); \
m_realm = std::move(other.m_realm); \
m_rbool_query = std::move(other.m_rbool_query); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
if (m_rbool_query) { \
auto schema = m_realm.schema().find(other.schema.name); \
auto group = m_realm.read_group(); \
Expand All @@ -475,7 +478,7 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
m_obj = std::move(other.m_obj); \
m_realm = std::move(other.m_realm); \
m_rbool_query = std::move(other.m_rbool_query); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
if (m_rbool_query) { \
auto schema = m_realm.schema().find(other.schema.name); \
auto group = m_realm.read_group(); \
Expand All @@ -497,7 +500,7 @@ rbool managed<std::optional<type>>::operator op(const std::optional<type>& rhs)
auto schema = m.m_realm.schema().find(m.schema.name); \
auto group = m.m_realm.read_group(); \
auto table_ref = group.get_table(schema.table_key()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names_todo()); \
auto zipped = internal::zip_tuples(managed_pointers(), managed_pointers_names()); \
std::apply([&m, &table_ref](auto& ...pair) { \
((m.*pair.first).prepare_for_query(&m.m_realm, table_ref, pair.second, m.m_rbool_query), ...); \
}, zipped); \
Expand Down
2 changes: 1 addition & 1 deletion src/cpprealm/schedulers/default_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace realm::default_scheduler {
#elif defined(REALM_HAVE_UV) && REALM_HAVE_UV
return make_uv();
#else
return std::make_shared<realm_core_scheduler>(util::Scheduler::make_generic());
return std::make_shared<internal::realm_core_scheduler>(util::Scheduler::make_generic());
#endif
}

Expand Down

0 comments on commit 6a5b3ed

Please sign in to comment.