You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,8 @@ Incompatible Changes:
41
41
42
42
Think of this as similar to how you would capture a block in Ruby using the &block syntax.
43
43
44
+
* The `Data_Type<T>::define()` method has been removed. See the [Class Templates](docs/bindings/class_templates.md) documentation for the recommended approach.
45
+
44
46
## 4.9.1 (2026-01-04)
45
47
This release focuses on improving memory management for STL containers and attribute setters.
Copy file name to clipboardExpand all lines: docs/architecture/incomplete_types.md
+84Lines changed: 84 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -182,8 +182,92 @@ Since Rice only stores pointers and never copies incomplete types by value, it d
182
182
- Cannot access members of incomplete types directly
183
183
- The incomplete type must be registered before any function using it is called
184
184
185
+
## Smart Pointers to Incomplete Types
186
+
187
+
While Rice supports raw pointers and references to incomplete types, **smart pointers** (`std::shared_ptr`, `std::unique_ptr`, etc.) require special handling.
188
+
189
+
### The Problem
190
+
191
+
Smart pointers need to instantiate their deleter at compile time. When you create a `std::shared_ptr<T>` from a raw `T*`, the template must generate code to `delete` the pointer - which requires `T` to be a complete type:
192
+
193
+
```cpp
194
+
classImpl; // Forward declaration - incomplete
195
+
196
+
// This will cause a compiler warning/error:
197
+
// "deletion of pointer to incomplete type; no destructor called"
Rice's `define_shared_ptr<T>()` function uses `is_complete_v<T>` to detect incomplete types and skip registering constructors that would require the complete type:
204
+
205
+
```cpp
206
+
// From rice/stl/shared_ptr.ipp
207
+
if constexpr (detail::is_complete_v<T> && !std::is_void_v<T>)
-**Complete types**: Full smart pointer support including construction from raw pointers
216
+
-**Incomplete types**: Smart pointer type is registered, but constructors taking `T*` are skipped
217
+
218
+
### Passing Existing Smart Pointers
219
+
220
+
Even without the `T*` constructor, you can still pass around existing smart pointers that were created on the C++ side (where the complete type is available):
VALUE rb_cMat2b = Mat__instantiate<cv::Vec<unsigned char, 2>>(rb_mCv, "Mat2b");
76
75
77
76
...
78
77
```
79
78
80
79
There are few things to notice about the above code.
81
80
82
-
First, by convention, the method is named `"#{template_name}_builder"`. So in this case `Mat__builder`. You may of course name the method anything you want.
81
+
First, by convention, the function is named `"#{template_name}_instantiate"`. So in this case `Mat__instantiate`. You may of course name the function anything you want.
83
82
84
83
Second, the `template` keyword needs to be used in front of methods:
Copy file name to clipboardExpand all lines: docs/bindings/operators.md
+42-8Lines changed: 42 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,40 @@ C++ and Ruby support overriding the same arithmetic operators.
24
24
| / | / |
25
25
| % | % |
26
26
27
+
## Unary Operators
28
+
29
+
C++ supports unary versions of `+`, `-`, `~`, and `!`. Ruby uses special method names for unary `+` and `-` to distinguish them from their binary counterparts.
30
+
31
+
| C++ | Ruby | Notes |
32
+
|:---:|:----:|:------|
33
+
| +a | +@ | Unary plus |
34
+
| -a | -@ | Unary minus (negation) |
35
+
|~a | ~ | Bitwise NOT |
36
+
| !a | ! | Logical NOT |
37
+
38
+
Example:
39
+
40
+
```cpp
41
+
classVector
42
+
{
43
+
public:
44
+
Vector operator-() const; // Unary minus
45
+
Vector operator+() const; // Unary plus
46
+
};
47
+
```
48
+
49
+
```cpp
50
+
define_method("-@", &Vector::operator-);
51
+
define_method("+@", &Vector::operator+);
52
+
```
53
+
54
+
In Ruby:
55
+
56
+
```ruby
57
+
v = Vector.new(1, 2, 3)
58
+
negated = -v # Calls -@
59
+
```
60
+
27
61
## Assignment Operators
28
62
29
63
C++ supports overriding assignment operators while Ruby does not. Thus these operators must be mapped to Ruby methods.
@@ -35,7 +69,7 @@ C++ supports overriding assignment operators while Ruby does not. Thus these ope
35
69
| -= | Not overridable | assign_minus |
36
70
|*= | Not overridable | assign_multiply |
37
71
| /= | Not overridable | assign_divide |
38
-
| %= | Not overridable |assign_plus |
72
+
| %= | Not overridable |assign_modulus|
39
73
40
74
## Bitwise Operators
41
75
@@ -57,8 +91,8 @@ C++ and Ruby support overriding the same comparison operators.
57
91
|:---:|:----:|
58
92
| == | == |
59
93
| != | != |
60
-
| > |<|
61
-
| < |>|
94
+
| > |>|
95
+
| < |<|
62
96
| >= | >= |
63
97
| <= | <= |
64
98
@@ -70,18 +104,18 @@ Ruby allows the `!` operator to be overridden but not `&&` or `||`.
70
104
|:------:|:----------------:|:------------|
71
105
| && | Not overridable | logical_and |
72
106
|\|\|| Not overridable | logical_or |
73
-
| ! | ! |decrement_pre|
107
+
| ! | ! ||
74
108
75
109
## Increment / Decrement Operators
76
110
77
111
C++ supports increment and decrement operators while Ruby does not. Thus these operators must be mapped to Ruby methods.
0 commit comments