From: Vladimir Grigoriev on 12 Jan 2010 09:34 Igor, Do you mean that according to the standard std::min and std::min_element are among those algorithms? And one more question: is weak ordering the same as partial ordering in mathematics (usually this term can be often met in mathematics)? "Igor Tandetnik" <itandetnik(a)mvps.org> wrote in message news:ejvMjA5kKHA.1536(a)TK2MSFTNGP06.phx.gbl... No, that doesn't follow at all. The standard doesn't require that every binary predicate in existence must be a strict weak ordering. It says that certain algorithms should only be invoked with predicates that are strict weak orderings (and thus cannot be called with less_equal or greater_equal). -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Vladimir Grigoriev on 12 Jan 2010 09:42 Jeff, it seems that apart from the code itself of an algorithm one must know also much additional information to use the code.:) However as for find_if it uses a comparison operator/predicate. So with find_if there is no such problem. Vladimir Grigoriev "Jeff Flinn" <Jeff(a)news.microsoft.com> wrote in message news:ugxzBN5kKHA.4772(a)TK2MSFTNGP04.phx.gbl... > Vladimir Grigoriev wrote: >> Igor, in context of what you have said I do not understand existence of >> std::less_equal and std::greater_equal in C++. If I may not to use them >> with algorithms why do they exist? And I do not see any reasonable >> explanation why they may not be used for example in std::min or in >> std::min_element. > > They certainly are usable with algorithms not requiring strict weak > ordering such as std::find_if. > > Jeff
From: Igor Tandetnik on 12 Jan 2010 09:47 Vladimir Grigoriev wrote: > Do you mean that according to the standard std::min and std::min_element are > among those algorithms? Yes I do. > And one more question: is weak ordering the same as partial ordering in > mathematics (usually this term can be often met in mathematics)? No, it's stronger than partial ordering (but weaker than total ordering). The precise definition can be found in 25.3p4 in C++98. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Igor Tandetnik on 12 Jan 2010 09:51 Vladimir Grigoriev wrote: > This is very useful information. I did not even know till now that I can use > reverse iterators directly without their connection with containers. > However in your example p points to 8. Yes, I guess I need min_element(...).base() - 1. I haven't actually tested this. > So I need to do additional > manipulations with the reverse iterator to get correct pointer. With using > std::less_equal directly in the std::min_element I have not such > difficulties Other than the fact that your code exhibits undefined behavior, that is. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Igor Tandetnik on 12 Jan 2010 09:53 Vladimir Grigoriev wrote: > Jeff, it seems that apart from the code itself of an algorithm one must know > also much additional information to use the code.:) This is the case for any function in any library: you must know and satisfy the function's prerequisites when calling it. > However as for find_if it uses a comparison operator/predicate. So with > find_if there is no such problem. Which is precisely the point: less_than is usable with some, but not all, algorithms. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: volatile keyword and memory barriers Next: Can not deduse template arguments std::rel_ops |