rice 4.7.1 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -1
  3. data/CMakeLists.txt +14 -22
  4. data/CMakePresets.json +203 -75
  5. data/FindRuby.cmake +358 -123
  6. data/bin/rice-doc.rb +58 -141
  7. data/include/rice/api.hpp +261 -0
  8. data/include/rice/rice.hpp +2459 -1693
  9. data/include/rice/stl.hpp +450 -546
  10. data/lib/rice/doc/config.rb +70 -0
  11. data/lib/rice/doc/cpp_reference.rb +1 -4
  12. data/lib/rice/doc/mkdocs.rb +58 -20
  13. data/lib/rice/doc/rice.rb +21 -0
  14. data/lib/rice/doc.rb +1 -0
  15. data/lib/rice/make_rice_headers.rb +7 -0
  16. data/lib/rice/native_registry.rb +5 -10
  17. data/lib/rice/rbs.rb +6 -6
  18. data/lib/rice/version.rb +1 -1
  19. data/lib/rubygems_plugin.rb +12 -9
  20. data/rice/Arg.hpp +12 -6
  21. data/rice/Arg.ipp +14 -7
  22. data/rice/Buffer.ipp +44 -40
  23. data/rice/Callback.hpp +1 -1
  24. data/rice/Callback.ipp +2 -7
  25. data/rice/Constructor.hpp +1 -1
  26. data/rice/Constructor.ipp +11 -11
  27. data/rice/Data_Object.ipp +15 -15
  28. data/rice/Data_Type.hpp +9 -10
  29. data/rice/Data_Type.ipp +33 -31
  30. data/rice/Director.hpp +1 -0
  31. data/rice/Enum.ipp +58 -39
  32. data/rice/Exception.hpp +4 -4
  33. data/rice/Exception.ipp +7 -7
  34. data/rice/NoGVL.hpp +13 -0
  35. data/rice/Reference.hpp +56 -0
  36. data/rice/Reference.ipp +96 -0
  37. data/rice/Return.hpp +4 -1
  38. data/rice/Return.ipp +0 -6
  39. data/rice/cpp_api/Array.hpp +41 -4
  40. data/rice/cpp_api/Array.ipp +105 -9
  41. data/rice/cpp_api/Class.hpp +7 -2
  42. data/rice/cpp_api/Class.ipp +9 -4
  43. data/rice/cpp_api/Hash.ipp +7 -4
  44. data/rice/cpp_api/Module.hpp +4 -4
  45. data/rice/cpp_api/Module.ipp +12 -10
  46. data/rice/cpp_api/Object.hpp +10 -4
  47. data/rice/cpp_api/Object.ipp +20 -12
  48. data/rice/cpp_api/String.hpp +2 -2
  49. data/rice/cpp_api/String.ipp +11 -8
  50. data/rice/cpp_api/Symbol.ipp +7 -7
  51. data/rice/cpp_api/shared_methods.hpp +5 -9
  52. data/rice/detail/Forwards.hpp +18 -0
  53. data/rice/detail/Forwards.ipp +60 -0
  54. data/rice/detail/InstanceRegistry.hpp +0 -2
  55. data/rice/detail/Native.hpp +31 -21
  56. data/rice/detail/Native.ipp +282 -130
  57. data/rice/detail/NativeAttributeGet.hpp +5 -7
  58. data/rice/detail/NativeAttributeGet.ipp +26 -26
  59. data/rice/detail/NativeAttributeSet.hpp +2 -4
  60. data/rice/detail/NativeAttributeSet.ipp +20 -16
  61. data/rice/detail/NativeCallback.hpp +77 -0
  62. data/rice/detail/NativeCallback.ipp +280 -0
  63. data/rice/detail/NativeFunction.hpp +11 -21
  64. data/rice/detail/NativeFunction.ipp +58 -119
  65. data/rice/detail/NativeInvoker.hpp +4 -4
  66. data/rice/detail/NativeInvoker.ipp +7 -7
  67. data/rice/detail/NativeIterator.hpp +2 -4
  68. data/rice/detail/NativeIterator.ipp +18 -14
  69. data/rice/detail/NativeMethod.hpp +10 -20
  70. data/rice/detail/NativeMethod.ipp +54 -114
  71. data/rice/detail/NativeProc.hpp +5 -7
  72. data/rice/detail/NativeProc.ipp +39 -28
  73. data/rice/detail/NativeRegistry.hpp +1 -1
  74. data/rice/detail/NativeRegistry.ipp +29 -0
  75. data/rice/detail/Parameter.hpp +15 -8
  76. data/rice/detail/Parameter.ipp +102 -43
  77. data/rice/detail/Proc.ipp +14 -28
  78. data/rice/detail/RubyType.ipp +2 -53
  79. data/rice/detail/Type.hpp +23 -7
  80. data/rice/detail/Type.ipp +77 -93
  81. data/rice/detail/TypeRegistry.ipp +5 -4
  82. data/rice/detail/Wrapper.hpp +13 -12
  83. data/rice/detail/Wrapper.ipp +97 -44
  84. data/rice/detail/from_ruby.hpp +8 -6
  85. data/rice/detail/from_ruby.ipp +306 -173
  86. data/rice/detail/ruby.hpp +23 -0
  87. data/rice/libc/file.hpp +4 -4
  88. data/rice/rice.hpp +9 -8
  89. data/rice/rice_api/Native.ipp +5 -1
  90. data/rice/rice_api/NativeRegistry.ipp +14 -1
  91. data/rice/rice_api/Parameter.ipp +1 -1
  92. data/rice/ruby_mark.hpp +2 -1
  93. data/rice/stl/complex.ipp +12 -8
  94. data/rice/stl/map.ipp +27 -22
  95. data/rice/stl/monostate.ipp +16 -12
  96. data/rice/stl/multimap.hpp +0 -2
  97. data/rice/stl/multimap.ipp +27 -22
  98. data/rice/stl/optional.ipp +27 -11
  99. data/rice/stl/pair.ipp +5 -5
  100. data/rice/stl/reference_wrapper.ipp +5 -4
  101. data/rice/stl/set.ipp +16 -16
  102. data/rice/stl/shared_ptr.hpp +9 -9
  103. data/rice/stl/shared_ptr.ipp +52 -185
  104. data/rice/stl/string.ipp +18 -18
  105. data/rice/stl/string_view.ipp +1 -1
  106. data/rice/stl/tuple.ipp +15 -36
  107. data/rice/stl/unique_ptr.hpp +9 -3
  108. data/rice/stl/unique_ptr.ipp +86 -120
  109. data/rice/stl/unordered_map.ipp +20 -15
  110. data/rice/stl/variant.ipp +37 -21
  111. data/rice/stl/vector.ipp +41 -36
  112. data/rice/traits/function_traits.hpp +19 -19
  113. data/rice/traits/method_traits.hpp +4 -4
  114. data/rice/traits/rice_traits.hpp +162 -39
  115. data/rice.gemspec +1 -3
  116. data/test/test_Array.cpp +261 -3
  117. data/test/test_Attribute.cpp +6 -3
  118. data/test/test_Buffer.cpp +6 -42
  119. data/test/test_Callback.cpp +77 -23
  120. data/test/test_Data_Object.cpp +1 -1
  121. data/test/test_Data_Type.cpp +21 -22
  122. data/test/test_Director.cpp +2 -4
  123. data/test/test_Enum.cpp +34 -5
  124. data/test/test_File.cpp +9 -5
  125. data/test/test_From_Ruby.cpp +4 -3
  126. data/test/test_GVL.cpp +3 -3
  127. data/test/test_Hash.cpp +1 -1
  128. data/test/test_Inheritance.cpp +14 -14
  129. data/test/test_Iterator.cpp +54 -22
  130. data/test/test_Keep_Alive.cpp +1 -1
  131. data/test/test_Keep_Alive_No_Wrapper.cpp +7 -3
  132. data/test/test_Module.cpp +5 -5
  133. data/test/test_Overloads.cpp +345 -48
  134. data/test/test_Proc.cpp +54 -0
  135. data/test/test_Reference.cpp +181 -0
  136. data/test/test_Self.cpp +2 -2
  137. data/test/test_Stl_Set.cpp +6 -6
  138. data/test/test_Stl_SharedPtr.cpp +172 -33
  139. data/test/test_Stl_String_View.cpp +4 -2
  140. data/test/test_Stl_Tuple.cpp +1 -1
  141. data/test/test_Stl_UniquePtr.cpp +48 -3
  142. data/test/test_Stl_Variant.cpp +6 -14
  143. data/test/test_Stl_Vector.cpp +61 -30
  144. data/test/test_String.cpp +4 -2
  145. data/test/test_Struct.cpp +1 -1
  146. data/test/test_Symbol.cpp +1 -1
  147. data/test/test_To_Ruby.cpp +1 -0
  148. data/test/test_Type.cpp +36 -35
  149. data/test/test_global_functions.cpp +1 -1
  150. data/test/unittest.cpp +1 -1
  151. data/test/unittest.hpp +5 -5
  152. metadata +12 -10
  153. data/rice/Function.hpp +0 -17
  154. data/rice/Function.ipp +0 -13
  155. data/rice/detail/MethodInfo.hpp +0 -48
  156. data/rice/detail/MethodInfo.ipp +0 -99
  157. data/rice/detail/NativeCallbackFFI.hpp +0 -55
  158. data/rice/detail/NativeCallbackFFI.ipp +0 -152
  159. data/rice/detail/NativeCallbackSimple.hpp +0 -30
  160. data/rice/detail/NativeCallbackSimple.ipp +0 -29
@@ -107,7 +107,11 @@ namespace Rice
107
107
  {
108
108
  if constexpr (detail::is_comparable_v<Mapped_T>)
109
109
  {
110
- klass_.define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
110
+ klass_.define_method("==", [](T& unordered_map, T& other)->bool
111
+ {
112
+ return unordered_map == other;
113
+ })
114
+ .define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
111
115
  {
112
116
  auto it = std::find_if(unordered_map.begin(), unordered_map.end(),
113
117
  [&value](auto& pair)
@@ -117,10 +121,11 @@ namespace Rice
117
121
 
118
122
  return it != unordered_map.end();
119
123
  });
124
+ rb_define_alias(klass_, "eql?", "==");
120
125
  }
121
126
  else
122
127
  {
123
- klass_.define_method("value?", [](T& unordered_map, Mapped_T& value) -> bool
128
+ klass_.define_method("value?", [](T&, Mapped_T&) -> bool
124
129
  {
125
130
  return false;
126
131
  });
@@ -205,10 +210,10 @@ namespace Rice
205
210
  }
206
211
  else
207
212
  {
208
- klass_.define_method("to_s", [](const T& unordered_map)
209
- {
210
- return "[Not printable]";
211
- });
213
+ klass_.define_method("to_s", [](const T&)
214
+ {
215
+ return "[Not printable]";
216
+ });
212
217
  }
213
218
  }
214
219
 
@@ -299,7 +304,7 @@ namespace Rice
299
304
  {
300
305
  }
301
306
 
302
- Convertible is_convertible(VALUE value)
307
+ double is_convertible(VALUE value)
303
308
  {
304
309
  switch (rb_type(value))
305
310
  {
@@ -307,7 +312,7 @@ namespace Rice
307
312
  return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
308
313
  break;
309
314
  case RUBY_T_HASH:
310
- return Convertible::Cast;
315
+ return Convertible::Exact;
311
316
  break;
312
317
  default:
313
318
  return Convertible::None;
@@ -333,7 +338,7 @@ namespace Rice
333
338
  }
334
339
  default:
335
340
  {
336
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
341
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
337
342
  detail::protect(rb_obj_classname, value), "std::unordered_map");
338
343
  }
339
344
  }
@@ -353,7 +358,7 @@ namespace Rice
353
358
  {
354
359
  }
355
360
 
356
- Convertible is_convertible(VALUE value)
361
+ double is_convertible(VALUE value)
357
362
  {
358
363
  switch (rb_type(value))
359
364
  {
@@ -361,7 +366,7 @@ namespace Rice
361
366
  return Data_Type<std::unordered_map<T, U>>::is_descendant(value) ? Convertible::Exact : Convertible::None;
362
367
  break;
363
368
  case RUBY_T_HASH:
364
- return Convertible::Cast;
369
+ return Convertible::Exact;
365
370
  break;
366
371
  default:
367
372
  return Convertible::None;
@@ -388,7 +393,7 @@ namespace Rice
388
393
  }
389
394
  default:
390
395
  {
391
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
396
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
392
397
  detail::protect(rb_obj_classname, value), "std::unordered_map");
393
398
  }
394
399
  }
@@ -409,7 +414,7 @@ namespace Rice
409
414
  {
410
415
  }
411
416
 
412
- Convertible is_convertible(VALUE value)
417
+ double is_convertible(VALUE value)
413
418
  {
414
419
  switch (rb_type(value))
415
420
  {
@@ -420,7 +425,7 @@ namespace Rice
420
425
  return Convertible::Exact;
421
426
  break;
422
427
  case RUBY_T_HASH:
423
- return Convertible::Cast;
428
+ return Convertible::Exact;
424
429
  break;
425
430
  default:
426
431
  return Convertible::None;
@@ -447,7 +452,7 @@ namespace Rice
447
452
  }
448
453
  default:
449
454
  {
450
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
455
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
451
456
  detail::protect(rb_obj_classname, value), "std::unordered_map");
452
457
  }
453
458
  }
data/rice/stl/variant.ipp CHANGED
@@ -8,7 +8,7 @@ namespace Rice::detail
8
8
  using Tuple_T = std::tuple<Types...>;
9
9
 
10
10
  template<std::size_t... I>
11
- constexpr static bool verifyTypes(std::index_sequence<I...>& indices)
11
+ constexpr static bool verifyTypes(std::index_sequence<I...>&)
12
12
  {
13
13
  return (Type<std::tuple_element_t<I, Tuple_T>>::verify() && ...);
14
14
  }
@@ -32,18 +32,23 @@ namespace Rice::detail
32
32
  public:
33
33
  To_Ruby() = default;
34
34
 
35
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
35
+ explicit To_Ruby(Arg* arg) : arg_(arg)
36
36
  {
37
37
  }
38
38
 
39
39
  template<typename U, typename V>
40
40
  VALUE convertElement(U& data, bool takeOwnership)
41
41
  {
42
- return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
42
+ Arg arg("arg1");
43
+ if (takeOwnership)
44
+ {
45
+ arg.takeOwnership();
46
+ }
47
+ return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
43
48
  }
44
49
 
45
50
  template<typename U, std::size_t... I>
46
- VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
51
+ VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
47
52
  {
48
53
  // Create a tuple of the variant types so we can look over the tuple's types
49
54
  using Tuple_T = std::tuple<Types...>;
@@ -101,7 +106,7 @@ namespace Rice::detail
101
106
  }
102
107
 
103
108
  private:
104
- Return* returnInfo_ = nullptr;
109
+ Arg* arg_ = nullptr;
105
110
  };
106
111
 
107
112
  template<typename...Types>
@@ -110,25 +115,31 @@ namespace Rice::detail
110
115
  public:
111
116
  To_Ruby() = default;
112
117
 
113
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
118
+ explicit To_Ruby(Arg* arg) : arg_(arg)
114
119
  {
115
120
  }
116
121
 
117
122
  template<typename U, typename V>
118
123
  VALUE convertElement(U& data, bool takeOwnership)
119
124
  {
125
+ Arg arg("arg1");
126
+ if (takeOwnership)
127
+ {
128
+ arg.takeOwnership();
129
+ }
130
+
120
131
  if constexpr (std::is_const_v<U>)
121
132
  {
122
- return To_Ruby<V>().convert(std::get<V>(data));
133
+ return To_Ruby<V>(&arg).convert(std::get<V>(data));
123
134
  }
124
135
  else
125
136
  {
126
- return To_Ruby<V>().convert(std::forward<V>(std::get<V>(data)));
137
+ return To_Ruby<V>(&arg).convert(std::forward<V>(std::get<V>(data)));
127
138
  }
128
139
  }
129
140
 
130
141
  template<typename U, std::size_t... I>
131
- VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>& indices)
142
+ VALUE convertIterator(U& data, bool takeOwnership, std::index_sequence<I...>&)
132
143
  {
133
144
  // Create a tuple of the variant types so we can look over the tuple's types
134
145
  using Tuple_T = std::tuple<Types...>;
@@ -154,13 +165,13 @@ namespace Rice::detail
154
165
  template<typename U>
155
166
  VALUE convert(U& data)
156
167
  {
157
- bool isOwner = (this->returnInfo_ && this->returnInfo_->isOwner());
168
+ bool isOwner = (this->arg_ && this->arg_->isOwner());
158
169
  auto indices = std::make_index_sequence<std::variant_size_v<std::variant<Types...>>>{};
159
170
  return convertIterator(data, isOwner, indices);
160
171
  }
161
172
 
162
173
  private:
163
- Return* returnInfo_ = nullptr;
174
+ Arg* arg_ = nullptr;
164
175
  };
165
176
 
166
177
  template<typename...Types>
@@ -169,18 +180,18 @@ namespace Rice::detail
169
180
  public:
170
181
  From_Ruby() = default;
171
182
 
172
- explicit From_Ruby(Arg* arg)
183
+ explicit From_Ruby(Arg* arg) : arg_(arg)
173
184
  {
174
185
  }
175
186
 
176
- Convertible is_convertible(VALUE value)
187
+ double is_convertible(VALUE value)
177
188
  {
178
- Convertible result = Convertible::None;
189
+ double result = Convertible::None;
179
190
 
180
191
  for_each_tuple(this->fromRubys_,
181
192
  [&](auto& fromRuby)
182
193
  {
183
- result = result | fromRuby.is_convertible(value);
194
+ result = (std::max)(result, fromRuby.is_convertible(value));
184
195
  });
185
196
 
186
197
  return result;
@@ -192,17 +203,17 @@ namespace Rice::detail
192
203
  {
193
204
  int i = 0;
194
205
  int index = -1;
195
- Convertible foundConversion = Convertible::None;
206
+ double foundScore = Convertible::None;
196
207
 
197
208
  for_each_tuple(this->fromRubys_,
198
209
  [&](auto& fromRuby)
199
210
  {
200
- Convertible isConvertible = fromRuby.is_convertible(value);
211
+ double score = fromRuby.is_convertible(value);
201
212
 
202
- if (isConvertible > foundConversion)
213
+ if (score > foundScore)
203
214
  {
204
215
  index = i;
205
- foundConversion = isConvertible;
216
+ foundScore = score;
206
217
  }
207
218
  i++;
208
219
  });
@@ -240,7 +251,10 @@ namespace Rice::detail
240
251
  return convertInternal<I + 1>(value, index);
241
252
  }
242
253
  }
243
- rb_raise(rb_eArgError, "Could not find converter for variant");
254
+ else
255
+ {
256
+ rb_raise(rb_eArgError, "Could not find converter for variant");
257
+ }
244
258
  }
245
259
 
246
260
  std::variant<Types...> convert(VALUE value)
@@ -250,6 +264,7 @@ namespace Rice::detail
250
264
  }
251
265
 
252
266
  private:
267
+ Arg* arg_ = nullptr;
253
268
  // Possible converters we could use for this variant
254
269
  using From_Ruby_Ts = std::tuple<From_Ruby<Types>...>;
255
270
  From_Ruby_Ts fromRubys_;
@@ -261,7 +276,7 @@ namespace Rice::detail
261
276
  public:
262
277
  From_Ruby() = default;
263
278
 
264
- explicit From_Ruby(Arg* arg)
279
+ explicit From_Ruby(Arg* arg) : arg_(arg)
265
280
  {
266
281
  }
267
282
 
@@ -273,6 +288,7 @@ namespace Rice::detail
273
288
  }
274
289
 
275
290
  private:
291
+ Arg* arg_ = nullptr;
276
292
  std::variant<Types...> converted_;
277
293
  };
278
294
  }
data/rice/stl/vector.ipp CHANGED
@@ -39,7 +39,7 @@ namespace Rice
39
39
  Difference_T normalizeIndex(Size_T size, Difference_T index, bool enforceBounds = false)
40
40
  {
41
41
  // Negative indices mean count from the right
42
- if (index < 0 && (-index <= size))
42
+ if (index < 0 && ((Size_T)(-index) <= size))
43
43
  {
44
44
  index = size + index;
45
45
  }
@@ -83,7 +83,7 @@ namespace Rice
83
83
  }
84
84
 
85
85
  // Wrap the vector
86
- detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data, true);
86
+ detail::wrapConstructed<T>(self, Data_Type<T>::ruby_data_type(), data);
87
87
  });
88
88
  }
89
89
 
@@ -99,10 +99,10 @@ namespace Rice
99
99
  }
100
100
  else
101
101
  {
102
- klass_.define_method("resize", [](const T& vector, Size_T newSize)
103
- {
104
- // Do nothing
105
- });
102
+ klass_.define_method("resize", [](const T&, Size_T)
103
+ {
104
+ // Do nothing
105
+ });
106
106
  }
107
107
  }
108
108
 
@@ -159,7 +159,7 @@ namespace Rice
159
159
  return vector[index];
160
160
  }
161
161
  })
162
- .template define_method<Value_T*(T::*)()>("data", &T::data, Return().setBuffer());
162
+ .template define_method<Value_T*(T::*)()>("data", &T::data, ReturnBuffer());
163
163
  }
164
164
  else
165
165
  {
@@ -240,7 +240,11 @@ namespace Rice
240
240
  {
241
241
  if constexpr (detail::is_comparable_v<T>)
242
242
  {
243
- klass_.define_method("delete", [](T& vector, Parameter_T element) -> std::optional<Value_T>
243
+ klass_.define_method("==", [](T& vector, T& other)->bool
244
+ {
245
+ return vector == other;
246
+ })
247
+ .define_method("delete", [](T& vector, Parameter_T element) -> std::optional<Value_T>
244
248
  {
245
249
  auto iter = std::find(vector.begin(), vector.end(), element);
246
250
  if (iter == vector.end())
@@ -274,21 +278,22 @@ namespace Rice
274
278
  return iter - vector.begin();
275
279
  }
276
280
  });
281
+ rb_define_alias(klass_, "eql?", "==");
277
282
  }
278
283
  else
279
284
  {
280
- klass_.define_method("delete", [](T& vector, Parameter_T element) -> std::optional<Value_T>
281
- {
282
- return std::nullopt;
283
- })
284
- .define_method("include?", [](const T& vector, Parameter_T element)
285
- {
286
- return false;
287
- })
288
- .define_method("index", [](const T& vector, Parameter_T element) -> std::optional<Difference_T>
289
- {
290
- return std::nullopt;
291
- });
285
+ klass_.define_method("delete", [](T&, Parameter_T) -> std::optional<Value_T>
286
+ {
287
+ return std::nullopt;
288
+ })
289
+ .define_method("include?", [](const T&, Parameter_T)
290
+ {
291
+ return false;
292
+ })
293
+ .define_method("index", [](const T&, Parameter_T) -> std::optional<Difference_T>
294
+ {
295
+ return std::nullopt;
296
+ });
292
297
  }
293
298
  }
294
299
 
@@ -313,7 +318,7 @@ namespace Rice
313
318
  })
314
319
  .define_method("insert", [this](T& vector, Difference_T index, Parameter_T element) -> T&
315
320
  {
316
- int normalized = normalizeIndex(vector.size(), index, true);
321
+ size_t normalized = normalizeIndex(vector.size(), index, true);
317
322
  // For a Ruby array a positive index means insert the element before the index. But
318
323
  // a negative index means insert the element *after* the index. std::vector
319
324
  // inserts *before* the index. So add 1 if this is a negative index.
@@ -412,10 +417,10 @@ namespace Rice
412
417
  }
413
418
  else
414
419
  {
415
- klass_.define_method("to_s", [](const T& vector)
416
- {
417
- return "[Not printable]";
418
- });
420
+ klass_.define_method("to_s", [](const T&)
421
+ {
422
+ return "[Not printable]";
423
+ });
419
424
  }
420
425
  }
421
426
 
@@ -477,7 +482,7 @@ namespace Rice
477
482
  {
478
483
  }
479
484
 
480
- Convertible is_convertible(VALUE value)
485
+ double is_convertible(VALUE value)
481
486
  {
482
487
  switch (rb_type(value))
483
488
  {
@@ -487,7 +492,7 @@ namespace Rice
487
492
  case RUBY_T_ARRAY:
488
493
  if constexpr (std::is_default_constructible_v<T>)
489
494
  {
490
- return Convertible::Cast;
495
+ return Convertible::Exact;
491
496
  }
492
497
  default:
493
498
  return Convertible::None;
@@ -513,7 +518,7 @@ namespace Rice
513
518
  }
514
519
  default:
515
520
  {
516
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
521
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
517
522
  detail::protect(rb_obj_classname, value), "std::vector");
518
523
  }
519
524
  }
@@ -533,7 +538,7 @@ namespace Rice
533
538
  {
534
539
  }
535
540
 
536
- Convertible is_convertible(VALUE value)
541
+ double is_convertible(VALUE value)
537
542
  {
538
543
  switch (rb_type(value))
539
544
  {
@@ -543,7 +548,7 @@ namespace Rice
543
548
  case RUBY_T_ARRAY:
544
549
  if constexpr (std::is_default_constructible_v<T>)
545
550
  {
546
- return Convertible::Cast;
551
+ return Convertible::Exact;
547
552
  }
548
553
  default:
549
554
  return Convertible::None;
@@ -570,7 +575,7 @@ namespace Rice
570
575
  }
571
576
  default:
572
577
  {
573
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
578
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
574
579
  detail::protect(rb_obj_classname, value), "std::vector");
575
580
  }
576
581
  }
@@ -591,7 +596,7 @@ namespace Rice
591
596
  {
592
597
  }
593
598
 
594
- Convertible is_convertible(VALUE value)
599
+ double is_convertible(VALUE value)
595
600
  {
596
601
  switch (rb_type(value))
597
602
  {
@@ -604,7 +609,7 @@ namespace Rice
604
609
  case RUBY_T_ARRAY:
605
610
  if constexpr (std::is_default_constructible_v<T>)
606
611
  {
607
- return Convertible::Cast;
612
+ return Convertible::Exact;
608
613
  }
609
614
  default:
610
615
  return Convertible::None;
@@ -631,7 +636,7 @@ namespace Rice
631
636
  }
632
637
  default:
633
638
  {
634
- throw Exception(rb_eTypeError, "wrong argument type %s (expected % s)",
639
+ throw Exception(rb_eTypeError, "wrong argument type %s (expected %s)",
635
640
  detail::protect(rb_obj_classname, value), "std::vector");
636
641
  }
637
642
  }
@@ -652,7 +657,7 @@ namespace Rice
652
657
  public:
653
658
  To_Ruby() = default;
654
659
 
655
- explicit To_Ruby(Return* returnInfo) : returnInfo_(returnInfo)
660
+ explicit To_Ruby(Arg* arg) : arg_(arg)
656
661
  {
657
662
  }
658
663
 
@@ -662,7 +667,7 @@ namespace Rice
662
667
  }
663
668
 
664
669
  private:
665
- Return* returnInfo_ = nullptr;
670
+ Arg* arg_ = nullptr;
666
671
  };
667
672
  }
668
673
  }
@@ -9,12 +9,12 @@ namespace Rice::detail
9
9
  template<typename Function_T>
10
10
  struct function_traits;
11
11
 
12
- template<typename Return_T, typename Class_T, typename...Arg_Ts>
13
- struct function_traits<Return_T(Class_T, Arg_Ts...)>
12
+ template<typename Return_T, typename Class_T, typename...Parameter_Ts>
13
+ struct function_traits<Return_T(Class_T, Parameter_Ts...)>
14
14
  {
15
- using arg_types = std::tuple<Arg_Ts...>;
15
+ using arg_types = std::tuple<Parameter_Ts...>;
16
16
 
17
- static constexpr std::size_t arity = sizeof...(Arg_Ts);
17
+ static constexpr std::size_t arity = sizeof...(Parameter_Ts);
18
18
 
19
19
  template<std::size_t N>
20
20
  using nth_arg = typename std::tuple_element_t<N, arg_types>;
@@ -37,47 +37,47 @@ namespace Rice::detail
37
37
  };
38
38
 
39
39
  // C functions and static member functions passed by pointer
40
- template<typename Return_T, typename ...Arg_Ts>
41
- struct function_traits<Return_T(*)(Arg_Ts...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
40
+ template<typename Return_T, typename ...Parameter_Ts>
41
+ struct function_traits<Return_T(*)(Parameter_Ts...)> : public function_traits<Return_T(std::nullptr_t, Parameter_Ts...)>
42
42
  {
43
- using Function_T = Return_T(*)(Arg_Ts...);
43
+ using Function_T = Return_T(*)(Parameter_Ts...);
44
44
  };
45
45
 
46
46
  // C functions passed by pointer that take one or more defined parameter than a variable
47
47
  // number of parameters (the second ...)
48
- template<typename Return_T, typename ...Arg_Ts>
49
- struct function_traits<Return_T(*)(Arg_Ts..., ...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
48
+ template<typename Return_T, typename ...Parameter_Ts>
49
+ struct function_traits<Return_T(*)(Parameter_Ts..., ...)> : public function_traits<Return_T(std::nullptr_t, Parameter_Ts...)>
50
50
  {
51
51
  };
52
52
 
53
53
  // C Functions or static member functions passed by reference
54
- template<typename Return_T, typename ...Arg_Ts>
55
- struct function_traits<Return_T(&)(Arg_Ts...)> : public function_traits<Return_T(std::nullptr_t, Arg_Ts...)>
54
+ template<typename Return_T, typename ...Parameter_Ts>
55
+ struct function_traits<Return_T(&)(Parameter_Ts...)> : public function_traits<Return_T(std::nullptr_t, Parameter_Ts...)>
56
56
  {
57
57
  };
58
58
 
59
59
  // Member Functions on C++ classes
60
- template<typename Return_T, typename Class_T, typename...Arg_Ts>
61
- struct function_traits<Return_T(Class_T::*)(Arg_Ts...)> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
60
+ template<typename Return_T, typename Class_T, typename...Parameter_Ts>
61
+ struct function_traits<Return_T(Class_T::*)(Parameter_Ts...)> : public function_traits<Return_T(Class_T*, Parameter_Ts...)>
62
62
  {
63
63
  };
64
64
 
65
65
  // const member Functions on C++ classes
66
- template<typename Return_T, typename Class_T, typename...Arg_Ts>
67
- struct function_traits<Return_T(Class_T::*)(Arg_Ts...) const> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
66
+ template<typename Return_T, typename Class_T, typename...Parameter_Ts>
67
+ struct function_traits<Return_T(Class_T::*)(Parameter_Ts...) const> : public function_traits<Return_T(Class_T*, Parameter_Ts...)>
68
68
  {
69
69
  };
70
70
 
71
71
  // noexcept member Functions on C++ classes
72
- template<typename Return_T, typename Class_T, typename...Arg_Ts>
73
- struct function_traits<Return_T(Class_T::*)(Arg_Ts...) noexcept> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
72
+ template<typename Return_T, typename Class_T, typename...Parameter_Ts>
73
+ struct function_traits<Return_T(Class_T::*)(Parameter_Ts...) noexcept> : public function_traits<Return_T(Class_T*, Parameter_Ts...)>
74
74
  {
75
75
  };
76
76
 
77
77
 
78
78
  // const noexcept member Functions on C++ classes
79
- template<typename Return_T, typename Class_T, typename...Arg_Ts>
80
- struct function_traits<Return_T(Class_T::*)(Arg_Ts...) const noexcept> : public function_traits<Return_T(Class_T*, Arg_Ts...)>
79
+ template<typename Return_T, typename Class_T, typename...Parameter_Ts>
80
+ struct function_traits<Return_T(Class_T::*)(Parameter_Ts...) const noexcept> : public function_traits<Return_T(Class_T*, Parameter_Ts...)>
81
81
  {
82
82
  };
83
83
 
@@ -18,8 +18,8 @@ namespace Rice::detail
18
18
  {
19
19
  using Return_T = typename function_traits<Function_T>::return_type;
20
20
  using Class_T = typename function_traits<Function_T>::template nth_arg<0>;
21
- using Arg_Ts = typename tuple_shift<typename function_traits<Function_T>::arg_types>::type;
22
- static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
21
+ using Parameter_Ts = typename tuple_shift<typename function_traits<Function_T>::arg_types>::type;
22
+ static constexpr std::size_t arity = std::tuple_size_v<Parameter_Ts>;
23
23
  };
24
24
 
25
25
  // Member functions that have an implied self parameter of an object instance
@@ -29,8 +29,8 @@ namespace Rice::detail
29
29
  {
30
30
  using Return_T = typename function_traits<Function_T>::return_type;
31
31
  using Class_T = typename function_traits<Function_T>::class_type;
32
- using Arg_Ts = typename function_traits<Function_T>::arg_types;
33
- static constexpr std::size_t arity = std::tuple_size_v<Arg_Ts>;
32
+ using Parameter_Ts = typename function_traits<Function_T>::arg_types;
33
+ static constexpr std::size_t arity = std::tuple_size_v<Parameter_Ts>;
34
34
  };
35
35
  }
36
36
  #endif // Rice__detail__method_traits__hpp_