Experts, I am using boost::tuple as key in std::map. I would like to write my own comparison method (considering tolerance in comparison) The default comparison defined in tuple_comparison.hpp is of no use to me. Any help in this is highly appreciated. Regards, UJ
On Fri, Jun 5, 2015 at 8:21 AM, Uthpal Urubail
Experts,
I am using boost::tuple as key in std::map. I would like to write my own comparison method (considering tolerance in comparison)
What's the question?
The default comparison defined in tuple_comparison.hpp is of no use to me.
Seems like this is less of a boost question and more of a general C++ question. std::map, or any range, comparisons, generally take a const & of whatever the type is, key, item, whatever, and may return bool, int (or other integral type), etc. How you actually implement it is up to you. Could be a function, functor, lambda expression, whatever, AFAIK.
Any help in this is highly appreciated.
HTH
Regards,
UJ
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
UJ, Please look at the documentation for std::map for information on how to write your own comparator. http://www.cplusplus.com/reference/map/map/ Basically, you write a comparator class that overloads the () operator to accept two tuples, do whatever you need to do to compare them, and provide this as the Compare parameter of the std::map template. -- Kyle Edwards Software Developer 20 Corporate Circle | Albany, NY 12203 office 888-4BULLEX | 518.689.2023 | fax 518.689.2034 | web: www.bullex.com On Fri, 2015-06-05 at 12:21 +0000, Uthpal Urubail wrote:
Experts,
I am using boost::tuple as key in std::map. I would like to write my own comparison method (considering tolerance in comparison)
The default comparison defined in tuple_comparison.hppis of no use to me.
Any help in this is highly appreciated.
Regards,
UJ
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 5 Jun 2015, at 13:21, Uthpal Urubail
wrote: Experts, I am using boost::tuple as key in std::map. I would like to write my own comparison method (considering tolerance in comparison)
Map comparators must impose a strict weak ordering on the keys. Typically trying to use a tolerance means that transitivity is violated (ie a <= b and b <= c does not imply a <= c). If you must use floating point types as keys you need to be careful.
participants (4)
-
Kyle Edwards
-
Michael Powell
-
Pete Bartlett
-
Uthpal Urubail