<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: AcArray sort in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002061#M20962</link>
    <description>Thanks for the reply. I noticed that you use std::vector, which is OK by me. Instead of using your code, I changed the application to use std::vector container instead of AcArray and it works as expected. Not sure why yet, but it works..&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.&lt;BR /&gt;
&lt;BR /&gt;
Mike Bujak</description>
    <pubDate>Mon, 25 Jun 2007 12:50:06 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-06-25T12:50:06Z</dc:date>
    <item>
      <title>AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002059#M20960</link>
      <description>I want to sort some items in a AcArray but it isn't working as expected.&lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
std::sort(&amp;amp;data.first(), &amp;amp;data.last(), SortFileData);&lt;BR /&gt;
&lt;BR /&gt;
bool SorFileData(const PlotItem&amp;amp; item1, const PlotItem&amp;amp; item2)&lt;BR /&gt;
{&lt;BR /&gt;
      double x1 = min(item1._start.x, item1._end.x);&lt;BR /&gt;
      double x2 = min(item2._start.x, item2._end.x);&lt;BR /&gt;
&lt;BR /&gt;
     return x1 &amp;lt; x2;&lt;BR /&gt;
}&lt;BR /&gt;
[/code]&lt;BR /&gt;
&lt;BR /&gt;
After calling std::sort, the elements are different then without calling sort, but it is still incorrect.&lt;BR /&gt;
&lt;BR /&gt;
Results:&lt;BR /&gt;
"T",169.000,11.438,169.000,14.438,"BO"&lt;BR /&gt;
"P",240.000,42.000,217.000,42.000,""&lt;BR /&gt;
"T",217.000,11.438,217.000,14.438,"BO"&lt;BR /&gt;
"P",240.000,6.000,240.000,42.000,""&lt;BR /&gt;
"T",25.000,11.438,25.000,14.438,"BO"&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
As you can see, the last element has a starting point of 25. This should not be the last element.&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions ? &lt;BR /&gt;
&lt;BR /&gt;
Mike B</description>
      <pubDate>Fri, 22 Jun 2007 18:51:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002059#M20960</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-22T18:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002060#M20961</link>
      <description>No idea of why, there is no way to tell without seeing more of your code.&lt;BR /&gt;
&lt;BR /&gt;
Here is something that I think you want, HTH.&lt;BR /&gt;
&lt;BR /&gt;
[code]&lt;BR /&gt;
struct first_numeric_value&lt;BR /&gt;
{&lt;BR /&gt;
	int ToInt(const std::string&amp;amp; str)&lt;BR /&gt;
	{&lt;BR /&gt;
		int x;&lt;BR /&gt;
		std::stringstream ss(str);&lt;BR /&gt;
		ss &amp;gt;&amp;gt; x;&lt;BR /&gt;
		return x;&lt;BR /&gt;
	}&lt;BR /&gt;
	int getFirstNumericValue(const std::string&amp;amp; StrArray)&lt;BR /&gt;
	{&lt;BR /&gt;
		std::string::size_type pos1 = StrArray.find(",");&lt;BR /&gt;
		std::string::size_type pos2 = StrArray.find(",",pos1+1);&lt;BR /&gt;
		return ToInt(StrArray.substr(pos1+1,pos2-pos1-1));&lt;BR /&gt;
	}&lt;BR /&gt;
&lt;BR /&gt;
	bool operator()(const std::string&amp;amp; lhs, const std::string&amp;amp; rhs)&lt;BR /&gt;
	{&lt;BR /&gt;
		return getFirstNumericValue(lhs) &amp;lt; getFirstNumericValue(rhs);&lt;BR /&gt;
	}&lt;BR /&gt;
};&lt;BR /&gt;
&lt;BR /&gt;
static void doSomeTest(void)&lt;BR /&gt;
{&lt;BR /&gt;
	std::vector&amp;lt; std::string &amp;gt; myLst;&lt;BR /&gt;
	std::vector&amp;lt; std::string &amp;gt;::iterator it;&lt;BR /&gt;
	myLst.push_back( "\"T\",169.000,11.438,169.000,14.438,\"BO\"" );&lt;BR /&gt;
	myLst.push_back( "\"P\",240.000,42.000,217.000,42.000,\"\"" );&lt;BR /&gt;
	myLst.push_back( "\"T\",217.000,11.438,217.000,14.438,\"BO\"" );&lt;BR /&gt;
	myLst.push_back( "\"P\",240.000,6.000,240.000,42.000,\"\"" );&lt;BR /&gt;
	myLst.push_back( "\"T\",25.000,11.438,25.000,14.438,\"BO\"" );&lt;BR /&gt;
	std::sort( myLst.begin(), myLst.end(), first_numeric_value() );&lt;BR /&gt;
	for ( it = myLst.begin(); it != myLst.end(); ++it ) &lt;BR /&gt;
	{&lt;BR /&gt;
		std::string s;&lt;BR /&gt;
		s = ( *it );&lt;BR /&gt;
		CString str( s.c_str() );&lt;BR /&gt;
		acutPrintf( _T("\n%s"), str );&lt;BR /&gt;
	}&lt;BR /&gt;
	myLst.clear();&lt;BR /&gt;
}&lt;BR /&gt;
[/code]&lt;BR /&gt;
&lt;BR /&gt;
Then it will return an ascending sort of the vector:&lt;BR /&gt;
&lt;BR /&gt;
"T",25.000,11.438,25.000,14.438,"BO"&lt;BR /&gt;
"T",169.000,11.438,169.000,14.438,"BO"&lt;BR /&gt;
"T",217.000,11.438,217.000,14.438,"BO"&lt;BR /&gt;
"P",240.000,42.000,217.000,42.000,""&lt;BR /&gt;
"P",240.000,6.000,240.000,42.000,""</description>
      <pubDate>Sun, 24 Jun 2007 23:58:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002060#M20961</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-24T23:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002061#M20962</link>
      <description>Thanks for the reply. I noticed that you use std::vector, which is OK by me. Instead of using your code, I changed the application to use std::vector container instead of AcArray and it works as expected. Not sure why yet, but it works..&lt;BR /&gt;
&lt;BR /&gt;
Thanks again.&lt;BR /&gt;
&lt;BR /&gt;
Mike Bujak</description>
      <pubDate>Mon, 25 Jun 2007 12:50:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002061#M20962</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-25T12:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002062#M20963</link>
      <description>That's because std::sort() expects an iterator to the beginning of the container and another iterator to one past the end of the container, but AcArray::first() and AcArray::last() return references to the first/last element of the array, similar to vector's front() and back(); You can't use STL algorithms directly on an AcArray.</description>
      <pubDate>Tue, 26 Jun 2007 23:43:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002062#M20963</guid>
      <dc:creator>oliver253</dc:creator>
      <dc:date>2007-06-26T23:43:22Z</dc:date>
    </item>
    <item>
      <title>Re: AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002063#M20964</link>
      <description>&lt;OLIVER253&gt; wrote in message news:5639522@discussion.autodesk.com...&lt;BR /&gt;
&amp;gt;You can't use STL algorithms directly on an AcArray.&lt;BR /&gt;
Why? It just needs to provide one past end iterator (pointer in this case).&lt;BR /&gt;
&lt;BR /&gt;
AcArray has also the asArrayPtr() method. And you can use stl algorithms on &lt;BR /&gt;
arrays &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/OLIVER253&gt;</description>
      <pubDate>Wed, 27 Jun 2007 06:38:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002063#M20964</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-06-27T06:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: AcArray sort</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002064#M20965</link>
      <description>Completely forgot about that one,&lt;BR /&gt;
std::sort( data.asArrayPtr(), data.asArrayPtr() + data.length() ) should indeed work nicely.</description>
      <pubDate>Wed, 27 Jun 2007 10:53:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/acarray-sort/m-p/2002064#M20965</guid>
      <dc:creator>oliver253</dc:creator>
      <dc:date>2007-06-27T10:53:00Z</dc:date>
    </item>
  </channel>
</rss>

