469,628 Members | 1,101 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,628 developers. It's quick & easy.

std::sort crashes if more than 8 elements to be sorted.

I am using a sort func object like
struct mystruct {
bool operator () (MyClass* const &a, MyClass* const&b) {};
}

Invoke it like
std::sort(vec.begin(), vec.end(),mystruct);

Where vec is an std::vector<MyClass*>.

Everything works fine, except when my vector has more than 8 elements,
there is SEGV inside STL.
I am using Linux64(opteron), linux32(intel). gcc compiler
gcc/v3.2.3p1/bin/g++.
Is this a known issue/ bug , any way to fix this ?

Thanks.

Apr 28 '06 #1
4 4021
pr**********@gmail.com wrote:
I am using a sort func object like
struct mystruct {
bool operator () (MyClass* const &a, MyClass* const&b) {};
The bug is no doubt in what you left out of the empty braces above. Your
function object must provide for strict-weak-ordering. Google it.
}

Invoke it like
std::sort(vec.begin(), vec.end(),mystruct);

Where vec is an std::vector<MyClass*>.

Everything works fine, except when my vector has more than 8 elements,
there is SEGV inside STL.
I am using Linux64(opteron), linux32(intel). gcc compiler
gcc/v3.2.3p1/bin/g++.
Is this a known issue/ bug , any way to fix this ?
See above.
Thanks.


Welcome,

Jeff Flinn
Apr 28 '06 #2
<pr**********@gmail.com> wrote in message
news:11********************@g10g2000cwb.googlegrou ps.com...
I am using a sort func object like
struct mystruct {
bool operator () (MyClass* const &a, MyClass* const&b) {};
}

Invoke it like
std::sort(vec.begin(), vec.end(),mystruct);

Where vec is an std::vector<MyClass*>.

Everything works fine, except when my vector has more than 8 elements,
there is SEGV inside STL.
I am using Linux64(opteron), linux32(intel). gcc compiler
gcc/v3.2.3p1/bin/g++.
Is this a known issue/ bug , any way to fix this ?


My bet is your mystruct object does not impose a strict weak ordering
on Myclass objects. Any chance that (a < b && b < a) can ever be true
for two elements? If so, you're hosed.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Apr 28 '06 #3
In article <11********************@g10g2000cwb.googlegroups.c om>,
pr**********@gmail.com wrote:
I am using a sort func object like
struct mystruct {
bool operator () (MyClass* const &a, MyClass* const&b) {};
}

Invoke it like
std::sort(vec.begin(), vec.end(),mystruct);

Where vec is an std::vector<MyClass*>.

Everything works fine, except when my vector has more than 8 elements,
there is SEGV inside STL.
I am using Linux64(opteron), linux32(intel). gcc compiler
gcc/v3.2.3p1/bin/g++.
Is this a known issue/ bug , any way to fix this ?


There is nothing wrong with either vector or sort. Either you are doing
something wrong in your 'mystruct' or you are doing something wrong in
your "MyClass", or you are doing something wrong before the sort
function is called.

BTW you should be invoking it like:

std::sort( vec.begin(), vec.end(), mystruct() );

and use a sort func object like:

struct mystruct : std::binary_function< MyClass*, MyClass*, bool >
{
bool operator()( MyClass* a, MyClass* b ) const { }
};
Apr 28 '06 #4
Thanks, guys, you nailed it.

Apr 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by lok | last post: by
6 posts views Thread by alexhong2001 | last post: by
7 posts views Thread by Ireneusz SZCZESNIAK | last post: by
5 posts views Thread by fade | last post: by
11 posts views Thread by Jeff Schwab | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.