Realm C++ SDK Version v2.2.0

utils.hpp

1
2//
3// Copyright 2024 Realm Inc.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
18
19#ifndef CPPREALM_BRIDGE_UTILS_HPP
20#define CPPREALM_BRIDGE_UTILS_HPP
21
22#include <functional>
23#include <memory>
24#include <string_view>
25#include <string>
26#include <type_traits>
27
28#ifdef _WIN32
29
30#include <WinSock2.h>
31#include <intrin.h>
32#include <BaseTsd.h>
33
34#undef max // collides with numeric_limits::max called later in this header file
35#undef min // collides with numeric_limits::min called later in this header file
36#include <safeint.h>
37
38#endif // _WIN32
39
40#if __has_include(<cpprealm/internal/bridge/bridge_types.hpp>)
41#include <cpprealm/internal/bridge/bridge_types.hpp>
42#endif
43
44namespace realm::internal::bridge {
45 template <typename Left, typename Right, typename = void>
47 template <typename Left, typename Right>
48 struct LayoutCheck<Left, Right, std::enable_if_t<(sizeof(Left) == sizeof(Right) && alignof(Left) == alignof(Right))>> : std::true_type {
49 };
50}
51
52namespace realm::internal {
53 template <typename... Ts, typename... Us, size_t... Is>
54 auto constexpr zip_tuples_impl(const std::tuple<Ts...>& tuple1, const std::tuple<Us...>& tuple2, std::index_sequence<Is...>) {
55 return std::make_tuple(std::make_pair(std::get<Is>(tuple1), std::get<Is>(tuple2))...);
56 }
57
58 template <typename... Ts, typename... Us>
59 auto constexpr zip_tuples(const std::tuple<Ts...>& tuple1, const std::tuple<Us...>& tuple2) {
60 static_assert(sizeof...(Ts) == sizeof...(Us), "Tuples must have the same size");
61 return zip_tuples_impl(tuple1, tuple2, std::index_sequence_for<Ts...>());
62 }
63
64 template <typename T, std::size_t N, std::size_t... Is>
65 auto constexpr array_to_tuple_impl(const std::array<T, N>& arr, std::index_sequence<Is...>) {
66 return std::make_tuple(arr[Is]...);
67 }
68
69 template <typename T, std::size_t N>
70 auto constexpr array_to_tuple(const std::array<T, N>& arr) {
71 return array_to_tuple_impl(arr, std::make_index_sequence<N>{});
72 }
73}
74
75#endif //CPPREALM_BRIDGE_UTILS_HPP
Definition: utils.hpp:46