New issue
Advanced search Search tips

Issue 832901 link

Starred by 1 user

Issue metadata

Status: Untriaged
Owner: ----
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

flat_map doesn't support const key.

Project Member Reported by sebmarchand@chromium.org, Apr 13 2018

Issue description

base::flat_map doesn't seem to support const keys, e.g. the following code doesn't compile:

    base::flat_map<const std::string, int> m;
    m.insert(std::make_pair("foo", 1));

it's not entirely clear if being 100% compatible with the std::map API is one of the goal of base::flat_map, but even if not it'd probably worthwhile to try to improve the error message that gets printed for this kind of error:

In file included from C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\functional:7:
In file included from C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\tuple:8:
In file included from C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xutility:8:
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\utility(246,9):  error: no viable overloaded '='
                first = _STD forward<_Ty1>(_Right.first);
                ~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\vector(1056,17):  note: in instantiation of member function 'std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>::operator=' requested here
                        *_Where._Ptr = _STD move(_Obj);
                                     ^
../..\base/containers/flat_tree.h(949,22):  note: in instantiation of function template specialization 'std::vector<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> > >::emplace<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >' requested here
  return impl_.body_.emplace(position, std::forward<Args>(args)...);
                     ^
../..\base/containers/flat_tree.h(959,13):  note: in instantiation of function template specialization 'base::internal::flat_tree<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, base::internal::GetKeyFromValuePairFirst<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::less<void> >::unsafe_emplace<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >' requested here
    return {unsafe_emplace(lower, std::forward<Args>(args)...), true};
            ^
../..\base/containers/flat_tree.h(697,10):  note: in instantiation of function template specialization 'base::internal::flat_tree<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, base::internal::GetKeyFromValuePairFirst<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::less<void> >::emplace_key_args<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char>
>, int> >' requested here
  return emplace_key_args(GetKeyFromValue()(val), std::move(val));
         ^
../../base/containers/flat_map_unittest.cc(372,5):  note: in instantiation of member function 'base::internal::flat_tree<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, base::internal::GetKeyFromValuePairFirst<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, std::less<void> >::insert' requested here
  m.insert(std::make_pair("foo", 1));
    ^
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xstring(2251,16):  note: candidate function not viable: 'this' argument has type 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >', but method is not marked const
        basic_string& operator=(const basic_string& _Right)
                      ^
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xstring(2082,16):  note: candidate function not viable: 'this' argument has type 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >', but method is not marked const
        basic_string& operator=(basic_string&& _Right)
                      ^
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xstring(2212,16):  note: candidate function not viable: 'this' argument has type 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >', but method is not marked const
        basic_string& operator=(initializer_list<_Elem> _Ilist)
                      ^
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xstring(2280,16):  note: candidate function not viable: 'this' argument has type 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >', but method is not marked const
        basic_string& operator=(_In_z_ const _Elem * const _Ptr)
                      ^
C:\src\chrome\src\third_party\depot_tools\win_toolchain\vs_files\1180cb75833ea365097e279efb2d5d7a42dee4b0\win_sdk\bin\..\..\VC\Tools\MSVC\14.11.25503\include\xstring(2285,16):  note: candidate function not viable: 'this' argument has type 'const std::basic_string<char, std::char_traits<char>, std::allocator<char> >', but method is not marked const
        basic_string& operator=(const _Elem _Ch)
                      ^


 

Sign in to add a comment