View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0027324 | Open CASCADE | OCCT:Foundation Classes | public | 2016-03-31 11:55 | 2016-04-01 10:59 |
| Reporter | Assigned To | ||||
| Priority | normal | Severity | minor | ||
| Status | closed | Resolution | no change required | ||
| Summary | 0027324: NCollection_Sequence is not supported by std::sort algorithm | ||||
| Description | Code from Steps To Reproduce is not compiled. There are following errors: Error 1 error C2039: 'assert_ok' : is not a member of 'Standard_Static_Assert<condition>' ...\src\NCollection\NCollection_StlIterator.hxx 215 1 TKQADraw Error 2 error C3861: 'assert_ok': identifier not found ...\src\NCollection\NCollection_StlIterator.hxx 215 1 TKQADraw Error 3 error C2039: 'Differ' : is not a member of 'NCollection_Sequence<TheItemType>::Iterator' ...\src\NCollection\NCollection_StlIterator.hxx 216 1 TKQADraw | ||||
| Steps To Reproduce | Use following function:
#include <NCollection_Sequence.hxx>
#include <math.h>
#include <algorithm>
static Standard_Integer OCC27324()
{
NCollection_Sequence<Standard_Real> aSeq;
for(Standard_Integer i = 100; i > 0; i--)
{
aSeq.Append(1000.0*std::sin(IntToReal(i)));
}
std::sort(aSeq.begin(), aSeq.end()); // Compiler Error
return 0;
}
| ||||
| Tags | No tags attached. | ||||
| Test case number | |||||
|
|
Description and Steps To Reproduce has been updated. |
|
|
Nikolay, std::sort() requires random access iterators (see http://en.cppreference.com/w/cpp/algorithm/sort), while sequence provides only sequential iterator (just like std::list). That is why it cannot be used for std::sort(). Consider replacing sequence by array or vector. |
|
|
Andrey, 1. "just like std::list" Following code works: std::list<Standard_Real> aList; aList.sort(); I.e. there is sort method for std::list. 2. Described example is made for simple reproducing the problem. Indeed, I already have data of NCollection_Sequence type (e.g. IntPatch_SequenceOfPoint). And conversion them to array or vector is expensive operation. Now, I do not need in sort (I will try to use another way for my problem solution). However, I believe that NCollection_Sequence must support sort-operation. This fix can be made with lowest priority. However, I insist on its classification as a bug. |
|
|
You are welcome to propose a patch |
|
|
I would highly not recommend to use sort on a sequence. The method Exchange of the sequence performs two full iterations on the container to find items to swap (the method Find is called two times). So, I believe that it would be less expensive in most case to put items in array, sort, and then put them back in sequence. |
|
|
So, current behavior forces a developer to find an alternative solution, and if we make sorting of sequence compilable it can lead to development of inefficient code. Let's think about it. May be it is needed to make such implementation that causes an intended compilation error with a special error message. |
|
|
By the way, std::list has its own method sort, but can you use std::sort() instead of aList.sort()? |
|
|
Mikhail, If sort operation is so expensive, it may worth making correspond interface to convert Sequence to Vector or Array and vice versa? |
|
|
I think it is not needed. This operation also has some cost. But if needed a developer needs to write just two lines of code. |
|
|
OK. I agree. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2016-03-31 11:55 |
|
New Issue | |
| 2016-03-31 11:55 |
|
Assigned To | => abv |
| 2016-03-31 13:36 |
|
Description Updated | |
| 2016-03-31 13:36 |
|
Steps to Reproduce Updated | |
| 2016-03-31 13:36 |
|
Additional Information Updated | |
| 2016-03-31 13:37 |
|
Note Added: 0052232 | |
| 2016-03-31 13:39 |
|
Steps to Reproduce Updated | |
| 2016-03-31 13:48 |
|
Note Added: 0052233 | |
| 2016-03-31 13:48 |
|
Assigned To | abv => nbv |
| 2016-03-31 13:48 |
|
Status | new => feedback |
| 2016-03-31 14:38 |
|
Note Added: 0052239 | |
| 2016-03-31 14:38 |
|
Assigned To | nbv => abv |
| 2016-03-31 14:49 |
|
Note Added: 0052240 | |
| 2016-03-31 14:49 |
|
Assigned To | abv => nbv |
| 2016-03-31 14:49 |
|
Status | feedback => assigned |
| 2016-03-31 14:49 |
|
Target Version | 7.1.0 => Unscheduled |
| 2016-04-01 09:31 |
|
Note Added: 0052252 | |
| 2016-04-01 09:35 |
|
Note Added: 0052253 | |
| 2016-04-01 09:37 |
|
Note Added: 0052254 | |
| 2016-04-01 09:48 |
|
Note Added: 0052256 | |
| 2016-04-01 10:20 |
|
Note Added: 0052267 | |
| 2016-04-01 10:22 |
|
Note Added: 0052268 | |
| 2016-04-01 10:59 |
|
Status | assigned => closed |
| 2016-04-01 10:59 |
|
Resolution | open => no change required |
| 2016-04-01 10:59 |
|
Target Version | Unscheduled => |