Open pfee opened 9 months ago
Example compilation error:
$ c++ deduction.cpp
deduction.cpp: In function ‘int main()’:
deduction.cpp:17:66: error: class template argument deduction failed:
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
| ^
deduction.cpp:17:66: error: no matching function for call to ‘map(std::pair<std::basic_string_view<char>, int>, std::pair<std::basic_string_view<char>, int>)’
In file included from deduction.cpp:2:
/usr/include/frozen/map.h:109:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(std::initializer_list<typename frozen::bits::carray<std::pair<_T1, _T2>, N>::value_type>)-> frozen::map<Key, Value, N, Compare>’
109 | constexpr map(std::initializer_list<value_type> items)
| ^~~
/usr/include/frozen/map.h:109:13: note: template argument deduction/substitution failed:
deduction.cpp:17:66: note: candidate expects 1 argument, 2 provided
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
| ^
/usr/include/frozen/map.h:104:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(std::initializer_list<typename frozen::bits::carray<std::pair<_T1, _T2>, N>::value_type>, const Compare&)-> frozen::map<Key, Value, N, Compare>’
104 | constexpr map(std::initializer_list<value_type> items, Compare const &compare)
| ^~~
/usr/include/frozen/map.h:104:13: note: template argument deduction/substitution failed:
deduction.cpp:17:66: note: couldn’t deduce template parameter ‘Key’
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
| ^
/usr/include/frozen/map.h:101:22: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::bits::carray<std::pair<_T1, _T2>, N>)-> frozen::map<Key, Value, N, Compare>’
101 | explicit constexpr map(container_type items)
| ^~~
/usr/include/frozen/map.h:101:22: note: template argument deduction/substitution failed:
deduction.cpp:17:66: note: ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::bits::carray<std::pair<_T1, _T2>, N>’
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
| ^
/usr/include/frozen/map.h:97:13: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::bits::carray<std::pair<_T1, _T2>, N>, const Compare&)-> frozen::map<Key, Value, N, Compare>’
97 | constexpr map(container_type items, Compare const &compare)
| ^~~
/usr/include/frozen/map.h:97:13: note: template argument deduction/substitution failed:
deduction.cpp:17:66: note: ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::bits::carray<std::pair<_T1, _T2>, N>’
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
| ^
/usr/include/frozen/map.h:73:7: note: candidate: ‘template<class Key, class Value, long unsigned int N, class Compare> map(frozen::map<Key, Value, N, Compare>)-> frozen::map<Key, Value, N, Compare>’
73 | class map {
| ^~~
/usr/include/frozen/map.h:73:7: note: template argument deduction/substitution failed:
deduction.cpp:17:66: note: ‘std::pair<std::basic_string_view<char>, int>’ is not derived from ‘frozen::map<Key, Value, N, Compare>’
17 | frozen::map d = {std::pair{"one"sv, 1}, std::pair{"two"sv, 2}}; // Compilation error
|
I'm unable to use class template argument deduction with
frozen::map
andfrozen::unordered_map
. I'm able to use it withstd::map
andstd::unordered_map
.Is this a bug with the
frozen
library or an issue with my code?I've tried compiling with v1.1.1 and with the latest (7e79c375b0) from git. Both fail in the same way.
Environment:
My primary reason for wanting to use CTAD is to avoid having to specify the size of the container, which can be awkward with large datasets.