@@ -67,6 +67,32 @@ struct TraitSelector<std::tuple<TypesT...>>
67
67
using type = TupleTrait;
68
68
};
69
69
70
+ // Tuples are always copied because the memory layout in C++ and Julia is different, so references and pointers are not allowed
71
+ template <typename ... TypesT>
72
+ struct TraitSelector <std::tuple<TypesT...>&>
73
+ {
74
+ using type = TupleTrait;
75
+ static_assert (sizeof (std::tuple<TypesT...>) == 0 , " References to Julia tuples can't be used. Pass the tuple by value instead." );
76
+ };
77
+ template <typename ... TypesT>
78
+ struct TraitSelector <const std::tuple<TypesT...>&>
79
+ {
80
+ using type = TupleTrait;
81
+ static_assert (sizeof (std::tuple<TypesT...>) == 0 , " References to Julia tuples can't be used. Pass the tuple by value instead." );
82
+ };
83
+ template <typename ... TypesT>
84
+ struct TraitSelector <std::tuple<TypesT...>*>
85
+ {
86
+ using type = TupleTrait;
87
+ static_assert (sizeof (std::tuple<TypesT...>) == 0 , " Pointers to Julia tuples can't be used. Pass the tuple by value instead." );
88
+ };
89
+ template <typename ... TypesT>
90
+ struct TraitSelector <const std::tuple<TypesT...>*>
91
+ {
92
+ using type = TupleTrait;
93
+ static_assert (sizeof (std::tuple<TypesT...>) == 0 , " Pointers to Julia tuples can't be used. Pass the tuple by value instead." );
94
+ };
95
+
70
96
template <typename ... TypesT>
71
97
struct MappingTrait <std::tuple<TypesT...>, TupleTrait>
72
98
{
@@ -106,6 +132,21 @@ struct ConvertToJulia<std::tuple<TypesT...>, TupleTrait>
106
132
}
107
133
};
108
134
135
+ template <typename ... TypesT>
136
+ struct ConvertToCpp <std::tuple<TypesT...>, TupleTrait>
137
+ {
138
+ using cpp_t = std::tuple<TypesT...>;
139
+ inline cpp_t operator ()(jl_value_t * julia_val) const
140
+ {
141
+ constexpr std::size_t tup_sz = std::tuple_size<cpp_t >::value;
142
+ auto unpack_tuple = [&]<std::size_t ... Is>(std::index_sequence<Is...>)
143
+ {
144
+ return std::make_tuple ((unbox<std::tuple_element_t <Is, cpp_t >>(jl_get_nth_field_checked (julia_val, Is)))...);
145
+ };
146
+ return unpack_tuple (std::make_index_sequence<tup_sz>{});
147
+ }
148
+ };
149
+
109
150
// Wrap NTuple type
110
151
template <typename N, typename T>
111
152
struct NTuple
0 commit comments