[container] [flat_map] Sub-optimal behavior when utilized with std::less<>
It seems to me that neither boost::flat_map nor boost:flat_set with a custom comparator such as std::less<> behaves like std::set/std::map. This results in unnecessary allocation, in difference from std::map/set when used with a std::string as key for example Example: // Please note that I pretend that "dummy" is large enough to make the std::string utilize the heap. auto set = std::set<std::string, std::less<> >{}; auto n = set.count("dummy"); // No conversion from const char* to std::string auto flatset = boost::container::flat_set<std::string, std::less<> >{}; auto n = flatset.count("dummy"); // const char* is converted to a std::string before comparison, thus resulting in an unnecessary allocation. Is this a known issue intended to be resolved? Looking at the code of STL (which ever version ships with Visual Studio), find, count etc has been extended with template key types in addition to the regular key_type using an "is_transparent" trait: template<class _Other, class _Mycomp = key_compare, class = typename _Mycomp::is_transparent> size_type count(const _Other& _Keyval) const { _Keyval _Paircc _Ans = equal_range(_Keyval); return (_STD distance(_Ans.first, _Ans.second)); } Best regards /Viktor Sehr
On 06/15/18 13:22, Viktor Sehr via Boost wrote:
It seems to me that neither boost::flat_map nor boost:flat_set with a custom comparator such as std::less<> behaves like std::set/std::map. This results in unnecessary allocation, in difference from std::map/set when used with a std::string as key for example
Example: // Please note that I pretend that "dummy" is large enough to make the std::string utilize the heap. auto set = std::set<std::string, std::less<> >{}; auto n = set.count("dummy"); // No conversion from const char* to std::string
auto flatset = boost::container::flat_set<std::string, std::less<> >{}; auto n = flatset.count("dummy"); // const char* is converted to a std::string before comparison, thus resulting in an unnecessary allocation.
Is this a known issue intended to be resolved?
Support for templated lookup methods have been added not long ago. https://github.com/boostorg/container/issues/69
Hi Andrey, Thanks for looking it up! I hope it gets merged into 1.68. /Viktor On Fri, Jun 15, 2018 at 1:50 PM Andrey Semashev via Boost < boost@lists.boost.org> wrote:
On 06/15/18 13:22, Viktor Sehr via Boost wrote:
It seems to me that neither boost::flat_map nor boost:flat_set with a custom comparator such as std::less<> behaves like std::set/std::map. This results in unnecessary allocation, in difference from std::map/set when used with a std::string as key for example
Example: // Please note that I pretend that "dummy" is large enough to make the std::string utilize the heap. auto set = std::set<std::string, std::less<> >{}; auto n = set.count("dummy"); // No conversion from const char* to std::string
auto flatset = boost::container::flat_set<std::string, std::less<> >{}; auto n = flatset.count("dummy"); // const char* is converted to a std::string before comparison, thus resulting in an unnecessary allocation.
Is this a known issue intended to be resolved?
Support for templated lookup methods have been added not long ago.
https://github.com/boostorg/container/issues/69
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (4)
-
Andrey Semashev
-
degski
-
Ion Gaztañaga
-
Viktor Sehr