View Issue Details

IDProjectCategoryView StatusLast Update
0027324Open CASCADEOCCT:Foundation Classespublic2016-04-01 10:59
ReporternbvAssigned Tonbv 
PrioritynormalSeverityminor 
Status closedResolutionno change required 
Summary0027324: NCollection_Sequence is not supported by std::sort algorithm
DescriptionCode 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 ReproduceUse 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;
}
TagsNo tags attached.
Test case number

Activities

nbv

2016-03-31 13:37

developer   ~0052232

Description and Steps To Reproduce has been updated.

abv

2016-03-31 13:48

manager   ~0052233

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.

nbv

2016-03-31 14:38

developer   ~0052239

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.

abv

2016-03-31 14:49

manager   ~0052240

You are welcome to propose a patch

msv

2016-04-01 09:31

developer   ~0052252

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.

msv

2016-04-01 09:35

developer   ~0052253

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.

msv

2016-04-01 09:37

developer   ~0052254

By the way, std::list has its own method sort, but can you use std::sort() instead of aList.sort()?

nbv

2016-04-01 09:48

developer   ~0052256

Mikhail,

If sort operation is so expensive, it may worth making correspond interface to convert Sequence to Vector or Array and vice versa?

msv

2016-04-01 10:20

developer   ~0052267

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.

nbv

2016-04-01 10:22

developer   ~0052268

OK.

I agree.

Issue History

Date Modified Username Field Change
2016-03-31 11:55 nbv New Issue
2016-03-31 11:55 nbv Assigned To => abv
2016-03-31 13:36 nbv Description Updated
2016-03-31 13:36 nbv Steps to Reproduce Updated
2016-03-31 13:36 nbv Additional Information Updated
2016-03-31 13:37 nbv Note Added: 0052232
2016-03-31 13:39 nbv Steps to Reproduce Updated
2016-03-31 13:48 abv Note Added: 0052233
2016-03-31 13:48 abv Assigned To abv => nbv
2016-03-31 13:48 abv Status new => feedback
2016-03-31 14:38 nbv Note Added: 0052239
2016-03-31 14:38 nbv Assigned To nbv => abv
2016-03-31 14:49 abv Note Added: 0052240
2016-03-31 14:49 abv Assigned To abv => nbv
2016-03-31 14:49 abv Status feedback => assigned
2016-03-31 14:49 abv Target Version 7.1.0 => Unscheduled
2016-04-01 09:31 msv Note Added: 0052252
2016-04-01 09:35 msv Note Added: 0052253
2016-04-01 09:37 msv Note Added: 0052254
2016-04-01 09:48 nbv Note Added: 0052256
2016-04-01 10:20 msv Note Added: 0052267
2016-04-01 10:22 nbv Note Added: 0052268
2016-04-01 10:59 abv Status assigned => closed
2016-04-01 10:59 abv Resolution open => no change required
2016-04-01 10:59 abv Target Version Unscheduled =>