[container] [flat_map] Error with heterogeneous comparator and std::string_view

On MSVC (latest) the following code yields a compile error with flat_map, but not with std::map. I do not have the knowledge of std::less<> to resolve what causes the error. auto fm = boost::container::flat_map<std::string, int, std::less<> >{}; auto m = std::map<std::string, int, std::less<> >{}; auto k = std::string_view{ "my_key" }; auto x = m.find(k); // Compiles auto y = fm.find(k); // Does NOT compile Error message: 1>boost\container\flat_map.hpp(1314): error C2664: 'boost::container::vec_iterator<boost::container::dtl::pair<Key,T> *,true> boost::container::dtl::flat_tree<boost::container::dtl::pair<Key,T>,boost::container::dtl::select1st<Key>,Compare,boost::container::new_allocator<T2>>::find(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &) const': cannot convert argument 1 from 'const std::string_view' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &' 1> with 1> [ 1> Key=std::string, 1> T=int, 1> Compare=std::less<void>, 1> T2=boost::container::dtl::pair<std::string,int> 1> ] 1> boost\container\flat_map.hpp(1314): note: Reason: cannot convert from 'const std::string_view' to 'const std::basic_string<char,std::char_traits<char>,std::allocator<char>>' 1> boost\container\flat_map.hpp(1314): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Best regards /Viktor

On 08/12/18 19:26, Viktor Sehr via Boost wrote:
On MSVC (latest) the following code yields a compile error with flat_map, but not with std::map. I do not have the knowledge of std::less<> to resolve what causes the error.
auto fm = boost::container::flat_map<std::string, int, std::less<> >{}; auto m = std::map<std::string, int, std::less<> >{}; auto k = std::string_view{ "my_key" }; auto x = m.find(k); // Compiles auto y = fm.find(k); // Does NOT compile
Looks like this is the same problem that you asked before: http://boost.2283326.n4.nabble.com/container-flat-map-Sub-optimal-behavior-w... What Boost version are you using?

Hi, I'm using 1.68 release. Back in 1.67 heterogeneous lookup was not implemented, now in 1.68.0 it is implemented but fails to compile with std::string as key and std::string_view key for lookup in MSVC. /Viktor On Sun, Aug 12, 2018 at 7:09 PM Andrey Semashev via Boost < boost@lists.boost.org> wrote:
On 08/12/18 19:26, Viktor Sehr via Boost wrote:
On MSVC (latest) the following code yields a compile error with flat_map, but not with std::map. I do not have the knowledge of std::less<> to resolve what causes the error.
auto fm = boost::container::flat_map<std::string, int, std::less<> >{}; auto m = std::map<std::string, int, std::less<> >{}; auto k = std::string_view{ "my_key" }; auto x = m.find(k); // Compiles auto y = fm.find(k); // Does NOT compile
Looks like this is the same problem that you asked before:
http://boost.2283326.n4.nabble.com/container-flat-map-Sub-optimal-behavior-w...
What Boost version are you using?
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 12/08/2018 18:26, Viktor Sehr via Boost wrote:
On MSVC (latest) the following code yields a compile error with flat_map, but not with std::map. I do not have the knowledge of std::less<> to resolve what causes the error.
auto fm = boost::container::flat_map<std::string, int, std::less<> >{}; auto m = std::map<std::string, int, std::less<> >{}; auto k = std::string_view{ "my_key" }; auto x = m.find(k); // Compiles auto y = fm.find(k); // Does NOT compile
Looks like a bug in the is_transparent trait. It seems that used transparent comparator in tests was not detecting the issue. Working on a patch. Best, Ion

Thank you Ion! Best /Viktor On Mon, Aug 13, 2018 at 12:44 AM Ion Gaztañaga via Boost < boost@lists.boost.org> wrote:
On 12/08/2018 18:26, Viktor Sehr via Boost wrote:
On MSVC (latest) the following code yields a compile error with flat_map, but not with std::map. I do not have the knowledge of std::less<> to resolve what causes the error.
auto fm = boost::container::flat_map<std::string, int, std::less<> >{}; auto m = std::map<std::string, int, std::less<> >{}; auto k = std::string_view{ "my_key" }; auto x = m.find(k); // Compiles auto y = fm.find(k); // Does NOT compile
Looks like a bug in the is_transparent trait. It seems that used transparent comparator in tests was not detecting the issue. Working on a patch.
Best,
Ion
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 13/08/2018 15:02, Viktor Sehr via Boost wrote:
Thank you Ion!
Let's see if commit: https://github.com/boostorg/container/commit/139db663a3607d051c52845a4fef56a... fixes the issue. Best, Ion

On Mon, Aug 13, 2018 at 3:38 PM, Ion Gaztañaga via Boost <boost@lists.boost.org> wrote:
On 13/08/2018 15:02, Viktor Sehr via Boost wrote:
Thank you Ion!
Let's see if commit:
https://github.com/boostorg/container/commit/139db663a3607d051c52845a4fef56a...
fixes the issue.
The commit appears to contain unrelated changes as well.. -- Olaf

On 13/08/2018 16:03, Olaf van der Spek wrote:
On Mon, Aug 13, 2018 at 3:38 PM, Ion Gaztañaga via Boost <boost@lists.boost.org> wrote:
On 13/08/2018 15:02, Viktor Sehr via Boost wrote:
Thank you Ion!
Let's see if commit:
https://github.com/boostorg/container/commit/139db663a3607d051c52845a4fef56a...
fixes the issue.
The commit appears to contain unrelated changes as well..
Yes. The life of a lazy programmer with uncommitted changes.
participants (4)
-
Andrey Semashev
-
Ion Gaztañaga
-
Olaf van der Spek
-
Viktor Sehr