Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation issue with std::tuple #227

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading