rice 4.7.1 → 4.8.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -1
- data/CMakeLists.txt +14 -22
- data/CMakePresets.json +203 -75
- data/FindRuby.cmake +358 -123
- data/bin/rice-doc.rb +56 -141
- data/include/rice/api.hpp +248 -0
- data/include/rice/rice.hpp +2237 -1657
- data/include/rice/stl.hpp +346 -443
- data/lib/rice/doc/config.rb +70 -0
- data/lib/rice/doc/cpp_reference.rb +1 -4
- data/lib/rice/doc/mkdocs.rb +58 -20
- data/lib/rice/doc/rice.rb +20 -0
- data/lib/rice/doc.rb +1 -0
- data/lib/rice/make_rice_headers.rb +7 -0
- data/lib/rice/native_registry.rb +2 -2
- data/lib/rice/rbs.rb +2 -2
- data/lib/rice/version.rb +1 -1
- data/lib/rubygems_plugin.rb +12 -9
- data/rice/Arg.hpp +12 -6
- data/rice/Arg.ipp +14 -7
- data/rice/Buffer.ipp +44 -40
- data/rice/Callback.hpp +1 -1
- data/rice/Callback.ipp +2 -7
- data/rice/Constructor.hpp +1 -1
- data/rice/Constructor.ipp +11 -11
- data/rice/Data_Object.ipp +15 -15
- data/rice/Data_Type.hpp +9 -10
- data/rice/Data_Type.ipp +22 -25
- data/rice/Director.hpp +1 -0
- data/rice/Enum.ipp +58 -39
- data/rice/Exception.hpp +4 -4
- data/rice/Exception.ipp +7 -7
- data/rice/NoGVL.hpp +13 -0
- data/rice/Reference.hpp +56 -0
- data/rice/Reference.ipp +96 -0
- data/rice/Return.hpp +4 -1
- data/rice/Return.ipp +0 -6
- data/rice/cpp_api/Array.hpp +41 -4
- data/rice/cpp_api/Array.ipp +105 -9
- data/rice/cpp_api/Class.hpp +2 -2
- data/rice/cpp_api/Class.ipp +4 -4
- data/rice/cpp_api/Hash.ipp +7 -4
- data/rice/cpp_api/Module.hpp +4 -4
- data/rice/cpp_api/Module.ipp +12 -10
- data/rice/cpp_api/Object.hpp +4 -4
- data/rice/cpp_api/Object.ipp +15 -12
- data/rice/cpp_api/String.hpp +2 -2
- data/rice/cpp_api/String.ipp +11 -8
- data/rice/cpp_api/Symbol.ipp +7 -7
- data/rice/cpp_api/shared_methods.hpp +5 -9
- data/rice/detail/InstanceRegistry.hpp +0 -2
- data/rice/detail/Native.hpp +31 -21
- data/rice/detail/Native.ipp +282 -130
- data/rice/detail/NativeAttributeGet.hpp +5 -7
- data/rice/detail/NativeAttributeGet.ipp +26 -26
- data/rice/detail/NativeAttributeSet.hpp +2 -4
- data/rice/detail/NativeAttributeSet.ipp +20 -16
- data/rice/detail/NativeCallback.hpp +77 -0
- data/rice/detail/NativeCallback.ipp +280 -0
- data/rice/detail/NativeFunction.hpp +11 -21
- data/rice/detail/NativeFunction.ipp +58 -119
- data/rice/detail/NativeInvoker.hpp +4 -4
- data/rice/detail/NativeInvoker.ipp +7 -7
- data/rice/detail/NativeIterator.hpp +2 -4
- data/rice/detail/NativeIterator.ipp +18 -14
- data/rice/detail/NativeMethod.hpp +10 -20
- data/rice/detail/NativeMethod.ipp +54 -114
- data/rice/detail/NativeProc.hpp +5 -7
- data/rice/detail/NativeProc.ipp +39 -28
- data/rice/detail/NativeRegistry.hpp +0 -1
- data/rice/detail/Parameter.hpp +15 -8
- data/rice/detail/Parameter.ipp +102 -43
- data/rice/detail/Proc.ipp +14 -28
- data/rice/detail/RubyType.ipp +2 -53
- data/rice/detail/Type.hpp +23 -7
- data/rice/detail/Type.ipp +73 -93
- data/rice/detail/TypeRegistry.ipp +5 -4
- data/rice/detail/Wrapper.hpp +1 -1
- data/rice/detail/Wrapper.ipp +18 -10
- data/rice/detail/from_ruby.hpp +8 -6
- data/rice/detail/from_ruby.ipp +306 -173
- data/rice/detail/ruby.hpp +23 -0
- data/rice/libc/file.hpp +4 -4
- data/rice/rice.hpp +6 -8
- data/rice/rice_api/Native.ipp +5 -1
- data/rice/rice_api/Parameter.ipp +1 -1
- data/rice/ruby_mark.hpp +2 -1
- data/rice/stl/complex.ipp +12 -8
- data/rice/stl/map.ipp +27 -22
- data/rice/stl/monostate.ipp +16 -12
- data/rice/stl/multimap.hpp +0 -2
- data/rice/stl/multimap.ipp +27 -22
- data/rice/stl/optional.ipp +27 -11
- data/rice/stl/pair.ipp +5 -5
- data/rice/stl/reference_wrapper.ipp +5 -4
- data/rice/stl/set.ipp +16 -16
- data/rice/stl/shared_ptr.hpp +0 -16
- data/rice/stl/shared_ptr.ipp +34 -190
- data/rice/stl/string.ipp +18 -18
- data/rice/stl/string_view.ipp +1 -1
- data/rice/stl/tuple.ipp +15 -36
- data/rice/stl/unique_ptr.ipp +18 -8
- data/rice/stl/unordered_map.ipp +20 -15
- data/rice/stl/variant.ipp +37 -21
- data/rice/stl/vector.ipp +41 -36
- data/rice/traits/function_traits.hpp +19 -19
- data/rice/traits/method_traits.hpp +4 -4
- data/rice/traits/rice_traits.hpp +162 -39
- data/rice.gemspec +1 -3
- data/test/test_Array.cpp +261 -3
- data/test/test_Attribute.cpp +6 -3
- data/test/test_Buffer.cpp +6 -42
- data/test/test_Callback.cpp +77 -23
- data/test/test_Data_Object.cpp +1 -1
- data/test/test_Data_Type.cpp +21 -22
- data/test/test_Director.cpp +2 -4
- data/test/test_Enum.cpp +34 -5
- data/test/test_File.cpp +9 -5
- data/test/test_From_Ruby.cpp +4 -3
- data/test/test_GVL.cpp +3 -3
- data/test/test_Hash.cpp +1 -1
- data/test/test_Iterator.cpp +54 -22
- data/test/test_Keep_Alive.cpp +1 -1
- data/test/test_Keep_Alive_No_Wrapper.cpp +1 -1
- data/test/test_Module.cpp +5 -5
- data/test/test_Overloads.cpp +345 -48
- data/test/test_Proc.cpp +54 -0
- data/test/test_Reference.cpp +181 -0
- data/test/test_Self.cpp +2 -2
- data/test/test_Stl_Set.cpp +6 -6
- data/test/test_Stl_SharedPtr.cpp +54 -30
- data/test/test_Stl_String_View.cpp +4 -2
- data/test/test_Stl_Tuple.cpp +1 -1
- data/test/test_Stl_Variant.cpp +6 -14
- data/test/test_Stl_Vector.cpp +61 -30
- data/test/test_String.cpp +4 -2
- data/test/test_Struct.cpp +1 -1
- data/test/test_Symbol.cpp +1 -1
- data/test/test_To_Ruby.cpp +1 -0
- data/test/test_Type.cpp +36 -35
- data/test/test_global_functions.cpp +1 -1
- data/test/unittest.cpp +1 -1
- data/test/unittest.hpp +5 -5
- metadata +10 -10
- data/rice/Function.hpp +0 -17
- data/rice/Function.ipp +0 -13
- data/rice/detail/MethodInfo.hpp +0 -48
- data/rice/detail/MethodInfo.ipp +0 -99
- data/rice/detail/NativeCallbackFFI.hpp +0 -55
- data/rice/detail/NativeCallbackFFI.ipp +0 -152
- data/rice/detail/NativeCallbackSimple.hpp +0 -30
- data/rice/detail/NativeCallbackSimple.ipp +0 -29
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
|
|
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
|
|
103
|
-
|
|
104
|
-
|
|
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,
|
|
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("
|
|
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
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
.define_method("include?", [](const T
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
.define_method("index", [](const T
|
|
289
|
-
|
|
290
|
-
|
|
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
|
-
|
|
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&
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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
|
-
|
|
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::
|
|
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 %
|
|
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(
|
|
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
|
-
|
|
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...
|
|
13
|
-
struct function_traits<Return_T(Class_T,
|
|
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<
|
|
15
|
+
using arg_types = std::tuple<Parameter_Ts...>;
|
|
16
16
|
|
|
17
|
-
static constexpr std::size_t arity = sizeof...(
|
|
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 ...
|
|
41
|
-
struct function_traits<Return_T(*)(
|
|
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(*)(
|
|
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 ...
|
|
49
|
-
struct function_traits<Return_T(*)(
|
|
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 ...
|
|
55
|
-
struct function_traits<Return_T(&)(
|
|
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...
|
|
61
|
-
struct function_traits<Return_T(Class_T::*)(
|
|
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...
|
|
67
|
-
struct function_traits<Return_T(Class_T::*)(
|
|
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...
|
|
73
|
-
struct function_traits<Return_T(Class_T::*)(
|
|
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...
|
|
80
|
-
struct function_traits<Return_T(Class_T::*)(
|
|
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
|
|
22
|
-
static constexpr std::size_t arity = std::tuple_size_v<
|
|
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
|
|
33
|
-
static constexpr std::size_t arity = std::tuple_size_v<
|
|
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_
|
data/rice/traits/rice_traits.hpp
CHANGED
|
@@ -19,6 +19,10 @@ namespace Rice
|
|
|
19
19
|
template<typename T>
|
|
20
20
|
constexpr bool is_const_any_v = std::is_const_v<std::remove_pointer_t<std::remove_pointer_t<std::remove_reference_t<T>>>>;
|
|
21
21
|
|
|
22
|
+
// Helper to detect char types
|
|
23
|
+
template<typename T>
|
|
24
|
+
constexpr bool is_char_type_v = std::is_same_v<T, char> || std::is_same_v<T, signed char> || std::is_same_v<T, unsigned char>;
|
|
25
|
+
|
|
22
26
|
// Recursively remove const/volatile
|
|
23
27
|
template<typename T>
|
|
24
28
|
struct remove_cv_recursive
|
|
@@ -109,45 +113,6 @@ namespace Rice
|
|
|
109
113
|
template <typename T>
|
|
110
114
|
constexpr bool is_std_vector_v = is_std_vector<T>::value;
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
// -- Tuple Helpers ---
|
|
114
|
-
template<typename T>
|
|
115
|
-
struct tuple_shift;
|
|
116
|
-
|
|
117
|
-
template<typename T, typename...Arg_Ts>
|
|
118
|
-
struct tuple_shift<std::tuple<T, Arg_Ts...>>
|
|
119
|
-
{
|
|
120
|
-
using type = std::tuple<Arg_Ts...>;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
template<typename T, typename...Arg_Ts>
|
|
124
|
-
struct tuple_unshift;
|
|
125
|
-
|
|
126
|
-
template<typename T, typename...Arg_Ts>
|
|
127
|
-
struct tuple_unshift<T, std::tuple<Arg_Ts...>>
|
|
128
|
-
{
|
|
129
|
-
using type = std::tuple<T, Arg_Ts...>;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
template<template<typename, typename...> typename T, typename...Arg_Ts>
|
|
133
|
-
struct tuple_map;
|
|
134
|
-
|
|
135
|
-
template<template<typename, typename...> typename T, typename...Arg_Ts>
|
|
136
|
-
struct tuple_map<T, std::tuple<Arg_Ts...>>
|
|
137
|
-
{
|
|
138
|
-
using type = std::tuple<T<Arg_Ts>...>;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
template<typename...Arg_Ts>
|
|
143
|
-
struct tuple_to_variant;
|
|
144
|
-
|
|
145
|
-
template<typename...Arg_Ts>
|
|
146
|
-
struct tuple_to_variant<std::tuple<Arg_Ts...>>
|
|
147
|
-
{
|
|
148
|
-
using type = std::variant<Arg_Ts...>;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
116
|
template<class T>
|
|
152
117
|
struct is_pointer_pointer : std::false_type {};
|
|
153
118
|
|
|
@@ -186,6 +151,164 @@ namespace Rice
|
|
|
186
151
|
|
|
187
152
|
template<typename T>
|
|
188
153
|
constexpr bool is_wrapped_v = is_wrapped<T>::value;
|
|
154
|
+
|
|
155
|
+
// -- Tuple Helpers ---
|
|
156
|
+
template<typename T>
|
|
157
|
+
struct tuple_shift;
|
|
158
|
+
|
|
159
|
+
template<typename T, typename...Parameter_Ts>
|
|
160
|
+
struct tuple_shift<std::tuple<T, Parameter_Ts...>>
|
|
161
|
+
{
|
|
162
|
+
using type = std::tuple<Parameter_Ts...>;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
template<typename T, typename...Parameter_Ts>
|
|
166
|
+
struct tuple_unshift;
|
|
167
|
+
|
|
168
|
+
template<typename T, typename...Parameter_Ts>
|
|
169
|
+
struct tuple_unshift<T, std::tuple<Parameter_Ts...>>
|
|
170
|
+
{
|
|
171
|
+
using type = std::tuple<T, Parameter_Ts...>;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
template<template<typename, typename...> typename T, typename...Parameter_Ts>
|
|
175
|
+
struct tuple_map;
|
|
176
|
+
|
|
177
|
+
template<template<typename, typename...> typename T, typename...Parameter_Ts>
|
|
178
|
+
struct tuple_map<T, std::tuple<Parameter_Ts...>>
|
|
179
|
+
{
|
|
180
|
+
using type = std::tuple<T<Parameter_Ts>...>;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
template<typename...Parameter_Ts>
|
|
184
|
+
struct tuple_to_variant;
|
|
185
|
+
|
|
186
|
+
template<typename...Parameter_Ts>
|
|
187
|
+
struct tuple_to_variant<std::tuple<Parameter_Ts...>>
|
|
188
|
+
{
|
|
189
|
+
using type = std::variant<Parameter_Ts...>;
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
template <typename T, typename... List>
|
|
193
|
+
struct is_one_of : std::disjunction<std::is_same<T, List>...> {};
|
|
194
|
+
|
|
195
|
+
template <typename T, typename... List>
|
|
196
|
+
constexpr bool is_one_of_v = is_one_of<T, List...>::value;
|
|
197
|
+
|
|
198
|
+
template<typename... FilterTypes, typename... Arg_Ts>
|
|
199
|
+
auto tuple_filter(const Arg_Ts&... args)
|
|
200
|
+
{
|
|
201
|
+
return std::tuple_cat([&args]()
|
|
202
|
+
{
|
|
203
|
+
if constexpr (is_one_of_v<Arg_Ts, FilterTypes...>)
|
|
204
|
+
{
|
|
205
|
+
return std::tuple<const Arg_Ts&>(args);
|
|
206
|
+
}
|
|
207
|
+
else
|
|
208
|
+
{
|
|
209
|
+
return std::tuple<>();
|
|
210
|
+
}
|
|
211
|
+
}()...);
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// --- filter_types: recursively builds a new tuple of allowed types ---
|
|
215
|
+
template <typename Tuple, typename... Allowed>
|
|
216
|
+
struct tuple_filter_types;
|
|
217
|
+
|
|
218
|
+
template <typename... Ts, typename... Allowed>
|
|
219
|
+
struct tuple_filter_types<std::tuple<Ts...>, Allowed...>
|
|
220
|
+
{
|
|
221
|
+
using type = decltype(std::tuple_cat(std::declval<
|
|
222
|
+
std::conditional_t<is_one_of_v<std::decay_t<Ts>, Allowed...>, std::tuple<Ts>, std::tuple<>>>()...));
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
template <typename Tuple, typename... Allowed>
|
|
226
|
+
using tuple_filter_types_t = typename tuple_filter_types<Tuple, Allowed...>::type;
|
|
227
|
+
|
|
228
|
+
template <typename T, std::size_t... Is>
|
|
229
|
+
auto vector_to_tuple(const std::vector<T>& vec, std::index_sequence<Is...>)
|
|
230
|
+
{
|
|
231
|
+
return std::make_tuple(vec[Is]...);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
template <typename Tuple, typename T, typename Seq>
|
|
235
|
+
struct tuple_pad_type;
|
|
236
|
+
|
|
237
|
+
template <typename... Ts, typename T, std::size_t... Is>
|
|
238
|
+
struct tuple_pad_type<std::tuple<Ts...>, T, std::index_sequence<Is...>>
|
|
239
|
+
{
|
|
240
|
+
// Use Is only to repeat T N times.
|
|
241
|
+
// std::conditional_t<true, T, something<Is>> is always T, but expands N times.
|
|
242
|
+
using type = std::tuple<
|
|
243
|
+
Ts...,
|
|
244
|
+
std::conditional_t<true, T, std::integral_constant<std::size_t, Is>>...
|
|
245
|
+
>;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
template <typename Tuple, typename T, std::size_t N>
|
|
249
|
+
using tuple_pad_type_t = typename tuple_pad_type<Tuple, T, std::make_index_sequence<N>>::type;
|
|
250
|
+
|
|
251
|
+
// Pad tuple with values from a vector (vector size must match N)
|
|
252
|
+
template <std::size_t N, typename T, typename... Ts>
|
|
253
|
+
auto pad_tuple(const std::tuple<Ts...>& original, const std::vector<T>& padding)
|
|
254
|
+
{
|
|
255
|
+
if (padding.size() != N)
|
|
256
|
+
{
|
|
257
|
+
throw std::invalid_argument("Vector size doesn't match template parameter N");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
auto padding_tuple = vector_to_tuple(padding, std::make_index_sequence<N>{});
|
|
261
|
+
return std::tuple_cat(original, padding_tuple);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
template <typename Tuple, typename... Ts>
|
|
265
|
+
struct tuple_element_index_impl;
|
|
266
|
+
|
|
267
|
+
template <typename... Ts>
|
|
268
|
+
struct tuple_element_index_impl<std::tuple<>, Ts...>
|
|
269
|
+
{
|
|
270
|
+
static constexpr std::size_t value = 0;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
template <typename First, typename... Rest, typename... Ts>
|
|
274
|
+
struct tuple_element_index_impl<std::tuple<First, Rest...>, Ts...>
|
|
275
|
+
{
|
|
276
|
+
static constexpr bool matches = (std::is_same_v<std::decay_t<First>, Ts> || ...);
|
|
277
|
+
static constexpr std::size_t value =
|
|
278
|
+
matches ? 0 : 1 + tuple_element_index_impl<std::tuple<Rest...>, Ts...>::value;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
template <typename Tuple, typename... Ts>
|
|
282
|
+
struct tuple_element_index
|
|
283
|
+
{
|
|
284
|
+
static constexpr std::size_t value = tuple_element_index_impl<Tuple, Ts...>::value;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
template <typename Tuple, typename... Ts>
|
|
288
|
+
inline constexpr std::size_t tuple_element_index_v = tuple_element_index<Tuple, Ts...>::value;
|
|
289
|
+
|
|
290
|
+
/* template<typename Target, typename T>
|
|
291
|
+
constexpr auto tuple_predicate(T&& element)
|
|
292
|
+
{
|
|
293
|
+
using U = std::decay_t<T>;
|
|
294
|
+
if constexpr (std::is_same_v<U, Target>)
|
|
295
|
+
{
|
|
296
|
+
return std::tuple<U>{ std::forward<T>(element) };
|
|
297
|
+
}
|
|
298
|
+
else
|
|
299
|
+
{
|
|
300
|
+
return std::tuple<>{};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
template<typename Class_T, typename... Ts>
|
|
305
|
+
constexpr auto tuple_filter(Ts&&... args)
|
|
306
|
+
{
|
|
307
|
+
return std::tuple_cat(tuple_predicate<Class_T>(std::forward<Ts>(args))...);
|
|
308
|
+
}*/
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
189
312
|
} // detail
|
|
190
313
|
} // Rice
|
|
191
314
|
|