|
From: | anonymous |
Subject: | [Octave-bug-tracker] [bug #59500] sub-classes of octave_base_value aren't assignable |
Date: | Sun, 22 Nov 2020 10:24:23 -0500 (EST) |
User-agent: | Mozilla/5.0 (Windows NT 5.1; rv:68.9) Gecko/20100101 Goanna/4.6 Firefox/68.9 Mypal/28.14.2 |
URL: <https://savannah.gnu.org/bugs/?59500> Summary: sub-classes of octave_base_value aren't assignable Project: GNU Octave Submitted by: None Submitted on: Sun 22 Nov 2020 03:24:21 PM UTC Category: Interpreter Severity: 3 - Normal Priority: 5 - Normal Item Group: Regression Status: None Assigned to: None Originator Name: Originator Email: Open/Closed: Open Release: 6.0.92 Discussion Lock: Any Operating System: Any _______________________________________________________ Details: I recently noticed that all sub-classes of `octave_base_value` aren't copy-assignable. For example: octave_scalar a(1.0); octave_scalar b(2.0); b = a; The example works on Octave 5.2.0 but in 6.0.92 doesn't work. The compiler says that the `count` member of `octave_base_value` is of class `octave::refcount<octave_idx_type>` and the copy assignment operator of `octave::refcount<octave_idx_type>` is explicitly deleted. Because of that the copy assignment operator of `octave_base_value` is also implicitly deleted and because `octave_scalar` is a sub-class of `octave_base_value` and it doesn't defined its own copy assignment operator its default assignment operator is also deleted. Consider a typical signature of builtin functions: octave_value_list myfunction (const octave_value_list& lst, int n = 0) {} Now I want to use this function in a loop. One way is: octave_value_list lst = ovl (octave_value (0.0)); for (int i = 0; i < 1000000; i++) { lst(0) = double(i); myfunction (lst); } The statement `lst(0) = double(i);` calls the constructor of `octave_value::octave_value(double d)` and it internally calls `new octave_scalar(d)`. So creating a scalar value needs at least a memory allocation. A second way to doing the task is: octave_value_list lst = ovl (octave_value (0.0)); for (int i = 0; i < 1000000; i++) { *static_cast<octave_scalar*> (lst(0).internal_rep ()) = double(i); myfunction (lst); } I prefer and use the second method because it doesn't need extra 1000000 memory allocations. Unfortunately the second method doesn't work in new alpha 6.0.92 version. Many Thanks! _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?59500> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/
[Prev in Thread] | Current Thread | [Next in Thread] |